Auto grader error in Course 5 sequence models

Though all tests have got passed in the Emoji Assignment of “Course 5 sequence models”, auto grader has graded 0/100 with the below error

Exercise 5

"Filename: Exercise 5

0/100Score: 0 of 100

Cell #21. Can’t compile the student’s code. Error: KeyError(‘funny’,)"

Kindly help me rectify this error. My email id is ggnana.kumar@gmail.com and my fullname is Gnana Kumar Gnana Guru

Hi @Gnana_Kumar ,

If you do a search on the forum, you would find answers to the same query posted by others.

Thanks for your response. I searched the forum but I seem to have defined the condition correctly both in sentence_to_avg and sentences_to_indices functions

“if w in word_to_vec_map:” in sentence_to_avg function

“for w in sentence_words:” in sentences_to_indices function

I seem to have initialized the avg variable also correctly as below
avg = np.zeros(word_to_vec_map[any_word].shape)

Kindly let me know where is the issue. Which is cell #21 in the notebook.

Hi @Gnana_Kumar

Check the code block in the second ‘For’ loop follows the implementation instructions, especially the ‘if’ statement is checking ‘w’ against word_to_index.

Hi @Kic,

There is no if statement in the 2nd For loop in “sentences_to_indices” function . Pls see my code in 2nd for loop below.

  1. So kindly clarify which if block are you referring to?
  2. Also please let me know which is cell #21 that is causing the error (as per the auto grader). This will help in debugging.

for w in sentence_words:
# Set the (i,j)th entry of X_indices to the index of the correct word.
X_indices[i, j] = word_to_index[w]
# Increment j to j + 1
j = j + 1

Hi @Gnana_Kumar ,

The ‘If’ statement is needed to check whether the ‘w’ exists in the word_to_index.
As explained in the comment statement:
word_to_index – a dictionary containing the each word mapped to its index.
I have no knowledge of how the auto grader works, so I can’t help with the error cell reported.

Hi @Kic,
Do you mean to include the below if statement in bold below?

for w in sentence_words:

Set the (i,j)th entry of X_indices to the index of the correct word.

if w in word_to_index:
X_indices[i, j] = word_to_index[w]
# Increment j to j + 1
j = j + 1

Yes, that is right.
Don’t forget to apply indentation for code block after the ‘if’ statement.

Thanks @Kic for your help. It solved the issue.