C2W2 assignemnt preprocessing function

I keep getting errors on the part of the preprocessing_fn:

I first of all seem to be missing out on how to calculate missing values and this was my initil guess of error origin. The other thing I need help with is with the tf.greater part, where we check if label is grreater thn men.Any help?

1 Like

Hello @Wangari ,

Welcome to the course and thanks for your question.
There is a mistake in your traffic_volume = line of code. Hint: you should use the _fill_in_missing function defined at the bottom of this code block.
Hope that helps.

Best regards,

Hello @mjsmid , I cannot seem to find a “_fill_in_missing” function anywhere on this notebook.

1 Like

@mjsmid also, I scrolled through previous issues raised on discourse on the same and found that some notebooks had the _fill_in_missing_function. I copied its code to my notebook cell(a the bottom of code block as you stated) then now I am getting the error ‘Tensor’ object has no attribute ‘indices’

Hi @Wangari ,
Thanks for your feedback.
I don’t know exactly what the issue is from the info you gave. Could you please share the code block and a snippet of the error message?

Thanks and regards

Thanks for your responsiveness @mjsmid, here is the code(after adding the _fill_in_missing function)

Then the error I get:

Hi @Wangari ,

Could you please try to use tf.cast within the _fill_in_missing function and see if that works? I tried your code and it worked anyway with the tf.cast outside the function and as inputs[_VOLUME_KEY] already comes as a SparseTensor it should work both ways, so I doubt if this works.

Could you please also share the transform code definition and check if all definitions of the contents of the constants module are still as below?

%%writefile {_traffic_transform_module_file}

import tensorflow as tf
import tensorflow_transform as tft

import traffic_constants

# Unpack the contents of the constants module
_VOCAB_SIZE = traffic_constants.VOCAB_SIZE
_OOV_SIZE = traffic_constants.OOV_SIZE
_VOLUME_KEY = traffic_constants.VOLUME_KEY
_transformed_name = traffic_constants.transformed_name

def preprocessing_fn(inputs):


I also can not find any _fill_in_missing function. I am using the one you pasted. Can you please explain where you found it? Thanks!

I also get the same error when I tried both options, _fill_in_missing inside tf.cast and also following the suggestion to use tf.cast within the _fill_in_missing function …

and this is the error

I checked the transform code definitions and they seem OK:

Any suggestions more than welcome. Thanks again!

Hello @edgarbc I found it among the threads of these assignment(c2w2) here on discourse.

1 Like

@edgarbc I also tried several similar ways of resolving the errors but did not succeed.
Eventually I just submitted the assignment that way and passed but not with 100% score.

I think this might be caused by something that Tensorflow hasn’t found a solution for yet seeing that even some of the frameworks here are recently(less than a month ago) updated.

1 Like

if you find a solution kindly share it here, I’d be happy to see the code work successfully.

Hi @edgarbc & @Wangari ,

Sorry for the late reply.

Just went through the notebook again and somehow it worked without hiccups. It looks like in your case the inputs[_VOLUME_KEY] are not being loaded as a SparseTensor. To dig a bit deeper, could you please include the following lines of code before traffic_volume = … to see how the inputs are being loaded?

Then after running the subsequent cell, you see that it should recognize the inputs as a dictionary and the inputs[_VOLUME_KEY] as a SparseTensor.

Please let me know what datatypes the inputs take in your case.

From the Errormessage displayed in your post , my hunch is that it has something to do with the python/numpy version or the tf version you run.
Could you please also check these by running:
import numpy as np
Hi @chris.favila . I guess you may also be able to help with this issue. One of the strange things is that for the students there was no _fill_in_missing(x): function in the writefile , so something might be wrong with the online Assignment Notebook in Coursera.

Thanks and best regards,

Hi, When I print the inputs mentioned above in the preprocessing_fn I get:
<class ‘tensorflow.python.framework.ops.Tensor’>
<class ‘dict’>
<class ‘tensorflow.python.framework.ops.Tensor’>
<class ‘dict’>
Then an “AttributeError: ‘NoneType’ object has no attribute ‘name’”

np and tf versions respectively

I figured out the issue I was having.

As mentioned by multiple other threads, the " _fill_in_missing" function should not be used in this assignment.

Hope it helps


Hi Maarten! Sorry for the late reply. The _fill_in_missing() function should not be needed anymore when this course was refreshed so it is indeed not in the notebook. The error might be coming from another part of the solution. You might be in the old session as well that’s why that solution is working for you. Will send you a DM on how to switch as a mentor. Thanks!

Finally I can confirm, the function works without the fill_in_missing function.

@edgarbc I still need help getting the pre-processing function to work properly. even ignoring the fil_in_missing function, I still get errors. Could you share what you did to resolve the issue?

1 Like

Hi Wangari,

Your AttributeError may be due to the following lines in the function:

# Keep as is. No tft function needed.

outputs[_transformed_name(key)] = None

Contrary to what the comment appears to mean, something needs to be filled in for None. However, you do not need to use a tft function.

Hope this helps.

H​ey, it’s been 2 months since I am stuck in same assignment whereas I have already finished assignment 3. So, this assignment is stopping me from finishing this course.

I keep getting preprocessing_fn wrong.

moderator edit: removed code

I​ need a third eye here, I have tried everything

1 Like