def testSparseColumnWithKeysWithDenseInputTensor(self):
keys_sparse = tf.contrib.layers.sparse_column_with_keys(
"wire", ["marlo", "omar", "stringer", "rick"])
wire_tensor = tf.constant([["omar", "stringer"], ["marlo", "rick"]])
features = {"wire": wire_tensor}
output = feature_column_ops._Transformer(features).transform(keys_sparse)
with self.test_session():
tf.initialize_all_tables().run()
# While the input is a dense Tensor, the output should be a SparseTensor.
self.assertIsInstance(output, tf.SparseTensor)
self.assertEqual(output.dtype, tf.int64)
self.assertAllEqual(output.values.eval(), [1, 2, 0, 3])
self.assertAllEqual(output.indices.eval(),
[[0, 0], [0, 1], [1, 0], [1, 1]])
self.assertAllEqual(output.shape.eval(), [2, 2])
评论列表
文章目录