Week 2 Programming Assignment 1: Operations on Word Vectors - Debiasing

I passed all the tests (including optional ones). But when I submitted my code, it complained that it could not compile …

I can send my ipynb in a DM to the assigned TA. Thanks heaps!

1 Like

Please send me the code of that Cell # 4 (cosine_similarity) in a private message.

1 Like

There are two fundamental theories:

  1. You did not click “Save” before you clicked “Submit” and the grader is seeing an older version of your code.
  2. There is some way in which your code is not general: it passes the tests in the notebook, but fails a different test case from the grader.

Option 1) is easy to check. Option 2) is very common with all the assignments: there are lots of ways to write code that works for one specific test, but which is not really a general solution. Just passing the one set of tests in the notebook is never a guarantee of passing the graders.

2 Likes

Thanks Paul for the reply! The problem is the error msg is vague. I don’t know which one is ‘Cell 4’:


Cell #4. Can't compile the student's code. Error: TypeError("'int' object is not subscriptable",)

Fair enough. Did you try the “Save” + “Submit” strategy?

1 Like

If you just count the executable cells in order, the 4th one is the test cell that calls cosine_similarity. So that function would be the first place to look for hard-coding or “non-generality” issues that might cause that error. Where in that logic do you index a variable?

Update: hmmmm, I just looked at my implementation of cosine_similarity and it did not require any indexing operations the way I did it.

1 Like

I think the cell number is from a temporary notebook that is created by the grader. It scans the user notebook and grabs the cells that are marked for use by the grader, and adds them to the grader’s template.

2 Likes

We had a private DM conversation to examine the code and here’s the result:

It’s an interesting problem. You added the following cell as the fourth executable cell in the notebook to see what the word vectors look like:

word_to_vec_map['refiners']

It’s right after the cell that loads the word_to_vec_map. If you comment out that added statement, then the notebook passes the grader. So we can guess that the grader uses a smaller and more specific word_to_vec_map for its test case that does not contain an entry for “refiners”.

Now why that error would cause the specific message you see is another question, to which I don’t have a ready answer. I would have expected an error along the lines of “invalid dictionary key” or the like.

2 Likes

Thanks to @paulinpaloalto @saifkhanengr and @TMosh . I reset’ed the notebook and carefully only added the code needed (no exploring anymore, LOL). And it passed perfectly~

2 Likes

Nice work!

1 Like