Deeplearning Speacialization Course 5 , week 2- Problem in Emojify assignment

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

The problem is in the test case of cell #14. In the sentence to average function the variable avg is assigned same shape as word in word_to_vec_map() . Following syntax has been used by me:


After that it shows error in test case with key error: “love” as it is missing from controlled word to vec map

I have even replaced word[0] by any_word but still same error is coming.

1 Like

Try using the “any_word” variable.

Thanks for the reply . As I have mentioned same error is coming after using any_word.

I got it right finally ! Thanks for your help

@TMosh Im facing this same issue despite using the “any_word” variable. Any suggestions?


Tip: Most of these type of errors in this exercise involve incorrect usage of the dictionaries. That’s why the grader complains about key errors - because it uses a different dictionary that the exercise does.

@TMosh Okay so where else could this be causing issues in the exercise?

Initialising the avergae I have the following as you advised above:


Only other place I can think that might cause issues is calculating the average? I have the following?

avg += word_to_vec_map[w]

Hi @jlecornu

Extra pair of parenthesis is needed when calling np.zeros to initialize avg so that it would be the same shape as any_word vector.

@Kic Thank you! Just implemented this, but still have aKeyError: ‘love’?

Hi @jlecornu ,

Your code has passed the word finding part of the code. So, It could be the case of cleaning up the execution environment. Refresh the kernel and clear all output, rerun code from start would help.

@Kic - Thanks again for the tip, I have just done this and still same KeyError:‘love’…?

Hi @jlecornu ,

‘love’ is not in the word_to_vec_map. How does your code handle cases like that?

@Kic Apologies, I know we are not supposed to share full code but I hope it is okay to share a small snippet for this error to be fixed.

My code is below, from your suggestion I am guessing I need to add an “else” element. In this case what do we need to do when the word is not in the list?

{mentor edit: code removed}
  ### END CODE HERE ###
1 Like

Hi @jlecornu ,

The ‘if’ statement is checking words in the wrong place.
The ‘for’ loop picks each word from the input sequence, this word is then checked against the word_to_vec_map. Only when the word is found in the word_to_vec_map, will then be added to ‘avg’

hey so why am I getting "4 words " error?

What do you mean by getting ‘4 words’ error?

i have been stuck here for ages?