예제 #1
0
    def test_reduce_batch_coocurrences(self, x, weights, y, expected_results):
        x = tf.constant(x)
        y = tf.constant(y, dtype=tf.int64)
        if weights is not None:
            weights = tf.constant(weights)

        returned_tensors = (tf_utils.reduce_batch_weighted_cooccurrences(
            x, y, weights))
        with tf.compat.v1.Session() as sess:
            results = sess.run(returned_tensors)
            for result, expected in zip(results, expected_results):
                self.assertAllEqual(result, np.array(expected))
예제 #2
0
 def test_reduce_batch_coocurrences_sparse_tensor(self):
     x = tf.SparseTensor(indices=[(0, 0), (2, 1)],
                         values=['a', 'b'],
                         dense_shape=[4, 2])
     y = tf.constant([0, 1, 0, 0], dtype=tf.int64)
     expected_results = [[b'a', b'b', b'global_y_count_sentinel'],
                         [1, 1, 4], [[1, 0], [1, 0], [3, 1]], [1, 1, 4]]
     returned_tensors = (tf_utils.reduce_batch_weighted_cooccurrences(
         x, y, None))
     with tf.compat.v1.Session() as sess:
         results = sess.run(returned_tensors)
         for result, expected in zip(results, expected_results):
             self.assertAllEqual(result, np.array(expected))
예제 #3
0
 def _reduce_batch_weighted_cooccurrences_no_weights(x, y):
     return tf_utils.reduce_batch_weighted_cooccurrences(x, y)