I am facing an issue in week 2 assignment.
Here is the link of the classroom item I am referring to: Coursera | Online Courses & Credentials From Top Educators. Join for Free | Coursera
I keep getting the following error:
Wrong number of keys in loglikelihood dictionary.
Expected: 9165.
Got: 9147.
KeyError Traceback (most recent call last)
in
1 # Test your function
----> 2 w2_unittest.test_train_naive_bayes(train_naive_bayes, freqs, train_x, train_y)
~/work/w2_unittest.py in test_train_naive_bayes(target, freqs, train_x, train_y)
369 for key, value in test_case[âexpectedâ][âloglikelihoodâ].items():
370
â 371 if np.isclose(result2[key], value):
372 count_good += 1
373
KeyError: âtheyâdâ
From my understanding, this probably means that the word is not found in the dictionary, which is evident by the missing numbers in the vocab. I am just not sure where is the problem lies. I checked previous posts and reviewed my code but I am coming up blank.
2 Likes
Yes, I just reran that assignment with code that passed the grader the last time I looked at this assignment and I now get that exact error as well. My understanding is that âtheyâdâ should have been âstemmedâ by the process_tweet
function, so that it would not show up in that form.
Investigating ⌠The first step is to figure out what changed.
2 Likes
can you dm the screenshot of grade function count tweets and train_naive_bayes? please click on my name and then message.
Hi, Deepti.
You should be able to reproduce this error yourself. I just reran my notebook that used to pass the grader and I now get the same error shown above.
The assignment must be downloading something from a website that has changed, but I have not yet figured out what it is that has changed. None of the files in the assignment have changed, including the âpickleâ files.
hi @paulinpaloalto
this error must have been related to nltk data, I remember one of the other assignment of NLP had got some error which was eventually updated.
Just want to make sure learners facing the issue arenât having issue with the same, then we need to raise a ticket in the repo
hi learners,
Thank you for reporting this issue.
This concern has been reported to the staff. Kindly wait for staff response, until then please go ahead with next week.
Regards
DP
2 Likes
I am getting the same error.
kindly wait for staff response. They are working on it.
1 Like
Hey all,
The issue is now fixed. Iâm not sure exactly what happened, but I guess it was an update on the stopwords from NLTK side that might have added missing stopwords, changing the results of some calculations and thus breaking the unittests.
I have updated them, the autograders are still working as they donât rely on hardcoded values for comparison.
Please close and open again your labs and the unittests will be uploaded.
3 Likes
@lucas.coutinho
so learners need to update or get a fresh copy to resolve the current issue?? please let this be known as some learners might not know this.
Regards
DP
They donât need to refresh their workspace, just close and open the lab
3 Likes
Hi, Lucas.
Thanks very much for the quick response on this!
Just a followup question: does this mean that every time the NLTK website sneezes, youâll have to make a similar emergency fix? Is there a way you can isolate yourself from that? E.g. by importing the data, so that you control it? Or am I just mistaken about the way this all works?
But maybe itâs not worth the trouble since this the first time a change like this has been required in literally years. 
Best regards,
Paul
Hi Lukas, sorry to say but the problem remains:
0.0
9147
Expected Output:
0.0
9165
I will try now with a new workplaceâŚ
refreshed workplace gives an expected value of 9147.
so should work now, thanks!
1 Like
Hey @paulinpaloalto
Yes, you are correct! Currently, if NLTK updates either the stopwords of the tweet samples, the unittests will break.
I will update the assignment to use a pre-downloaded version of these objects, but this would require some adjustments in the autograder, which will take a bit longer. So for now I updated the unittests, but I will update the entire assignment so it wonât rely on external downloads.
Cheers,
Lucas
2 Likes
I am getting this error in loglikelihood
Wrong number of keys in loglikelihood dictionary.
Expected: 9147.
Got: 1.
KeyError Traceback (most recent call last)
in
1 # Test your function
----> 2 w2_unittest.test_train_naive_bayes(train_naive_bayes, freqs, train_x, train_y)
~/work/w2_unittest.py in test_train_naive_bayes(target, freqs, train_x, train_y)
369 for key, value in test_case[âexpectedâ][âloglikelihoodâ].items():
370
â 371 if np.isclose(result2[key], value):
372 count_good += 1
373
KeyError: â23rdâ
The error message is pretty clear: your resulting dictionary has literally only one element in it. So how could that happen? There must be a bug in your code that causes you to insert only one key into the dictionary. Are you sure you checked your loop logic there?
1 Like