예제 #1
0
  def testSplitTFIDFWithEmptyInput(self):
    with tf.Graph().as_default():
      tfidf = tf.SparseTensor(
          values=tf.constant([], shape=[0], dtype=tf.float32),
          indices=tf.constant([], shape=[0, 2], dtype=tf.int64),
          dense_shape=[2, 0])

      _, weights = mappers._split_tfidfs_to_outputs(tfidf)

      with self.test_session() as sess:
        weights_shape = sess.run(weights.dense_shape)
    self.assertAllEqual(weights_shape, [2, 0])
예제 #2
0
  def testSplitTFIDFWithEmptyInput(self):
    # TODO(b/123242111): rewrite this test using public functions.
    with tf.compat.v1.Graph().as_default():
      tfidf = tf.SparseTensor(
          values=tf.constant([], shape=[0], dtype=tf.float32),
          indices=tf.constant([], shape=[0, 2], dtype=tf.int64),
          dense_shape=[2, 0])

      _, weights = mappers._split_tfidfs_to_outputs(tfidf)

      with self.test_session() as sess:
        weights_shape = sess.run(weights.dense_shape)
    self.assertAllEqual(weights_shape, [2, 0])
예제 #3
0
    def testSplitTFIDF(self):
        tfidfs = tf.SparseTensor(
            [[0, 0], [0, 1], [2, 1], [2, 2]],
            [0.23104906, 0.19178806, 0.14384104, 0.34657359], [3, 4])

        out_index, out_weight = mappers._split_tfidfs_to_outputs(tfidfs)
        self.assertSparseOutput(expected_indices=[[0, 0], [0, 1], [2, 0],
                                                  [2, 1]],
                                expected_values=[0, 1, 1, 2],
                                expected_shape=[3, 2],
                                actual_sparse_tensor=out_index,
                                close_values=False)
        self.assertSparseOutput(
            expected_indices=[[0, 0], [0, 1], [2, 0], [2, 1]],
            expected_values=[0.23104906, 0.19178806, 0.14384104, 0.34657359],
            expected_shape=[3, 2],
            actual_sparse_tensor=out_weight,
            close_values=True)