Dino character level language model - indexing examples

Hi everyone,

I’m stuck with the model() function in the dinosaur name character level language model programming exercise.

The unit test throws the following error:

----> 3 assert last_name == 'Trodonosaurus\n', "Wrong expected output"
      4 print("\033[92mAll tests passed!")

AssertionError: Wrong expected output

Looking at the debugging information, this seems to be a problem with the indexing since one of the sampled names in the list printed at iteration 2000 appears to be an empty string. The index itself looks like it’s behaving fine though:

j =  1535 idx =  1535
j =  1536 idx =  0
Iteration: 2000, Loss: 27.852178



Does anyone have any ideas as to what might be going wrong? Last name at iteration 22k is “Ceanosaurus”

Thank you!


It bugged me so much that I ended up working it out after all - so here’s the solution in the unlikely case anyone else hits this problem:

The code was correct but after reloading the workbook I missed re-running the cell that sorts the character vector to generate the char_to_ix dictionary:

chars = sorted(chars)

This lead to a different order of characters in the index and a different end result in sampled names.

Thanks for the explanation.
Personally, I got in the habit of running all the cells when I start a work session.

1 Like

I struggled with a similar error for more than one hour…

If any one pass by here, make sure you used the stripped list of example and not the original “data_”.


Same as Yassine happened to me.
Before the assembly of X and Y vectors, param data_x is shuffled in a new set with names in different order. So make sure you use the variable “examples” to create X and Y data.
All the best!

Please some help, I know it needs to be used “examples” instead of data_x, also, I restarted the kernel and made sure to run the cell with the sorted. An yet, I am still getting assertion error. I got the following which to me is correct:

j = 0 idx = 0
single_example = turiasaurus
single_example_chars [‘t’, ‘u’, ‘r’, ‘i’, ‘a’, ‘s’, ‘a’, ‘u’, ‘r’, ‘u’, ‘s’]
single_example_ix [20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19]
X = [None, 20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19]
Y = [20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19, 0]

Thanks for help!