Sequence Models_Week1_Assignment2_Sample function


Facing challenges with the sample function and my results do not match with my expected output, hence the error attached:

My results:
list of sampled indices:
[23, 16]
list of sampled characters:
[‘i’, ‘\n’]

Expected output:

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]
list of sampled characters:
 ['w', 'p', 'z', 'z', 'x', 'c', 'u', 'a', 'g', 'x', 'o', 'c', 'y', 't', 'f', 'm', 'j', 'h', 't', 'l', 'b', '\n']


Please post a screen capture image that shows the entire assert message, not just the last few lines.

What has me puzzled is that your first two indices are correct, but the corresponding characters are wrong.

The characters are looked-up via the ix_to_char dictionary, which is created in cell 4 in the notebook, and your code should not modify it. So I don’t understand how those two characters can be wrong.

Perhaps you’ve modified something in the notebook that you should not have.

Hi @TMosh , thanks for your quick response. I could not really understand it either but i ran the code this morning and it worked without any modification.

Below is the attached error I got yesterday:

But thanks again for the response. I really appreciate it

It’s possible that the notebook’s internal state (via its global variables) got out of sequence due to editing the notebook without restarting the kernel and running all the cells again.

With the notebooks in Course 5, you really have to be careful about modifying the code while you are debugging - because you will often have to re-run all of the cells if your code modifies any of the global assets.

1 Like

Thanks so much for your advice @TMosh. I really appreciate your help