NLP C1 WEEK 3 grader not giving correct grade

When creating a post, please add:

  • 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
1 Like

There are many potential errors in your notebook that can cause this. The tests in the notebook do not prove your code is perfect.

Please post a screen capture image that shows the detailed feedback from the grader.

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.

1 Like

I do not understand what you are saying please help

{moderator edit - solution notebook removed}

I am stuck with it please help anyone I can not understand

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.

2 Likes

I have changed it but i get the same result please help sir

{moderator edit - solution notebook removed}

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.

1 Like

sir i can not find it stuck with it what to do?

sir please help

sir please help me i can not able to find the error

Please check your DMs for a message from me.

sir i have changed the code but error occurs nothing found

I somehow got (‘Tunis’, 0.5291997). I need advise on this.

When you compute the vector for the new country, please check that you followed the idea in the comment for that line:

# get embedding of country 2 (it's a combination of the embeddings of country 1, city 1 and city 2)
# Remember: King - Man + Woman = Queen

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?

Attached is my cosine_similarity which passed the test. Please help advise anything wrong based on the attached.

{moderator edit - solution code removed}

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.