def testHashStringsWithKeyDenseInput(self): strings = tf.constant(['Cake', 'Pie', 'Sundae']) expected_output = [6, 5, 6] hash_buckets = 11 hashed_strings = mappers.hash_strings(strings, hash_buckets, key=[123, 456]) with self.test_session() as sess: output = sess.run(hashed_strings) self.assertAllEqual(expected_output, output)
def testHashStringsWithKeyRaggedInput(self): strings = tf.RaggedTensor.from_row_splits( values=['$$$', '%^#', '&$!#@', '$$$'], row_splits=[0, 1, 1, 2, 2, 4]) hash_buckets = 173 expected_hashed_strings = tf.RaggedTensor.from_row_splits( values=[16, 156, 9, 16], row_splits=[0, 1, 1, 2, 2, 4]) hashed_strings = mappers.hash_strings(strings, hash_buckets, key=[321, 555]) self.assertAllEqual(expected_hashed_strings, hashed_strings)
def testHashStringsNoKeyRaggedInput(self): strings = tf.RaggedTensor.from_row_splits( values=['Dog', 'Cat', ''], row_splits=[0, 1, 1, 1, 1, 3]) hash_buckets = 17 expected_hashed_strings = tf.RaggedTensor.from_row_splits( values=[12, 4, 11], row_splits=[0, 1, 1, 1, 1, 3]) hashed_strings = mappers.hash_strings(strings, hash_buckets) self.assertAllEqual(expected_hashed_strings, hashed_strings)
def testHashStringsNoKeyDenseInput(self): strings = tf.constant(['Car', 'Bus', 'Tree']) expected_output = [8, 4, 5] hash_buckets = 11 hashed_strings = mappers.hash_strings(strings, hash_buckets) with self.test_session() as sess: output = sess.run(hashed_strings) self.assertAllEqual(expected_output, output)
def testHashStringsNoKeySparseInput(self): strings = tf.SparseTensor(indices=[[0, 0], [0, 1], [1, 0]], values=['Dog', 'Cat', ''], dense_shape=[2, 2]) hash_buckets = 17 expected_indices = [[0, 0], [0, 1], [1, 0]] expected_values = [12, 4, 11] expected_shape = [2, 2] hashed_strings = mappers.hash_strings(strings, hash_buckets) self.assertSparseOutput(expected_indices=expected_indices, expected_values=expected_values, expected_shape=expected_shape, actual_sparse_tensor=hashed_strings, close_values=False)
def testHashStringsWithKeySparseInput(self): strings = tf.SparseTensor(indices=[[0, 0], [0, 1], [1, 0], [2, 0]], values=['$$$', '%^#', '&$!#@', '$$$'], dense_shape=[3, 2]) hash_buckets = 173 expected_indices = [[0, 0], [0, 1], [1, 0], [2, 0]] expected_values = [16, 156, 9, 16] expected_shape = [3, 2] hashed_strings = mappers.hash_strings(strings, hash_buckets, key=[321, 555]) self.assertSparseOutput( expected_indices=expected_indices, expected_values=expected_values, expected_shape=expected_shape, actual_sparse_tensor=hashed_strings, close_values=False)