C2_W3_Assignment Exercise 11 - Transform Error

Instantiate the Transform component

transform = Transform(
examples=example_gen.outputs[‘examples’],
schema=schema_gen.outputs[‘schema’],
module_file=os.path.abspath(_cover_transform_module_file))

END CODE HERE

Run the component

context.run(transform, enable_cache=False)


File “/home/jovyan/work/cover_transform.py”, line 48
features_dict[_transformed_name(feature)] = tft.hash_strings with the param hash_buckets set to 10(data_col)
^
SyntaxError: invalid syntax

Traceback (most recent call last):

File “/opt/conda/lib/python3.8/site-packages/IPython/core/interactiveshell.py”, line 3437, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)

File “”, line 12, in
context.run(transform, enable_cache=False)

File “/opt/conda/lib/python3.8/site-packages/tfx/orchestration/experimental/interactive/interactive_context.py”, line 67, in run_if_ipython
return fn(*args, **kwargs)

File “/opt/conda/lib/python3.8/site-packages/tfx/orchestration/experimental/interactive/interactive_context.py”, line 182, in run
execution_id = launcher.launch().execution_id

File “/opt/conda/lib/python3.8/site-packages/tfx/orchestration/launcher/base_component_launcher.py”, line 202, in launch
self._run_executor(execution_decision.execution_id,

File “/opt/conda/lib/python3.8/site-packages/tfx/orchestration/launcher/in_process_component_launcher.py”, line 67, in _run_executor
executor.Do(input_dict, output_dict, exec_properties)

File “/opt/conda/lib/python3.8/site-packages/tfx/components/transform/executor.py”, line 417, in Do
self.Transform(label_inputs, label_outputs, status_file)

File “/opt/conda/lib/python3.8/site-packages/tfx/components/transform/executor.py”, line 847, in Transform
preprocessing_fn = self._GetPreprocessingFn(inputs, outputs)

File “/opt/conda/lib/python3.8/site-packages/tfx/components/transform/executor.py”, line 767, in _GetPreprocessingFn
fn = import_utils.import_func_from_source(

File “/opt/conda/lib/python3.8/site-packages/tfx/utils/import_utils.py”, line 67, in import_func_from_source
loader.exec_module(user_module)

File “”, line 779, in exec_module

File “”, line 916, in get_code

File “”, line 846, in source_to_code

File “”, line 219, in _call_with_frames_removed

File “/home/jovyan/work/cover_transform.py”, line 48
features_dict[_transformed_name(feature)] = tft.hash_strings with the param hash_buckets set to 10(data_col)
^
SyntaxError: invalid syntax

Hi @jschoi

I see that you corrected the module_file name, referring back to your previous question.

For this question, can you please send me a copy of your full implementation of:

for feature in _HASH_STRING_FEATURE_KEYS:

In other words, send me all 4 lines in this for expression.

From the error message, it looks like one of the comments has gotten mixed up with the code itself.

Chris

for feature in _HASH_STRING_FEATURE_KEYS:
data_col = inputs[feature]
# Transform by hashing strings into buckets
# Hint: Use tft.hash_strings with the param hash_buckets set to 10
features_dict[_transformed_name(feature)] = tft.hash_strings with the param hash_buckets set to 10(data_col)

@Chris

for feature in _HASH_STRING_FEATURE_KEYS:
data_col = inputs[feature]
# Transform by hashing strings into buckets
# Hint: Use tft.hash_strings with the param hash_buckets set to 10
features_dict[_transformed_name(feature)] = tft.hash_strings with the param hash_buckets set to 10(data_col)

Hi @jschoi

You have used the hint comment in place of the tft.hash_buckets() function on the last line.

Replace it with this function, and pass it the data_col as your first input and the suggested number of buckets as your second.

For an example, you can see the documentation for this function here.

Once implemented, it should look similar to the other transform function implementations above this one.

Let me know if you need any further assistance.

Chris