C5W1 dinosaurus exercise 4

Week 1 Exercise 4 Model
I got the following error message. All my previous exercises have passed the test. I am not sure why this last one is not working. The expected Loss is 27, but mine is way lower. At the beginning of the iteration, the print out X and Y are as below.
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: 22000, Loss: 0.294620

Iavesaqr
Esitoriasaurus
Esitoriasaurus
Iaeaurus
Urus
Andoravenator
Saurur


AssertionError 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!”)

AssertionError: Wrong expected output

Even if your previous functions are correct, they can still malfunction if you call them incorrectly or with the wrong data. So the place to look is in your top level model code. One common mistake is to use the sorted inputs instead of the scrambled version that they create for you in the template code, but making that mistake causes different results at 22000 iterations than what you are showing there. I don’t think I’ve ever seen a case in which the same name gets generated twice in a row. That might be a clue: maybe you are calling sample incorrectly from your model.

This code “np.random.shuffle(examples)” is to scramble the samples, correct? They are there. Also, the part that calls sample function is in the template too and I didn’t write it. Not sure how it can be called incorrectly.

At the first iteration, the loss function is 23.087336, which is already lower than the expected output at the end of the iteration. Does that say anything?

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

Ok, maybe it’s time to just look at your code. We aren’t supposed to do that here on a public thread, but please check your DMs for a message from me about how to proceed.

Actually here’s one more question: you are running this on the course website, not on your local computer, right? If you are running in a different environment, you might well get different results because of “versionitis” issues with all the various libraries and packages.

Just to close the loop on the public thread, all the code was correct except for one logic error in the model function on the line that keeps the index value from looping past the end of the input dataset when the number of iterations is large. They explain in the instructions that you need to use a “modulo” operation there “%”. Please make sure you read carefully and understand what they are saying in that part of the instructions.