C5W1A2 Excercise 2 - AssertionError: Wrong Values

I am getting an AssertionError: Wrong values. I have checked the calculations and everything looks fine, yet I’m unable to get the required values. The following is my output :

Sampling:
list of sampled indices:
 [23, 16, 26, 26, 19, 25, 22, 16, 7, 11, 17, 26, 23, 23, 23, 18, 10, 6, 12, 2, 14, 24, 14, 17, 7, 18, 0]
list of sampled characters:
 ['w', 'p', 'z', 'z', 's', 'y', 'v', 'p', 'g', 'k', 'q', 'z', 'w', 'w', 'w', 'r', 'j', 'f', 'l', 'b', 'n', 'x', 'n', 'q', 'g', 'r', '\n']

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-9-a13d660e654a> in <module>
     19     print("\033[92mAll tests passed!")
     20 
---> 21 sample_test(sample)

<ipython-input-9-a13d660e654a> in sample_test(target)
     15     assert indices[-1] == char_to_ix['\n'], "All samples must end with \\n"
     16     assert min(indices) >= 0 and max(indices) < len(char_to_ix), f"Sampled indexes must be between 0 and len(char_to_ix)={len(char_to_ix)}"
---> 17     assert np.allclose(indices[0:6], [23, 16, 26, 26, 24, 3]), "Wrong values"
     18 
     19     print("\033[92mAll tests passed!")

AssertionError: Wrong values

I’ve been stuck on this assignment for a week now and would love it if anyone could help me out.
Thanks

Hi @shrekansal ,

If you are sure you have checked your calculations followed the formulas correctly, then, post that section of code in a direct message to me. I will have a look for you.

@Kic Thanks for your help, but I figured out the cause of the problem

Hey @shrekansal I stumbled upon your thread because I’m stuck with the same error. In my case, the six first indices are [23, 16, 15, 1, 7, 23] (it gets wrong by the third index). Do you have any clue on which mistake you found in your code?

Oh, just found my mistake. For future reference, in case anyone gets here facing similar problem, I figured it out after fixing two things:

  • x and a_prev must be column vectors,
  • y is a 2D array and, as one can find in the problem tips, np.random.choice asks for a 1D array summing to 1.
1 Like

Any help is greatly appreciated.
Here is my list of sampled indices:
[23, 16, 26, 26, 24, 3, 21, 1, 7, 24, 15, 3, 25, 20, 6, 13, 10, 8, 20, 12, 2, 0]

It fails after the first one (23). I believe my implementation of idx using np.random.choice is incorrect. I belive I’m implementing the probabilitieds or range wrongly. Thanks for your help

Hi @francktchafa ,

Please post a fresh query with error message to get a speedy response.