C2W2_Assignment: preprocessing_fn


I got this error in the # Test your preprocessing_fn cell

# Test your preprocessing_fn

import traffic_transform
from testing_values import feature_description, raw_data

# NOTE: These next two lines are for reloading your traffic_transform module in case you need to 
# update your initial solution and re-run this cell. Please do not remove them especially if you
# have revised your solution. Else, your changes will not be detected.
import importlib

raw_data_metadata = dataset_metadata.DatasetMetadata(schema_utils.schema_from_feature_spec(feature_description))

with tft_beam.Context(temp_dir=tempfile.mkdtemp()):
    transformed_dataset, _ = (
        (raw_data, raw_data_metadata) | tft_beam.AnalyzeAndTransformDataset(traffic_transform.preprocessing_fn))

transformed_data, transformed_metadata = transformed_dataset


16 (raw_data, raw_data_metadata) | tft_beam.AnalyzeAndTransformDataset(traffic_transform.preprocessing_fn))

    654     result = collections.defaultdict(list)

/opt/conda/lib/python3.8/site-packages/tensorflow_transform/schema_inference.py in _get_tensor_value_to_key_map(features_dict)
    547     else:
    548       values = tensor
--> 549     result[values.name] = key
    550   return result

AttributeError: 'str' object has no attribute 'name'

Any one with the same problem? How did you solve it?


1 Like

Please click my name and message your notebook as an attachment.

1 Like


Please fix the way you process the categorical feature keys inside preprocessing_fn. Ensure that you pick the correct fields from the input. Assigning the field name as the output is incorrect.

1 Like