def test_feature_validation(self):
    default_vocab = test_utils.sentencepiece_vocab()
    features = {'inputs': dataset_providers.Feature(vocabulary=default_vocab, required=False), 'targets': dataset_providers.Feature(vocabulary=default_vocab, required=True), 'inputs_rank2': dataset_providers.Feature(vocabulary=vocabularies.PassThroughVocabulary(5), required=False, rank=2), 'continuous_features': dataset_providers.ContinuousFeature(required=False, rank=2)}

    def _materialize(output):
        task = dataset_providers.Task('feature_validation_task', self.function_source, output_features=features, preprocessors=((lambda _: tf.data.Dataset.from_tensors(output)),), metric_fns=[])
        list(task.get_dataset({'inputs': 13, 'targets': 13, 'inputs_rank2': 13}, 'train', use_cached=False).as_numpy_iterator())
    _materialize({'targets': [0]})
    with self.assertRaisesWithLiteralMatch(ValueError, 'Task dataset is missing expected output feature after preprocessing: targets'):
        _materialize({'inputs': [0]})
    with self.assertRaisesWithLiteralMatch(ValueError, "Task dataset has incorrect type for feature 'targets' after preprocessing: Got string, expected int32"):
        _materialize({'targets': ['wrong type']})
    with self.assertRaisesWithLiteralMatch(ValueError, "Task dataset has incorrect rank for feature 'targets' after preprocessing: Got 0, expected 1"):
        _materialize({'targets': 0})
    _materialize({'targets': [0], 'inputs_rank2': [[0, 0, 0], [0, 0, 0]]})
    with self.assertRaisesWithLiteralMatch(ValueError, "Task dataset has incorrect rank for feature 'inputs_rank2' after preprocessing: Got 1, expected 2"):
        _materialize({'targets': [0], 'inputs_rank2': [0]})
    _materialize({'targets': [0], 'continuous_features': [[1, 1], [0, 1]]})
def test_feature_validation(self):
    default_vocab = test_utils.sentencepiece_vocab()
    features = {'inputs': dataset_providers.Feature(vocabulary=default_vocab, required=False), 'targets': dataset_providers.Feature(vocabulary=default_vocab, required=True), 'inputs_rank2': dataset_providers.Feature(vocabulary=vocabularies.PassThroughVocabulary(5), required=False, rank=2), 'continuous_features': dataset_providers.ContinuousFeature(required=False, rank=2)}

    def _materialize(output):
        task = dataset_providers.Task('feature_validation_task', self.function_source, output_features=features, preprocessors=((lambda _: tf.data.Dataset.from_tensors(output)),), metric_fns=[])
        list(task.get_dataset({'inputs': 13, 'targets': 13, 'inputs_rank2': 13}, 'train', use_cached=False).as_numpy_iterator())
    _materialize({'targets': [0]})
    with self.assertRaisesWithLiteralMatch(ValueError, 'Task dataset is missing expected output feature after preprocessing: targets'):
        _materialize({'inputs': [0]})
    with self.assertRaisesWithLiteralMatch(ValueError, "Task dataset has incorrect type for feature 'targets' after preprocessing: Got string, expected int32"):
        _materialize({'targets': ['wrong type']})
    with self.assertRaisesWithLiteralMatch(ValueError, "Task dataset has incorrect rank for feature 'targets' after preprocessing: Got 0, expected 1"):
        _materialize({'targets': 0})
    _materialize({'targets': [0], 'inputs_rank2': [[0, 0, 0], [0, 0, 0]]})
    with self.assertRaisesWithLiteralMatch(ValueError, "Task dataset has incorrect rank for feature 'inputs_rank2' after preprocessing: Got 1, expected 2"):
        _materialize({'targets': [0], 'inputs_rank2': [0]})
    _materialize({'targets': [0], 'continuous_features': [[1, 1], [0, 1]]})