def testSparseColumnDtypes(self): sc = fc.sparse_column_with_integerized_feature("sc", 10) self.assertDictEqual( {"sc": parsing_ops.VarLenFeature(dtype=dtypes.int64)}, sc.config) sc = fc.sparse_column_with_integerized_feature("sc", 10, dtype=dtypes.int32) self.assertDictEqual( {"sc": parsing_ops.VarLenFeature(dtype=dtypes.int32)}, sc.config) with self.assertRaisesRegexp(ValueError, "dtype must be an integer"): fc.sparse_column_with_integerized_feature("sc", 10, dtype=dtypes.float32)
def testSparseColumnDtypes(self): sc = fc.sparse_column_with_integerized_feature("sc", 10) self.assertDictEqual( { "sc": parsing_ops.VarLenFeature(dtype=dtypes.int64) }, sc.config) sc = fc.sparse_column_with_integerized_feature("sc", 10, dtype=dtypes.int32) self.assertDictEqual( { "sc": parsing_ops.VarLenFeature(dtype=dtypes.int32) }, sc.config) with self.assertRaisesRegexp(ValueError, "dtype must be an integer"): fc.sparse_column_with_integerized_feature("sc", 10, dtype=dtypes.float32)
def testSparseColumnSingleBucket(self): sc = fc.sparse_column_with_integerized_feature("sc", 1) self.assertDictEqual( { "sc": parsing_ops.VarLenFeature(dtype=dtypes.int64) }, sc.config) self.assertEqual(1, sc._wide_embedding_lookup_arguments(None).vocab_size)
def testSparseColumnSingleBucket(self): sc = fc.sparse_column_with_integerized_feature("sc", 1) self.assertDictEqual( { "sc": parsing_ops.VarLenFeature(dtype=dtypes.int64) }, sc.config) self.assertEqual(1, sc._wide_embedding_lookup_arguments(None).vocab_size)
def testSparseColumnIntegerizedDeepCopy(self): """Tests deepcopy of sparse_column_with_integerized_feature.""" column = fc.sparse_column_with_integerized_feature("a", 10) self.assertEqual("a", column.name) column_copy = copy.deepcopy(column) self.assertEqual("a", column_copy.name) self.assertEqual(10, column_copy.bucket_size) self.assertTrue(column_copy.is_integerized)
def testSparseColumnIntegerizedDeepCopy(self): """Tests deepcopy of sparse_column_with_integerized_feature.""" column = fc.sparse_column_with_integerized_feature("a", 10) self.assertEqual("a", column.name) column_copy = copy.deepcopy(column) self.assertEqual("a", column_copy.name) self.assertEqual(10, column_copy.bucket_size) self.assertTrue(column_copy.is_integerized)
def testBucketizedColumnRequiresRealValuedColumn(self): with self.assertRaisesRegexp( TypeError, "source_column must be an instance of _RealValuedColumn"): fc.bucketized_column("bbb", [0]) with self.assertRaisesRegexp( TypeError, "source_column must be an instance of _RealValuedColumn"): fc.bucketized_column( fc.sparse_column_with_integerized_feature( column_name="bbb", bucket_size=10), [0])
def testBucketizedColumnRequiresRealValuedColumn(self): with self.assertRaisesRegexp( TypeError, "source_column must be an instance of _RealValuedColumn"): fc.bucketized_column("bbb", [0]) with self.assertRaisesRegexp( TypeError, "source_column must be an instance of _RealValuedColumn"): fc.bucketized_column( fc.sparse_column_with_integerized_feature( column_name="bbb", bucket_size=10), [0])
def testSparseColumnAcceptsDenseScalar(self): """Tests that `SparseColumn`s accept dense scalar inputs.""" batch_size = 4 dense_scalar_input = [1, 2, 3, 4] sparse_column = fc.sparse_column_with_integerized_feature("values", 10) features = {"values": constant_op.constant(dense_scalar_input, dtype=dtypes.int64)} sparse_column.insert_transformed_feature(features) sparse_output = features[sparse_column] expected_shape = [batch_size, 1] with self.test_session() as sess: sparse_result = sess.run(sparse_output) self.assertEquals(expected_shape, list(sparse_result.dense_shape))
def testSparseColumnAcceptsDenseScalar(self): """Tests that `SparseColumn`s accept dense scalar inputs.""" batch_size = 4 dense_scalar_input = [1, 2, 3, 4] sparse_column = fc.sparse_column_with_integerized_feature("values", 10) features = {"values": constant_op.constant(dense_scalar_input, dtype=dtypes.int64)} sparse_column.insert_transformed_feature(features) sparse_output = features[sparse_column] expected_shape = [batch_size, 1] with self.test_session() as sess: sparse_result = sess.run(sparse_output) self.assertEquals(expected_shape, list(sparse_result.dense_shape))