コード例 #1
0
    def testSequenceAppendTokenExtend(self):
        x = np.asarray(
            [[1, 2, 3, 0], [1, 2, 3, 4], [0, 0, 0, 0], [1, 0, 0, 0]], np.int32)
        x_paddings = np.asarray(
            [[0, 0, 0, 1], [0, 0, 0, 0], [1, 1, 1, 1], [0, 1, 1, 1]], np.int32)

        with self.session() as sess:
            x_appended, x_appended_paddings = insertion.SequenceAppendToken(
                tf.convert_to_tensor(x), tf.convert_to_tensor(x_paddings), 10,
                True)

            x_appended, x_appended_paddings = sess.run(
                [x_appended, x_appended_paddings])

            # `x_appended_gold` is the same as `x` w/ token `10` appended, we also
            # test for the condition of extend=True which requires +1 dim in the
            # time dimension.
            # `x_appended_paddings_gold` is the corresponding paddings.
            x_appended_gold = np.asarray([[1, 2, 3, 10, 0], [1, 2, 3, 4, 10],
                                          [10, 0, 0, 0, 0], [1, 10, 0, 0, 0]],
                                         np.int32)
            x_appended_paddings_gold = np.asarray(
                [[0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 1, 1, 1, 1],
                 [0, 0, 1, 1, 1]], np.int32)

            self.assertAllEqual(x_appended, x_appended_gold)
            self.assertAllEqual(x_appended_paddings, x_appended_paddings_gold)
コード例 #2
0
    def testSequenceAppendToken(self):
        x = np.asarray(
            [[1, 2, 3, 0], [1, 2, 3, 4], [0, 0, 0, 0], [1, 0, 0, 0]], np.int32)
        x_paddings = np.asarray(
            [[0, 0, 0, 1], [0, 0, 0, 1], [1, 1, 1, 1], [0, 1, 1, 1]],
            np.float32)

        with self.session() as sess:
            x_appended, x_appended_paddings = insertion.SequenceAppendToken(
                tf.convert_to_tensor(x), tf.convert_to_tensor(x_paddings), 10)

            x_appended, x_appended_paddings = sess.run([
                tf.convert_to_tensor(x_appended),
                tf.convert_to_tensor(x_appended_paddings)
            ])

            # `x_appended_gold` is the same as `x` w/ token `10` appended.
            # `x_appended_paddings_gold` is the corresponding paddings.
            x_appended_gold = np.asarray(
                [[1, 2, 3, 10], [1, 2, 3, 10], [10, 0, 0, 0], [1, 10, 0, 0]],
                np.int32)
            x_appended_paddings_gold = np.asarray(
                [[0, 0, 0, 0], [0, 0, 0, 0], [0, 1, 1, 1], [0, 0, 1, 1]],
                np.float32)

            self.assertAllEqual(x_appended, x_appended_gold)
            self.assertAllEqual(x_appended_paddings, x_appended_paddings_gold)