DLS/Course5/Week1 Dinosaurus_Island_Character_level_language_model

I’m getting an error in the sampling function as follows;

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

<ipython-input-40-a13d660e654a> in sample_test(target)
----> 9     indices = target(parameters, char_to_ix, 0)
     10     print("Sampling:")
     11     print("list of sampled indices:\n", indices)

<ipython-input-39-69920f8c406b> in sample(parameters, char_to_ix, seed)
     56         # Step 3: Sample the index of a character within the vocabulary from the probability distribution y
     57         # (see additional hints above)
---> 58         idx = np.random.choice(range(len(y.ravel())), p= y.ravel())
     60         # Append the index to "indices"

mtrand.pyx in numpy.random.mtrand.RandomState.choice()

ValueError: probabilities do not sum to 1

Any help is appreciated. Thank you.

Perhaps your ‘y’ variable has the wrong values. Did you use softmax()?

Hey @TMosh,
Thank you for your help. I found the issue. I had used the wrong shapes in initializing with zeros. Correcting it did the trick. I think it was some sort of a broadcasting error that caused this all. Anyway, it’s sorted now. Thanks a lot.