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:
avg=np.zeros(word_to_vec_map[words[0]].shape)
After that it shows error in test case with key error: “love” as it is missing from controlled word to vec map
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.
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 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?
### START CODE HERE ###
{mentor edit: code removed}
### END CODE HERE ###
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’