示例#1
0
 def _testSinusoidalPositionEncoder(self, depth):
   encoder = position.SinusoidalPositionEncoder()
   positions = position.make_positions([4, 6])
   encoding = encoder.encode(positions, depth)
   with self.test_session() as sess:
     encoding = sess.run(encoding)
     self.assertAllEqual([2, 6, depth], encoding.shape)
示例#2
0
 def _testSinusoidalPositionEncoder(self, depth, dtype=tf.float32):
     encoder = position.SinusoidalPositionEncoder()
     positions = position.make_positions([4, 6])
     encoding = encoder.encode(positions, depth, dtype=dtype)
     self.assertEqual(dtype, encoding.dtype.base_dtype)
     encoding = self.evaluate(encoding)
     self.assertAllEqual([2, 6, depth], encoding.shape)
示例#3
0
 def testPositionBuilder(self):
     sequence_length = tf.constant([4, 6])
     positions = position.make_positions(sequence_length)
     with self.test_session() as sess:
         positions = sess.run(positions)
         self.assertAllEqual([[1, 2, 3, 4, 0, 0], [1, 2, 3, 4, 5, 6]],
                             positions)
示例#4
0
 def testPositionBuilderWithMaxLen(self):
     sequence_length = tf.constant([4, 6])
     positions = position.make_positions(sequence_length, maximum_length=7)
     positions = self.evaluate(positions)
     self.assertAllEqual([[1, 2, 3, 4, 0, 0, 0], [1, 2, 3, 4, 5, 6, 0]],
                         positions)
示例#5
0
 def testPositionBuilder(self):
     sequence_length = tf.constant([4, 6])
     positions = position.make_positions(sequence_length)
     positions = self.evaluate(positions)
     self.assertAllEqual([[1, 2, 3, 4, 0, 0], [1, 2, 3, 4, 5, 6]],
                         positions)
示例#6
0
 def testPositionBuilder(self):
   sequence_length = tf.constant([4, 6])
   positions = position.make_positions(sequence_length)
   with self.test_session() as sess:
     positions = sess.run(positions)
     self.assertAllEqual([[1, 2, 3, 4, 0, 0], [1, 2, 3, 4, 5, 6]], positions)