C5W2 Emojify Can't compile the student's code. Error: KeyError('never',)

Cell #14. Can’t compile the student’s code. Error: KeyError(‘never’,)

Autograder showing this error. Please help.

Hey @kumarsaurabh
From what I know of people encountering this error, and me helping them, in ex 1 your are not calculating your “avg” correctly.

Try that and let me know.

Hi @Mubsi

Can you help me with the initialization of “avg” in the exercise. I think that might be the only issue there.

Initialize the average word vector, should have the same shape as your word vectors.

@Mubsi: This is the error I am facing:

KeyError: ‘love’

I’m stuck here too, for me the output value of avg is correct but it is still throwing key error ‘love’

I have exactly the same issue on the grading of my assignment. And the only error I have is in exercise 1, where I get the error: KeyError: ‘love’.

Check the line where u have initialised value for avg. np.zero(.……).

This error occurs due to wrong initialisation of avg and if u ignore the test case then it lead it cell 14 error cannot compile (“never”).

1 Like

Hey, thanks. I was able to get mine fixed by making use of the any_word which I had carelessly ignored.


I received the same error when I did not initialized the size of avg with the first entry in words instead of with any_word…hope it helps :+1:

Could you please tell how to implement it?

String has no size()

@devreev, this thread covers a lot of different questions.
Which one are you asking about, specifically?

Cell #14. Can’t compile the student’s code. Error: KeyError(‘never’,)

Instead of words[0], try the any_word variable.

1 Like

The problem with using words[0] is that the words in the sentence are not necessarily going to be found in the word_to_vec_map dictionary - because there is more than one dictionary used in the exercise.

That’s why “love” or “never” throw errors, they aren’t in the test case dictionary.

1 Like

Thank you so much. It worked

1 Like

i used any_word but still getting keyerror"love"

Somewhere, your code is referring to the sentence words instead of the dictionary.