Dinosaurus_Island_Character_level_language_model

Need help with Course 5 Week 1

Dinosaurus_Island_Character_level_language_model

I’m getting the following Error and Output.

j is 0
idx is 0
number of iterations 22001
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]]
ix newline 0
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]

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

in model(data_x, ix_to_char, char_to_ix, num_iterations, n_a, dino_names, vocab_size, verbose)
88 if j % 2000 == 0:
89
—> 90 print('Iteration: %d, Loss: f' (j, loss) + ‘\n’)
91
92 # The number of dinosaur names to print

TypeError: only size-1 arrays can be converted to Python scalars

Any tips?

It seems there is an error in your code that generates either the ‘j’ or ‘loss’ value.

• ‘j’ iterates through the for-loop range of the “num_iterations” value.

• ‘loss’ originates in the “curr_loss” value returned from your optimize() function.

j seems fine, it just errors out after one pass at current loss

``````    curr_loss, gradients, a_prev = optimize(X, Y, a_prev, parameters, learning_rate = 0.01)
print("current loss is ", curr_loss)
``````

I’m getting this for the value which is probably where it’s breaking.

current loss is [6.5920883 6.5920883 6.5920883 6.5920883 6.5920883 6.5920883 6.5920883
6.5920883 6.5920883 6.5920883 6.5920883]

Is the problem with my optimize function? That seemed ok. The arguments seem pretty straight forward so not quite sure what’s going on.

Ideas?

Ok, I got past that part. It was an issue with my value for Y. So it J does start to loop, but breaks a J = 1536. See below output:

j is and type 1535 <class ‘int’> idx is and type 1535 <class ‘int’> number of iterations and type 22001 <class ‘int’> single example jinzhousaurus <class ‘str’> single example chars [‘j’, ‘i’, ‘n’, ‘z’, ‘h’, ‘o’, ‘u’, ‘s’, ‘a’, ‘u’, ‘r’, ‘u’, ‘s’] <class ‘list’> single example ix [10, 9, 14, 26, 8, 15, 21, 19, 1, 21, 18, 21, 19] <class ‘list’> X [None, [10, 9, 14, 26, 8, 15, 21, 19, 1, 21, 18, 21, 19]] <class ‘list’> ix newline 0 <class ‘int’> Y [10, 9, 14, 26, 8, 15, 21, 19, 1, 21, 18, 21, 19, 0] <class ‘list’> current loss is 5.949467721212252 () gradients len 5 a prev (50, 1) j = 1535 idx = 1535 j is and type 1536 <class ‘int’> idx is and type 0 <class ‘int’> number of iterations and type 22001 <class ‘int’>

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
3 assert last_name == ‘Trodonosaurus\n’, “Wrong expected output”
4 print("\033[92mAll tests passed!")

in model(data_x, ix_to_char, char_to_ix, num_iterations, n_a, dino_names, vocab_size, verbose)
53
54 # Set the input X (see instructions above)
—> 55 single_example = examples[j]
56 print(“single example”, single_example, type(single_example))
57 single_example_chars = [c for c in single_example]

IndexError: list index out of range

Did you ever resolve this? I am having the same problem.

1 Like

Have a look at the shape of X and Y, they should not be 2-dim