Week # must be added in the tags option of the post.
Link to the classroom item you are referring to:
Description (include relevant info but please do not post solution code or your entire notebook) My notebook is not graded correctly I passed all the tests but grader not giving full marks
If you get 0 points for get_country and get_accuracy, then you’ve probably made the most common mistake on this assignment: referencing the global variable word_embeddings directly from the local scope of your get_country function. That is a bug, because the grader passes a different dictionary for the embeddings argument there. get_accuracy also fails, because it calls get_country.
Yes, I looked at your notebook and you made exactly the mistake I was describing:
Within the body of the function get_country, you directly reference word_embeddings. That is a global variable that happens to be passed to that function as the parameter embeddings. So it works in the notebook, because you happen to accidentally be referencing the same dictionary that is actually passed by that test case. But it is a bug, because what happens if the grader passes a different dictionary as the embeddings parameter? That is why you fail the grader’s test.
You should only reference embeddings within get_country.
If you don’t understand how the concept of “scope” works in python, it would be a good idea to google “variable scope python” and read some tutorials about that. This is not a beginning python course: you need to already be a reasonably competent python programmer to succeed here. The concept of “scope” is present in all procedural languages more complicated than BASIC and python’s version of scope is one of the fairly simple ones: no “block level” scope, just function body local scope and global scope basically.
No, you have fixed most of the cases of that error, but there is still a reference to word_embeddings in your get_country function. All it takes is one to cause this error. Use the string search in the browser to find all instances of that name or just read the code more carefully.
Just out of curiosity, I added instrumentation to my get_country function to see what similarity value I got for Tunis and where’s what I see:
Tunis = 0.5451543927192688 (current max value 0.7626821994781494)
('Egypt', 0.7626822)
Notice that my value for Tunis is different than what you show. So that might indicate that your cosine_similarity function is not correct. Are you sure that your code passes the local test for that?
That code is pretty clearly correct. Maybe it’s time to look at the rest of your code. We can’t do that on a public thread, but please check your DMs for a message from me.