fixit for feature column VocabularyListFeatureColumnTest, IndicatorColumn, IdentityColumn and WeightCategoricalColumn.
PiperOrigin-RevId: 325090178 Change-Id: I427fae37945eeed690b99bc959e7757dea7086ed
This commit is contained in:
parent
96cbf43548
commit
3338e5d816
@ -3827,7 +3827,6 @@ class VocabularyListCategoricalColumnTest(test.TestCase):
|
||||
'aaa': parsing_ops.VarLenFeature(dtypes.int64)
|
||||
}, column._parse_example_spec)
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_all_constructor_args(self):
|
||||
column = fc._categorical_column_with_vocabulary_list(
|
||||
key='aaa',
|
||||
@ -3839,7 +3838,6 @@ class VocabularyListCategoricalColumnTest(test.TestCase):
|
||||
'aaa': parsing_ops.VarLenFeature(dtypes.int32)
|
||||
}, column._parse_example_spec)
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_deep_copy(self):
|
||||
original = fc._categorical_column_with_vocabulary_list(
|
||||
key='aaa', vocabulary_list=(12, 24, 36), dtype=dtypes.int32)
|
||||
@ -3974,8 +3972,8 @@ class VocabularyListCategoricalColumnTest(test.TestCase):
|
||||
dense_shape=[1, 2]),
|
||||
features['aaa'].eval())
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_get_sparse_tensors(self):
|
||||
with ops.Graph().as_default():
|
||||
column = fc._categorical_column_with_vocabulary_list(
|
||||
key='aaa', vocabulary_list=('omar', 'stringer', 'marlo'))
|
||||
inputs = sparse_tensor.SparseTensorValue(
|
||||
@ -3993,8 +3991,8 @@ class VocabularyListCategoricalColumnTest(test.TestCase):
|
||||
dense_shape=inputs.dense_shape),
|
||||
id_weight_pair.id_tensor.eval())
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_transform_feature(self):
|
||||
with ops.Graph().as_default():
|
||||
column = fc._categorical_column_with_vocabulary_list(
|
||||
key='aaa', vocabulary_list=('omar', 'stringer', 'marlo'))
|
||||
inputs = sparse_tensor.SparseTensorValue(
|
||||
@ -4026,14 +4024,12 @@ class VocabularyListCategoricalColumnTest(test.TestCase):
|
||||
ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES))
|
||||
self.assertCountEqual([], ops.get_collection('my_weights'))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_get_sparse_tensors_dense_input(self):
|
||||
with ops.Graph().as_default():
|
||||
column = fc._categorical_column_with_vocabulary_list(
|
||||
key='aaa', vocabulary_list=('omar', 'stringer', 'marlo'))
|
||||
id_weight_pair = column._get_sparse_tensors(
|
||||
_LazyBuilder({
|
||||
'aaa': (('marlo', ''), ('skywalker', 'omar'))
|
||||
}))
|
||||
_LazyBuilder({'aaa': (('marlo', ''), ('skywalker', 'omar'))}))
|
||||
self.assertIsNone(id_weight_pair.weight_tensor)
|
||||
with _initialized_session():
|
||||
_assert_sparse_tensor_value(
|
||||
@ -4041,11 +4037,10 @@ class VocabularyListCategoricalColumnTest(test.TestCase):
|
||||
sparse_tensor.SparseTensorValue(
|
||||
indices=((0, 0), (1, 0), (1, 1)),
|
||||
values=np.array((2, -1, 0), dtype=np.int64),
|
||||
dense_shape=(2, 2)),
|
||||
id_weight_pair.id_tensor.eval())
|
||||
dense_shape=(2, 2)), id_weight_pair.id_tensor.eval())
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_get_sparse_tensors_default_value_in_vocabulary(self):
|
||||
with ops.Graph().as_default():
|
||||
column = fc._categorical_column_with_vocabulary_list(
|
||||
key='aaa',
|
||||
vocabulary_list=('omar', 'stringer', 'marlo'),
|
||||
@ -4065,8 +4060,8 @@ class VocabularyListCategoricalColumnTest(test.TestCase):
|
||||
dense_shape=inputs.dense_shape),
|
||||
id_weight_pair.id_tensor.eval())
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_get_sparse_tensors_with_oov_buckets(self):
|
||||
with ops.Graph().as_default():
|
||||
column = fc._categorical_column_with_vocabulary_list(
|
||||
key='aaa',
|
||||
vocabulary_list=('omar', 'stringer', 'marlo'),
|
||||
@ -4086,8 +4081,8 @@ class VocabularyListCategoricalColumnTest(test.TestCase):
|
||||
dense_shape=inputs.dense_shape),
|
||||
id_weight_pair.id_tensor.eval())
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_get_sparse_tensors_int32(self):
|
||||
with ops.Graph().as_default():
|
||||
column = fc._categorical_column_with_vocabulary_list(
|
||||
key='aaa',
|
||||
vocabulary_list=np.array((30, 35, 11, 23, 22), dtype=np.int32),
|
||||
@ -4107,8 +4102,8 @@ class VocabularyListCategoricalColumnTest(test.TestCase):
|
||||
dense_shape=inputs.dense_shape),
|
||||
id_weight_pair.id_tensor.eval())
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_get_sparse_tensors_int32_dense_input(self):
|
||||
with ops.Graph().as_default():
|
||||
default_value = -100
|
||||
column = fc._categorical_column_with_vocabulary_list(
|
||||
key='aaa',
|
||||
@ -4118,8 +4113,8 @@ class VocabularyListCategoricalColumnTest(test.TestCase):
|
||||
id_weight_pair = column._get_sparse_tensors(
|
||||
_LazyBuilder({
|
||||
'aaa':
|
||||
np.array(
|
||||
((11, -1, -1), (100, 30, -1), (-1, -1, 22)), dtype=np.int32)
|
||||
np.array(((11, -1, -1), (100, 30, -1), (-1, -1, 22)),
|
||||
dtype=np.int32)
|
||||
}))
|
||||
self.assertIsNone(id_weight_pair.weight_tensor)
|
||||
with _initialized_session():
|
||||
@ -4128,11 +4123,10 @@ class VocabularyListCategoricalColumnTest(test.TestCase):
|
||||
sparse_tensor.SparseTensorValue(
|
||||
indices=((0, 0), (1, 0), (1, 1), (2, 2)),
|
||||
values=np.array((2, default_value, 0, 4), dtype=np.int64),
|
||||
dense_shape=(3, 3)),
|
||||
id_weight_pair.id_tensor.eval())
|
||||
dense_shape=(3, 3)), id_weight_pair.id_tensor.eval())
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_get_sparse_tensors_int32_with_oov_buckets(self):
|
||||
with ops.Graph().as_default():
|
||||
column = fc._categorical_column_with_vocabulary_list(
|
||||
key='aaa',
|
||||
vocabulary_list=np.array((30, 35, 11, 23, 22), dtype=np.int32),
|
||||
@ -4153,7 +4147,6 @@ class VocabularyListCategoricalColumnTest(test.TestCase):
|
||||
dense_shape=inputs.dense_shape),
|
||||
id_weight_pair.id_tensor.eval())
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_linear_model(self):
|
||||
wire_column = fc._categorical_column_with_vocabulary_list(
|
||||
key='aaa',
|
||||
@ -4179,7 +4172,6 @@ class VocabularyListCategoricalColumnTest(test.TestCase):
|
||||
# 'skywalker' -> 3, 'omar' -> 0: wire_var[3] + wire_var[0] = 4+1 = 5
|
||||
self.assertAllClose(((3.,), (5.,)), self.evaluate(predictions))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_keras_linear_model(self):
|
||||
wire_column = fc._categorical_column_with_vocabulary_list(
|
||||
key='aaa',
|
||||
@ -4223,7 +4215,6 @@ class IdentityCategoricalColumnTest(test.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, 'key must be a string.'):
|
||||
fc._categorical_column_with_identity(key=('aaa',), num_buckets=3)
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_deep_copy(self):
|
||||
original = fc._categorical_column_with_identity(key='aaa', num_buckets=3)
|
||||
for column in (original, copy.deepcopy(original)):
|
||||
@ -4282,8 +4273,8 @@ class IdentityCategoricalColumnTest(test.TestCase):
|
||||
dense_shape=[1, 2]),
|
||||
features['aaa'].eval())
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_get_sparse_tensors(self):
|
||||
with ops.Graph().as_default():
|
||||
column = fc._categorical_column_with_identity(key='aaa', num_buckets=3)
|
||||
inputs = sparse_tensor.SparseTensorValue(
|
||||
indices=((0, 0), (1, 0), (1, 1)),
|
||||
@ -4300,8 +4291,8 @@ class IdentityCategoricalColumnTest(test.TestCase):
|
||||
dense_shape=inputs.dense_shape),
|
||||
id_weight_pair.id_tensor.eval())
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_transform_feature(self):
|
||||
with ops.Graph().as_default():
|
||||
column = fc._categorical_column_with_identity(key='aaa', num_buckets=3)
|
||||
inputs = sparse_tensor.SparseTensorValue(
|
||||
indices=((0, 0), (1, 0), (1, 1)),
|
||||
@ -4331,8 +4322,8 @@ class IdentityCategoricalColumnTest(test.TestCase):
|
||||
ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES))
|
||||
self.assertCountEqual([], ops.get_collection('my_weights'))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_get_sparse_tensors_dense_input(self):
|
||||
with ops.Graph().as_default():
|
||||
column = fc._categorical_column_with_identity(key='aaa', num_buckets=3)
|
||||
id_weight_pair = column._get_sparse_tensors(
|
||||
_LazyBuilder({
|
||||
@ -4348,12 +4339,13 @@ class IdentityCategoricalColumnTest(test.TestCase):
|
||||
dense_shape=(2, 2)),
|
||||
id_weight_pair.id_tensor.eval())
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_get_sparse_tensors_with_inputs_too_big(self):
|
||||
with ops.Graph().as_default():
|
||||
# Inputs.
|
||||
vocabulary_size = 2
|
||||
sparse_input = sparse_tensor.SparseTensorValue(
|
||||
indices=((0, 0), (1, 0), (1, 1)), values=(2, 1, 0), dense_shape=(2, 2))
|
||||
indices=((0, 0), (1, 0), (1, 1)), values=(2, 1, 0),
|
||||
dense_shape=(2, 2))
|
||||
|
||||
# Embedding variable.
|
||||
embedding_dimension = 2
|
||||
@ -4383,8 +4375,8 @@ class IdentityCategoricalColumnTest(test.TestCase):
|
||||
r'indices\[0\] .* 2 .* \[0, 2\)'):
|
||||
self.evaluate(embedding_lookup)
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_get_sparse_tensors_with_inputs_too_small(self):
|
||||
with ops.Graph().as_default():
|
||||
# Inputs.
|
||||
vocabulary_size = 2
|
||||
sparse_input = sparse_tensor.SparseTensorValue(
|
||||
@ -4418,8 +4410,8 @@ class IdentityCategoricalColumnTest(test.TestCase):
|
||||
with _initialized_session():
|
||||
self.assertAllEqual(expected_lookups, self.evaluate(embedding_lookup))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_get_sparse_tensors_with_default_value(self):
|
||||
with ops.Graph().as_default():
|
||||
column = fc._categorical_column_with_identity(
|
||||
key='aaa', num_buckets=4, default_value=3)
|
||||
inputs = sparse_tensor.SparseTensorValue(
|
||||
@ -4437,8 +4429,8 @@ class IdentityCategoricalColumnTest(test.TestCase):
|
||||
dense_shape=inputs.dense_shape),
|
||||
id_weight_pair.id_tensor.eval())
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_get_sparse_tensors_with_default_value_and_placeholder_inputs(self):
|
||||
with ops.Graph().as_default():
|
||||
column = fc._categorical_column_with_identity(
|
||||
key='aaa', num_buckets=4, default_value=3)
|
||||
input_indices = array_ops.placeholder(dtype=dtypes.int64)
|
||||
@ -4463,7 +4455,6 @@ class IdentityCategoricalColumnTest(test.TestCase):
|
||||
input_shape: (2, 2),
|
||||
}))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_linear_model(self):
|
||||
column = fc._categorical_column_with_identity(key='aaa', num_buckets=3)
|
||||
self.assertEqual(3, column._num_buckets)
|
||||
@ -4485,7 +4476,6 @@ class IdentityCategoricalColumnTest(test.TestCase):
|
||||
# weight_var[2] + weight_var[1] = 3+2 = 5
|
||||
self.assertAllClose(((1.,), (5.,)), self.evaluate(predictions))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_keras_linear_model(self):
|
||||
column = fc._categorical_column_with_identity(key='aaa', num_buckets=3)
|
||||
self.assertEqual(3, column._num_buckets)
|
||||
@ -4637,7 +4627,6 @@ class IndicatorColumnTest(test.TestCase):
|
||||
with self.cached_session():
|
||||
self.assertAllEqual([[0., 1., 1., 0.]], self.evaluate(output))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_deep_copy(self):
|
||||
a = fc._categorical_column_with_hash_bucket('a', 4)
|
||||
column = fc._indicator_column(a)
|
||||
@ -4670,8 +4659,8 @@ class IndicatorColumnTest(test.TestCase):
|
||||
dense_shape=[1, 2]),
|
||||
features['aaa'].eval())
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_transform(self):
|
||||
with ops.Graph().as_default():
|
||||
a = fc._categorical_column_with_vocabulary_list(
|
||||
key='aaa', vocabulary_list=('omar', 'stringer', 'marlo'))
|
||||
a_indicator = fc._indicator_column(a)
|
||||
@ -4681,13 +4670,14 @@ class IndicatorColumnTest(test.TestCase):
|
||||
values=('marlo', 'skywalker', 'omar'),
|
||||
dense_shape=(2, 2))
|
||||
}
|
||||
indicator_tensor = _transform_features(features, [a_indicator])[a_indicator]
|
||||
indicator_tensor = _transform_features(features,
|
||||
[a_indicator])[a_indicator]
|
||||
with _initialized_session():
|
||||
self.assertAllEqual([[0, 0, 1], [1, 0, 0]],
|
||||
self.evaluate(indicator_tensor))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_transform_with_weighted_column(self):
|
||||
with ops.Graph().as_default():
|
||||
# Github issue 12557
|
||||
ids = fc._categorical_column_with_vocabulary_list(
|
||||
key='ids', vocabulary_list=('a', 'b', 'c'))
|
||||
@ -4701,8 +4691,8 @@ class IndicatorColumnTest(test.TestCase):
|
||||
with _initialized_session():
|
||||
self.assertAllEqual([[6., 4., 3.]], self.evaluate(indicator_tensor))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_transform_with_missing_value_in_weighted_column(self):
|
||||
with ops.Graph().as_default():
|
||||
# Github issue 12583
|
||||
ids = fc._categorical_column_with_vocabulary_list(
|
||||
key='ids', vocabulary_list=('a', 'b', 'c'))
|
||||
@ -4716,8 +4706,8 @@ class IndicatorColumnTest(test.TestCase):
|
||||
with _initialized_session():
|
||||
self.assertAllEqual([[0., 4., 2.]], self.evaluate(indicator_tensor))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_transform_with_missing_value_in_categorical_column(self):
|
||||
with ops.Graph().as_default():
|
||||
# Github issue 12583
|
||||
ids = fc._categorical_column_with_vocabulary_list(
|
||||
key='ids', vocabulary_list=('a', 'b', 'c'))
|
||||
@ -4729,7 +4719,6 @@ class IndicatorColumnTest(test.TestCase):
|
||||
with _initialized_session():
|
||||
self.assertAllEqual([[0., 1., 1.]], self.evaluate(indicator_tensor))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_linear_model(self):
|
||||
animal = fc._indicator_column(
|
||||
fc._categorical_column_with_identity('animal', num_buckets=4))
|
||||
@ -4749,7 +4738,6 @@ class IndicatorColumnTest(test.TestCase):
|
||||
weight_var.assign([[1.], [2.], [3.], [4.]]).eval()
|
||||
self.assertAllClose([[2. + 3.]], self.evaluate(predictions))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_keras_linear_model(self):
|
||||
animal = fc._indicator_column(
|
||||
fc._categorical_column_with_identity('animal', num_buckets=4))
|
||||
@ -4769,7 +4757,6 @@ class IndicatorColumnTest(test.TestCase):
|
||||
weight_var.assign([[1.], [2.], [3.], [4.]]).eval()
|
||||
self.assertAllClose([[2. + 3.]], self.evaluate(predictions))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_input_layer(self):
|
||||
animal = fc._indicator_column(
|
||||
fc._categorical_column_with_identity('animal', num_buckets=4))
|
||||
@ -6279,7 +6266,6 @@ class SharedEmbeddingColumnTest(test.TestCase, parameterized.TestCase):
|
||||
|
||||
class WeightedCategoricalColumnTest(test.TestCase):
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_defaults(self):
|
||||
column = fc._weighted_categorical_column(
|
||||
categorical_column=fc._categorical_column_with_identity(
|
||||
@ -6293,7 +6279,6 @@ class WeightedCategoricalColumnTest(test.TestCase):
|
||||
'values': parsing_ops.VarLenFeature(dtypes.float32)
|
||||
}, column._parse_example_spec)
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_deep_copy(self):
|
||||
"""Tests deepcopy of categorical_column_with_hash_bucket."""
|
||||
original = fc._weighted_categorical_column(
|
||||
@ -6392,8 +6377,8 @@ class WeightedCategoricalColumnTest(test.TestCase):
|
||||
dense_shape=[1, 2]),
|
||||
features['weights'].eval())
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_transform_features(self):
|
||||
with ops.Graph().as_default():
|
||||
column = fc._weighted_categorical_column(
|
||||
categorical_column=fc._categorical_column_with_identity(
|
||||
key='ids', num_buckets=3),
|
||||
@ -6424,8 +6409,8 @@ class WeightedCategoricalColumnTest(test.TestCase):
|
||||
values=np.array(weights.values, dtype=np.float32),
|
||||
dense_shape=weights.dense_shape), self.evaluate(weight_tensor))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_transform_features_dense_input(self):
|
||||
with ops.Graph().as_default():
|
||||
column = fc._weighted_categorical_column(
|
||||
categorical_column=fc._categorical_column_with_identity(
|
||||
key='ids', num_buckets=3),
|
||||
@ -6452,8 +6437,8 @@ class WeightedCategoricalColumnTest(test.TestCase):
|
||||
values=np.array(weights.values, dtype=np.float32),
|
||||
dense_shape=weights.dense_shape), self.evaluate(weight_tensor))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_transform_features_dense_weights(self):
|
||||
with ops.Graph().as_default():
|
||||
column = fc._weighted_categorical_column(
|
||||
categorical_column=fc._categorical_column_with_identity(
|
||||
key='ids', num_buckets=3),
|
||||
@ -6480,7 +6465,6 @@ class WeightedCategoricalColumnTest(test.TestCase):
|
||||
values=np.array((.5, 1., .1), dtype=np.float32),
|
||||
dense_shape=(2, 2)), self.evaluate(weight_tensor))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_keras_linear_model(self):
|
||||
column = fc._weighted_categorical_column(
|
||||
categorical_column=fc._categorical_column_with_identity(
|
||||
@ -6583,7 +6567,6 @@ class WeightedCategoricalColumnTest(test.TestCase):
|
||||
# = 3*1 + 2*.1 = 3+.2 = 3.2
|
||||
self.assertAllClose(((.5,), (3.2,)), self.evaluate(predictions))
|
||||
|
||||
@test_util.run_deprecated_v1
|
||||
def test_linear_model(self):
|
||||
column = fc._weighted_categorical_column(
|
||||
categorical_column=fc._categorical_column_with_identity(
|
||||
|
Loading…
Reference in New Issue
Block a user