C1_W1_Assignment Word Frequency Count

Hi there,

The test data for grading extract_features in week one’s assignment appears to be incorrect.

Performing a loop over the words in word_l with additive assignment always produces results that are slightly off the test data.

Please see the output for the first test below, where I have intentionally printed the freqs value per-key.

['followfriday', 'top', 'engag', 'member', 'commun', 'week', ':)']
positive:  :) 2964
negative:  :) 6
positive:  commun 31
negative:  commun 5
positive:  engag 11
positive:  followfriday 27
positive:  member 18
negative:  member 10
positive:  top 34
negative:  top 9
positive:  week 76
negative:  week 51
[[1.000e+00 3.161e+03 8.100e+01]]
Expected output
[[1.000e+00 3.133e+03 6.100e+01]]

As can clearly be surmised, when using freqs[(word, 1.0)] and freqs[(word, 0.0)], the summed values I return are accurate. The sum of negative values is very clearly 81 and not 61. The sum of positive values is also clearly 3,161 and not 3133.

Please note I am not using .lower() on my strings.

Am I missing something crucial here?

1 Like

My numbers agree with the Expected Values as shown. Are you sure your code correctly handles the fact that not all words have both positive and negative frequencies?

1 Like

Hi Paul,

Bizarrely, performing a full re-run of my workspace fixed the issue.

My code was indeed correct - hence I was very confused (this is not a complex method).

Perhaps something downloaded incorrectly…? I have no idea.

Regardless, this is now solved :slightly_smiling_face: thanks for the assistance.

1 Like

Glad to hear that things are working correctly now. My guess is that it was probably an issue where the code you were looking at was not what you were actually running. If you type new code into a function cell and then just call that function again, it runs the old code. You have to actually click “Shift-Enter” on the function cell itself to get the code changes compiled into the runtime image. Now that you know this fact, you can easily demonstrate to yourself how it works.

One sledgehammer way to get things back in sync is:

  1. Kernel → Restart and Clear Output
  2. Save
  3. Cell → Run All

Now WYSIWYG …

1 Like