def testMalformedSparseFeatures(self):
tensors = {
'a': tf.sparse_placeholder(tf.int64),
}
# Invalid indices.
schema = self.toSchema({
'a': tf.SparseFeature('idx', 'val', tf.float32, 10)
})
instances = [{'a': ([-1, 2], [1.0, 2.0])}]
with self.assertRaisesRegexp(
ValueError, 'has index .* out of range'):
_ = impl_helper.make_feed_dict(tensors, schema, instances)
instances = [{'a': ([11, 1], [1.0, 2.0])}]
with self.assertRaisesRegexp(
ValueError, 'has index .* out of range'):
_ = impl_helper.make_feed_dict(tensors, schema, instances)
# Indices and values of different lengths.
schema = self.toSchema({
'a': tf.SparseFeature('idx', 'val', tf.float32, 10)
})
instances = [{'a': ([1, 2], [1])}]
with self.assertRaisesRegexp(
ValueError, 'indices and values of different lengths'):
_ = impl_helper.make_feed_dict(tensors, schema, instances)
# Tuple of the wrong length.
instances = [{'a': ([1], [2], [3])}]
with self.assertRaisesRegexp(
ValueError, 'too many values to unpack'):
_ = impl_helper.make_feed_dict(tensors, schema, instances)
评论列表
文章目录