Beispiel #1
0
 def testToTFIDFNotSmooth(self):
   term_freq = tf.SparseTensor(
       [[0, 0], [0, 1], [0, 2], [1, 0], [1, 3]],
       [(3/5), (1/5), (1/5), (1/2), (1/2)],
       [2, 4])
   reduced_term_freq = tf.constant([[2, 1, 1, 1]])
   output_tensor = mappers._to_tfidf(term_freq, reduced_term_freq, 2, False)
   log_2_over_1 = 1.6931471
   self.assertSparseOutput(
       expected_indices=[[0, 0], [0, 1], [0, 2], [1, 0], [1, 3]],
       expected_values=[(3/5), (1/5)*log_2_over_1, (1/5)*log_2_over_1,
                        (1/2), (1/2)*log_2_over_1],
       expected_shape=[2, 4],
       actual_sparse_tensor=output_tensor,
       close_values=True)
Beispiel #2
0
 def testToTFIDF(self):
   term_freq = tf.SparseTensor(
       [[0, 0], [0, 1], [0, 2], [1, 0], [1, 3]],
       [(3/5), (1/5), (1/5), (1/2), (1/2)],
       [2, 4])
   reduced_term_freq = tf.constant([[2, 1, 1, 1]])
   output_tensor = mappers._to_tfidf(term_freq, reduced_term_freq, 2, True)
   log_3_over_2 = 0.4054651
   self.assertSparseOutput(
       expected_indices=[[0, 0], [0, 1], [0, 2], [1, 0], [1, 3]],
       expected_values=[0, (1/5)*log_3_over_2, (1/5)*log_3_over_2,
                        0, (1/2)*log_3_over_2],
       expected_shape=[2, 4],
       actual_sparse_tensor=output_tensor,
       close_values=True)