C3W1_Assignment please help me

How can I resolve this error whether my expected outputs is correct ??

I don’t know this assignment, but the error message is pretty clear: your code is treating vocab as a dictionary, but it is not. It is a python list. So there are two possibilities: vocab is defined incorrectly or your code that uses it as a dictionary should be treating it as a list. Your job is now to read the instructions again and figure out which of those paths to go down.

But given that your code seems to have worked with the first visible test in the notebook, maybe the better first step would be to read the test function in w1_unittest.py and figure out what is different between that test case and the one that you pass. Click File -> Open from the notebook and have a look around.

1 Like

On further reflection, one scenario I can think of is that your notebook is an old copy. These courses got upgraded not all that long ago from Trax to TF. Maybe you started on the old course and then it got rebooted underneath you and you’re trying to use an old notebook saved from the previous version.

Hi @Mohsin_Saleem

You are overthinking. There’s an example in a cell above the exercise, which shows you how to convert “Hello world” to ids:

Tensorflow has a function tf.keras.layers.StringLookup that does this efficiently for list of characters. Note that the output object is of type tf.Tensor. Here is the result of applying the StringLookup function to the characters of “Hello world”

ids = tf.keras.layers.StringLookup(vocabulary=list(vocab), mask_token=None)(chars)