Week2 Assignment 1, Cell executes but no error

I am executing the cell with sentence_to_avg(sentence, word_to_vec_map) and it throws an error

at line - avg = np.zeros((word_to_vec_map[words[0]]).shape)

KeyError: ‘love’
It is not finding the key “love” when executing one of the test sentences that starts with “love”.
map does not have “love” key, hence it shows the error.
is this the negative test case, I should check for?

Any clues are appreciated.

Sometimes, this same cell executes without throwing any error, any ideas why notebook would do this?


I did not have that error, but my code for that line does not look the same as yours.

The key question is how the variable words is initialized in your implementation. I did not have such a variable in my implementation.

The code template has a pre-defined variable to use in that statement. I believe it’s named “any_word”.

Yet another silly error on my side. Fixed now. Thanks much!