C5W1 A2-Dinosaurus_Island EX-4 | list index out of range

When coding the model() function, I have defined the labels Y to be the same as X but shifted one index to the left and have added a newline character. But I am stucked with the error " list index out of range" in the rnn_forward function called by the optimize function.

Please, could you advise on what to modify in my code.


IndexError Traceback (most recent call last)
Input In [114], in <cell line: 1>()
----> 1 parameters, last_name = model(data.split(“\n”), ix_to_char, char_to_ix, 22001, verbose = True)
3 assert last_name == ‘Trodonosaurus\n’, “Wrong expected output”
4 print(“\033[92mAll tests passed!”)

Input In [113], in model(data_x, ix_to_char, char_to_ix, num_iterations, n_a, dino_names, vocab_size, verbose)
53 single_example_chars = [c for c in single_example]
54 single_example_ix = [char_to_ix[c] for c in single_example_chars]
—> 55 X = rnn_forward([None] + single_example_ix, single_example_ix, a_prev, parameters, vocab_size = 27)
57 # Set the labels Y (see instructions above)
58 ix_newline = char_to_ix[‘\n’]

File ~\OneDrive\Documents\data_scientist\FORMATION\DS\Coursera\deeplearning specialization\C5_Sequence Models\S1_Recurrent Neural Networks\TP02\utils.py:102, in rnn_forward(X, Y, a0, parameters, vocab_size)
99 a[t], y_hat[t] = rnn_step_forward(parameters, a[t-1], x[t])
101 # Update the loss by substracting the cross-entropy term of this time-step from it.
→ 102 loss -= np.log(y_hat[t][Y[t],0])
104 cache = (y_hat, a, x)
106 return loss, cache

IndexError: list index out of range

The instructions do not tell you to use rnn_forward() here. The instructions just point out why [None] has a special value in this model.

The key instruction here is is the second bullet: to prepend [None] to the list of example indices.

rnn_forward() is used indirectly later in this function, when it calls optimize().

Thanks for your comment.
I have removed the rnn_forward) function here and have defined only X, adding [None] as a flag.

My code is now running and I get “AssertionError: Wrong expected output”