Exemplo n.º 1
0
 def test_reduce_batch_vocabulary(self, x, weights, expected_analyzer_inputs):
   x = tf.constant(x)
   if weights is not None:
     weights = tf.constant(weights)
   with tf.Session() as sess:
     results = sess.run(tf_utils.reduce_batch_vocabulary(x, weights))
     self.assertAllEqual(results,
                         np.array(expected_analyzer_inputs, dtype=np.object))
Exemplo n.º 2
0
    def test_reduce_batch_vocabulary(self, x, weights, labels,
                                     expected_analyzer_inputs):
        x = tf.constant(x)
        vocab_ordering_type = (tf_utils.VocabOrderingType.FREQUENCY)
        if weights is not None:
            weights = tf.constant(weights)
            vocab_ordering_type = (
                tf_utils.VocabOrderingType.WEIGHTED_FREQUENCY)
        if labels is not None:
            labels = tf.constant(labels, dtype=tf.int64)
            vocab_ordering_type = (
                tf_utils.VocabOrderingType.WEIGHTED_MUTUAL_INFORMATION)

        x, sum_weights, sum_positive, counts = tf_utils.reduce_batch_vocabulary(
            x, vocab_ordering_type, weights, labels)
        with tf.Session() as sess:
            results = sess.run([
                a for a in [x, sum_weights, sum_positive, counts]
                if a is not None
            ])
            for result, expected in zip(results, expected_analyzer_inputs):
                self.assertAllEqual(result, np.array(expected))