def test_autoregressive_inputs_packed(self): x = tf.constant([3, 8, 1, 9, 1, 5, 4, 1, 0, 0]) sequence_id = tf.constant([1, 1, 1, 2, 2, 3, 3, 3, 0, 0]) autoreg_inputs = feature_converters.autoregressive_inputs( x, sequence_id=sequence_id) actual = self.evaluate(autoreg_inputs) expected = [0, 3, 8, 0, 9, 0, 5, 4, 0, 0] self.assertAllEqual(actual, expected)
def test_autoregressive_inputs_packed_non_eos(self): # In the correct input format, x[4] should have been 1 (EOS). x = tf.constant([3, 8, 1, 9, 6, 5, 4, 1, 0, 0]) # sequence_id is correctly formated. sequence_id = tf.constant([1, 1, 1, 2, 2, 3, 3, 3, 0, 0]) autoreg_inputs = feature_converters.autoregressive_inputs( x, sequence_id=sequence_id) actual = self.evaluate(autoreg_inputs) # The incorrect x[4] should not affect the output as long as the sequence_id # is correct. expected = [0, 3, 8, 0, 9, 0, 5, 4, 0, 0] self.assertAllEqual(actual, expected)
def test_autoregressive_inputs_different_dtypes(self): x = tf.constant([3, 8, 1, 9, 1, 5, 4, 1, 0, 0]) sequence_id = tf.constant([1, 1, 1, 2, 2, 3, 3, 3, 0, 0], tf.int32) autoreg_inputs = feature_converters.autoregressive_inputs( x, sequence_id=sequence_id, output_dtype=tf.int64) self.assertEqual(autoreg_inputs.dtype, tf.int64)
def test_autoregressive_inputs_unpacked(self): x = tf.constant([3, 8, 9, 5, 1, 0, 0]) autoreg_inputs = feature_converters.autoregressive_inputs(x) actual = self.evaluate(autoreg_inputs) expected = [0, 3, 8, 9, 5, 1, 0] self.assertAllEqual(actual, expected)