def testOneHotColumnFromWeightedSparseColumnFails(self):
ids_column = tf.contrib.layers.sparse_column_with_keys(
"ids", ["a", "b", "c", "unseen"])
ids_tensor = tf.SparseTensor(
values=["c", "b", "a", "c"],
indices=[[0, 0], [1, 0], [2, 0], [2, 1]],
shape=[3, 2])
weighted_ids_column = tf.contrib.layers.weighted_sparse_column(ids_column,
"weights")
weights_tensor = tf.SparseTensor(
values=[10.0, 20.0, 30.0, 40.0],
indices=[[0, 0], [1, 0], [2, 0], [2, 1]],
shape=[3, 2])
features = {"ids": ids_tensor, "weights": weights_tensor}
one_hot_column = tf.contrib.layers.one_hot_column(weighted_ids_column)
with self.test_session():
tf.initialize_all_variables().run()
tf.initialize_all_tables().run()
with self.assertRaisesRegexp(
ValueError,
"one_hot_column does not yet support weighted_sparse_column"):
_ = tf.contrib.layers.input_from_feature_columns(features,
[one_hot_column])
评论列表
文章目录