C5 W1 A2: Problem running the exercise code


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

in model(data, ix_to_char, char_to_ix, num_iterations, n_a, dino_names, vocab_size)
50 # Perform one optimization step: Forward-prop → Backward-prop → Clip → Update parameters
51 # Choose a learning rate of 0.01
—> 52 curr_loss, gradients, a_prev = optimize(X, Y, a_prev, parameters, learning_rate = 0.01)
53
54 ### END CODE HERE ###

in optimize(X, Y, a_prev, parameters, learning_rate)
32
33 # Forward propagate through time (≈1 line)
—> 34 loss, cache = rnn_forward(X, Y, a_prev, parameters)
35
36 # Backpropagate through time (≈1 line)

~/work/W1A2/utils.py in rnn_forward(X, Y, a0, parameters, vocab_size)
100
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])
103
104 cache = (y_hat, a, x)

IndexError: index 46 is out of bounds for axis 0 with size 27

An out of bounds error means your are trying to access an element of a list (matrix) beyond its size.

hi i don’t know why but now is working i have done nothing (i know the error meaning but i was not understanding why :))

1 Like

or better
if i change the call to the module in this way is working:
#parameters, last_name = model(data.split(‘\n’), ix_to_char, char_to_ix, 22001, verbose = True)

parameters, last_name=parameters = model(data, ix_to_char, char_to_ix)

I think you posted this message in the wrong course forum. There are no RNN’s in the Machine Learning Specialization. They are in the Deep Learning Specialization, though.

I’ll move it the DLS Course 5 Week 1 forum.