Emojify - KeyError (‘funny’,)


I have completed the “Programming Assignment: Emojify” assignment.
Although all the tasks are “passed” I get a score of 0 for the following reason: “Exercise 5 - Cell # 22. Can’t compile the student’s code. Error: KeyError (‘funny’,)”.

Can someone help me?
Thank you,

Hey @ramitsurana , this output is misleading. We apologise for that.
In reality, your ex 3 implementation is incorrect. Since ex 3 has effects on ex 5, it says ex 5 is incorrect.

Kindly make sure your implementation of ex 3 is correct.

and as for your mistake: in ex 3 your “if” call is incorrect in the second “for” loop.

Thanks @Mubsi . I have updated the code. Still seeing the same issue. Can you please check?

Sure. Can you DM your solutions ? Thanks.

Anyone else coming across this exact error or something similar, I have pointed out what your mistake is.

yes i have got the same issue…!!
help me out…!!

Hey @kaveen, you are probably making the same mistake. Kindly check.

@mubsi Im not getting it…still the same issue…

for w in sentence_words:
# if w exists in the word_to_index dictionary
if w in word_to_index:


kindly DM me your grader output and notebook. I’ll take a look.

A common mistake in this function “sentence_to_avg” is when initialzing the avg variable.
You must use the shape of a word from the word_to_vec_map dictionary.

If you use one of the words from the ‘sentence’ variable, your code will likely throw a “KeyError(…)”, because there are several different dictionaries used. The dictionaries used by the exercise test case cells are very small, and most of the sentence words you might select by hard-coding are not found in those dictionaries.

So if you use (for example) “funny” or “the” or word[0] when finding the shape for the initial avg value, you’re probably going to get a good result on the exercise data set, but will fail on the test cases and the grader.

This is why the starter code computes the variable “any_word” for you to use in the initialization of “avg”. It is selected from the first word in the dictionary that is passed to the function.

I am using any_word and get the error [KeyError (‘funny’)], i also check the condition if and i guess it’s okay. Can you help me please?

Please post just your line of code for setting the initial avg = values.

avg = np.zeros(word_to_vec_map[any_word].shape)

Any idea for solving the problem?

Check everywhere in the notebook that you’re using word_to_vec_map or are calling the sentence_to_avg() function. Somewhere, you’re using a word from the sentence instead of using a word from the dictionary.

Also check the sentences_to_indices() function.

From comments earlier in this thread, a problem in the sentences_to_indices() function comes in the code you implement below this comment (for the ‘if’ statement within the second for-loop):

’ # if w exists in the word_to_index dictionary

Yes, I have the same issue with “# if w exists in the word_to_index dictionary”. Not sure how to implement it correctly.

Please help, I don’t know how to implement “# if w exists in the word_to_index dictionary”