Exercise 3 error

On the exercise 3 get_country function I am getting a “Wrong output similarity. Maybe you should check your cosine_similarity implementation.” I checked my cosine_similarity function and all tests are passed and is working properly. Could I get some guidance why this is not working properly?

1 Like

Let’s start by seeing what your results are on the test case in the notebook. Here’s what I get:

# feel free to try different words
king = word_embeddings['king']
queen = word_embeddings['queen']

cosine_similarity(king, queen)

0.6510956

**Expected Output**:

≈≈ 0.651095

In [7]:

# Test your function

w3_unittest.test_cosine_similarity(cosine_similarity)

All tests passed

Did you get the correct value on that first test?

1 Like


Yes here is that same snip on my notebook.

1 Like

Then where is the failure? Only from the grader? If you pass the tests in the notebook, but fail the grader, then that means that there is something about your code that is not general. It is somehow hard-coded to match the test case. There really aren’t many moving parts in that function, so it’s a little hard to come up with a theory about the nature of such an error here, but in general it’s things like referencing global variables instead of the actual parameters passed to the function or hard-coding dimensions or some other assumptions about the nature of the inputs in a way that does not generalize.

1 Like

The issue is coming from later in the assignment on UNQ_C3 the get_country function. It’s telling me there is something wrong with the cosine_similarity function

1 Like

You can’t set much store by those suggestions for where the error is. You could try submitting to the grader and I’ll bet your cosine_similarity function would pass. So now you need to invest the effort in looking at your get_country implementation. Maybe you are calling cosine_similarity incorrectly or something along those lines. The most common error on that function is ignoring the parameter for the dictionary and directly referencing the global value that is passed, but that will not cause any errors in the notebook test: it just fails the grader later. :scream_cat:

1 Like

Notice that your answers are different in all cases from the expected ones. There are a fair number of lines of code in this function. One suggestion would be to carefully read through and compare your actual code to the suggestions in the comments for each line of code.

1 Like