Week1 Assignment 2 - model

In the definition of X, it is explained in the instructions that we need to prepend the list [None] to the list of input characters. But then an error is raised later in the call for the function: optimise.
The error is:
TypeError: ‘NoneType’ object is not subscriptable

I’m not sure what to do …

Typically that error means you have another error in your code, or you left a “None” statement in your code that needs to be replaced with real code.

As Tom says, e.g. maybe you didn’t set X correctly. I “borrowed” the print statement from the “verbose” debug logic later and put that right after my logic to initialize X and Y and here’s what I see:

len(examples) = 1536
 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] 

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] 

Iteration: 0, Loss: 23.087336

vocab_size = 27
Nkzxwtdmfqoeyhsqwasjkjvu
vocab_size = 27
Kneb

If that doesn’t shed any light, it might be worth showing us the actual exception trace that you got.

Found the bug!
One bug is due to inaccurate instructions: “… *Prepend the list [ None ] in front of the list of input characters. …”
As I understood it, in the definition of X the None should be prepend to the list of characters. Your print statements made me realise that it should be prepend to the list of indices.

The second bug was that I defined Y to be slice + append at the same time: X[1:].append(ix_newline).
Apparently these should be separated in order to work: first assign the slice to Y, then Y.append(…).

Thank you for helping!