f7c759ca562303127a9991574d5a985d4dff99e8,sonnet/python/modules/gated_rnn_test.py,LSTMTest,testComputation,#LSTMTest#Any#,122

Before Change


    batch_size = 2
    hidden_size = 4
    hidden_state_size = projection_size or hidden_size
    inputs = tf.placeholder(tf.float32, shape=[batch_size, hidden_size])
    prev_cell = tf.placeholder(tf.float32, shape=[batch_size, hidden_size])
    prev_hidden = tf.placeholder(tf.float32,
                                 shape=[batch_size, hidden_state_size])
    lstm = snt.LSTM(hidden_size, projection_size=projection_size)
    _, next_state = lstm(inputs, (prev_hidden, prev_cell))
    next_hidden, next_cell = next_state
    lstm_variables = lstm.get_variables()
    param_map = {param.name.split("/")[-1].split(":")[0]:
                 param for param in lstm_variables}

    // With random data, check the TF calculation matches the Numpy version.
    input_data = np.random.randn(batch_size, hidden_size)
    prev_hidden_data = np.random.randn(batch_size, hidden_state_size)
    prev_cell_data = np.random.randn(batch_size, hidden_size)

    with self.test_session() as session:
      tf.global_variables_initializer().run()
      fetches = [(next_hidden, next_cell),
                 param_map[snt.LSTM.W_GATES],
                 param_map[snt.LSTM.B_GATES]]
      if projection_size is not None:
        fetches.append(param_map[snt.LSTM.W_H_PROJECTION])
      output = session.run(fetches,
                           {inputs: input_data,
                            prev_cell: prev_cell_data,
                            prev_hidden: prev_hidden_data})

    next_state_ex, gate_weights_ex, gate_biases_ex = output[:3]
    in_and_hid = np.concatenate((input_data, prev_hidden_data), axis=1)
    real_gate = np.dot(in_and_hid, gate_weights_ex) + gate_biases_ex
    // i = input_gate, j = next_input, f = forget_gate, o = output_gate

After Change



    // With random data, check the TF calculation matches the Numpy version.
    input_data = np.random.randn(batch_size, hidden_size).astype(np.float32)
    prev_hidden_data = np.random.randn(batch_size,
                                       hidden_state_size).astype(np.float32)
    prev_cell_data = np.random.randn(batch_size, hidden_size).astype(np.float32)

    inputs = tf.constant(input_data)
    prev_cell = tf.constant(prev_cell_data)
    prev_hidden = tf.constant(prev_hidden_data)

    lstm = snt.LSTM(hidden_size, projection_size=projection_size)
    _, next_state = lstm(inputs, (prev_hidden, prev_cell))
    next_hidden, next_cell = next_state
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 4

Non-data size: 22

Instances


Project Name: deepmind/sonnet
Commit Name: f7c759ca562303127a9991574d5a985d4dff99e8
Time: 2018-07-17
Author: tomhennigan@google.com
File Name: sonnet/python/modules/gated_rnn_test.py
Class Name: LSTMTest
Method Name: testComputation


Project Name: deepmind/sonnet
Commit Name: f7c759ca562303127a9991574d5a985d4dff99e8
Time: 2018-07-17
Author: tomhennigan@google.com
File Name: sonnet/python/modules/gated_rnn_test.py
Class Name: HighwayCoreTest
Method Name: testComputation


Project Name: deepmind/sonnet
Commit Name: f7c759ca562303127a9991574d5a985d4dff99e8
Time: 2018-07-17
Author: tomhennigan@google.com
File Name: sonnet/python/modules/gated_rnn_test.py
Class Name: GRUTest
Method Name: testComputation


Project Name: deepmind/sonnet
Commit Name: f7c759ca562303127a9991574d5a985d4dff99e8
Time: 2018-07-17
Author: tomhennigan@google.com
File Name: sonnet/python/modules/gated_rnn_test.py
Class Name: LSTMTest
Method Name: testComputation


Project Name: deepmind/sonnet
Commit Name: f7c759ca562303127a9991574d5a985d4dff99e8
Time: 2018-07-17
Author: tomhennigan@google.com
File Name: sonnet/python/modules/gated_rnn_test.py
Class Name: LSTMTest
Method Name: testPeephole