Unit test W2_train naive bayes grading error

I got correct logprior and loglikelihood values of 0 and 9165 respectively. However the immediate next unit test failed giving message “Sunglass” keyerror Expected 9165 elements in loglikelihood but got 148.

All subsequent cells as well as unit tests also ran correctly meaning there was no error in my code. Yet since the unit test failed, I got 0 score in train section of the assignment.

May I know what I can do to correct this ?

Maybe is the case you have hard code some variable, check that as first step?

It seems to me if your code fails a test, then it has an error.
Each test checks for a specific condition. Your code doesn’t work for one of them.

Thanks for the reply. But the error said found 148 loglikelihood elements when clearly the print statement gave 9165 as len(loglikelihood). How is that possible?

Also, when I said “meaning there was no error in my code” I meant that all subsequent function calls gave correct output.

Thanks. But what is returned is controlled by the assignment function. How will hard coded variable impact this ? Besides, all other function calls gave correct result.

Whats best to do in this case and what I would do is, go over that functions implementation once again and see yourself if all makes sense, next is go to files -open- and check the unit tests file if its there, that might give you some indication of where you are going wrong as well. Ultimately if all your efforts fail, a mentor might have to have a look at your code.
Thousands of learners have done this and passed.

Hey @Mayank11,
Can you try to print the length of your vocab? For the given test-case, I believe the length of the vocab should be 9165.

Cheers,
Elemento