# Exercise 3 error

**URL:** <https://community.deeplearning.ai/t/exercise-3-error/479371>\
**Category:** NLP with Classification and Vector Spaces\
**Tags:** week-module-3\
**Created:** [October 28, 2023, 12:25pm UTC](https://community.deeplearning.ai/t/exercise-3-error/479371 "2023-10-28T12:25:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hal\_Roberts](https://avatars.discourse-cdn.com/v4/letter/h/50afbb/32.png) [@Hal\_Roberts](https://community.deeplearning.ai/u/Hal_Roberts)\
**Post date:** [October 28, 2023, 12:25pm UTC](https://community.deeplearning.ai/t/exercise-3-error/479371/1 "2023-10-28T12:25:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [October 28, 2023, 6:01pm UTC](https://community.deeplearning.ai/t/exercise-3-error/479371/2 "2023-10-28T18:01:50Z")

</div>

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

```auto
# 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?

---

<div class="post-metadata">

**Author:** ![Hal\_Roberts](https://avatars.discourse-cdn.com/v4/letter/h/50afbb/32.png) [@Hal\_Roberts](https://community.deeplearning.ai/u/Hal_Roberts)\
**Post date:** [October 29, 2023, 2:22pm UTC](https://community.deeplearning.ai/t/exercise-3-error/479371/3 "2023-10-29T14:22:41Z")

</div>

![image](https://global.discourse-cdn.com/dlai/original/3X/2/2/2220cc1a2e41026e9c470fc237c021af36a1a623.png)  
Yes here is that same snip on my notebook.

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [October 29, 2023, 2:42pm UTC](https://community.deeplearning.ai/t/exercise-3-error/479371/4 "2023-10-29T14:42:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Hal\_Roberts](https://avatars.discourse-cdn.com/v4/letter/h/50afbb/32.png) [@Hal\_Roberts](https://community.deeplearning.ai/u/Hal_Roberts)\
**Post date:** [October 29, 2023, 5:18pm UTC](https://community.deeplearning.ai/t/exercise-3-error/479371/5 "2023-10-29T17:18:31Z")

</div>

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

 ![image](https://global.discourse-cdn.com/dlai/original/3X/4/9/49c7cab770caab578b64801aa073f4ecb4371b34.png)

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [October 29, 2023, 5:21pm UTC](https://community.deeplearning.ai/t/exercise-3-error/479371/6 "2023-10-29T17:21:38Z")

</div>

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. 🙀

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [October 29, 2023, 5:43pm UTC](https://community.deeplearning.ai/t/exercise-3-error/479371/7 "2023-10-29T17:43:42Z")

</div>

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.
