f7c759ca562303127a9991574d5a985d4dff99e8,sonnet/python/modules/gated_rnn_test.py,LSTMTest,testCellClipping,#LSTMTest#,686

Before Change


    core = snt.LSTM(hidden_size=5, cell_clip_value=1.0)
    obs = tf.constant(np.random.rand(3, 10), dtype=tf.float32)
    hidden = tf.placeholder(tf.float32, shape=[3, 5])
    cell = tf.placeholder(tf.float32, shape=[3, 5])
    output = core(obs, [hidden, cell])
    with self.test_session() as sess:
      sess.run(tf.global_variables_initializer())
      unclipped = np.random.rand(3, 5) - 0.5
      unclipped *= 2.0 / unclipped.max()
      clipped = unclipped.clip(-1., 1.)

      output1, (hidden1, cell1) = sess.run(output, feed_dict={hidden: unclipped,
                                                              cell: unclipped})
      output2, (hidden2, cell2) = sess.run(output, feed_dict={hidden: unclipped,
                                                              cell: clipped})
      self.assertAllClose(output1, output2)
      self.assertAllClose(hidden1, hidden2)
      self.assertAllClose(cell1, cell2)

  @parameterized.parameters(
      (False, False, False, False),
      (False, True, False, False),
      (True, False, True, False),

After Change


    self.assertAllClose(hidden1, hidden2)
    self.assertAllClose(cell1, cell2)

  def testCellClipping(self):
    core = snt.LSTM(hidden_size=5, cell_clip_value=1.0)
    obs = tf.constant(np.random.rand(3, 10), dtype=tf.float32)

    unclipped = np.random.rand(3, 5) - 0.5
    unclipped *= 2.0 / unclipped.max()
    unclipped = unclipped.astype(np.float32)
    clipped = unclipped.clip(-1., 1.)

    hidden = tf.constant(unclipped)
    cell = tf.constant(unclipped)
    output = core(obs, [hidden, cell])
    self.evaluate(tf.global_variables_initializer())
    output1, (hidden1, cell1) = self.evaluate(output)

    cell = tf.constant(clipped)
    output = core(obs, [hidden, cell])
    output2, (hidden2, cell2) = self.evaluate(output)
    self.assertAllClose(output1, output2)
    self.assertAllClose(hidden1, hidden2)
    self.assertAllClose(cell1, cell2)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 15

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: testCellClipping


Project Name: deepmind/sonnet
Commit Name: e61955b5553d98b4346817e0e9161f79fb23a40c
Time: 2018-07-17
Author: tomhennigan@google.com
File Name: sonnet/python/modules/nets/alexnet_test.py
Class Name: AlexNetTest
Method Name: testNoDropoutInTesting


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: testHiddenClipping


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: testCellClipping