Hi guys, my get_country function is returning wrong values for similarity (which is calculated by cosine_similarity).

The cosine similarity is very straightforward and appearently correctly implemented, but the values are still wrong. I think it could be something about the data loaded (but it is already onthe notebook).

I was able to get the expected answer at least up to the last decimal place:

('Egypt', 0.7626822)

I assume youâve been through the instructions carefully and compared them to your code. The most common mistake on this function is to directly reference the global variable word_embeddings within the body of the function, instead of referencing it through the parameter. But that actually passes the test case in the notebook and only fails when you submit to the grader.

There are a couple of key pieces here: did you test to make sure that the word is not in the âgroupâ that you defined early on? But if you accidentally included everything, you end up with higher numbers, not lower as in your case. So thatâs probably not it âŚ

The only other thing I can think of is maybe you didnât compute the difference vector correctly. Hereâs the hint in the comments:

# Remember: King - Man + Woman = None

If you already know that your cosine_similarity function passes the tests, then the rest of this should be pretty straightforward.

Perfect!
I was initially counting the vector as merely the difference between the embeddings of country1 and city1, and directly applying the city2 embeddings in the cosine_similarity calculation. Intuitively, this approach seemed viable, but I think I made some mistakes while manipulating the embeddings.