Sequence Modeling Week 1 -> Assignment 2 Dinosaurs Island -> Exercise 4 - Modeling

  1. My output from the training model looks like this. Not sure why the generated names are so long, not seem right. Any idea what could cause it?

  2. Why do we have the assert statement like:
    assert last_name == ‘Trodonosaurus\n’, “Wrong expected output”

why the last_name has to be exactly “Trodonosaurus\n” since we randomized the training sample list?

Thanks

beginning of output

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]
Y = [20, 21, 18, 9, 1, 19, 1, 21, 18, 21, 19]

Iteration: 0, Loss: 23.084041

Nkzxwtdmfqoeyhsqwasjkjvu
Kneb
Kzxwtdmfqoeyhsqwasjkjvu
Neb
Zxwtdmfqoeyhsqwasjkjvu
Eb
Xwtdmfqoeyhsqwasjkjvu

j = 1535 idx = 1535
j = 1536 idx = 0
Iteration: 2000, Loss: 26.502484

Opwusololosaurustarosaurasputinanelulelangaloltonp
Knedalosatansaurustoncycgosantosauruscuruseurusaur
Lytronleronxeseuhusauruhitiylecidetalgangaloltonpm
Omaaltonacosaurustoncycgosantosauruscuruseurusauru
Xtosaurusaurustarosaurasputinanelulelangaloltonpmo
Ecalosasausaurustoncycgosantosauruscuruseurusaurus
Tromieronxerosaurusrucnsaurunhalumbeconaloltonpmol

Iteration: 4000, Loss: 24.785437

Optrrpdonosaurusmarmintochurymecheluidedikamnesaur
Lomabatronanthsaurusaurusaurpsjurusaurusaurusaurus
Mysourusaurusclrasaurusaurusaurusaurusaurleraurosa
Omabcosaurusaurustilaxanosaurusaurusaurusaurusauru
Wushhnisaurusaurusauruphonyoranchunchaphamolsieros
Edakpsanassurinitkicyikosaurusaurusaurusaurusaurus
Tosaurusaurusocrriosalosaururccesasaururaratonsaur

… and more

Iteration: 22000, Loss: 21.981231

Onyxusaurusaurustarimisoanuovelaneluamiangakiasaur
Lnecagosauruscrichypeeyamosaurusauriopterisceingto
Lyxusaurusaurustarimispansexiaceodtalgarcammastesa
Oleadosauruscrichypeeyamosaurusauriopterisceingtos
Wusteriopeuptosaurusstanshyilceleteniangainetomorm
Egadrondchuntekiupegybersaurusauriopterisaurussomi
Trodonsicriptomorbetocerauruseggxagiangamiatonosau


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

end of output

This is a really interesting bug! I’ve never seen it before in 5 years of mentoring this course. Looking at the logic, it is expecting the algorithm to generate a newline character at some point. If it doesn’t, then it cuts off the length at 50. Maybe you did not initialize the variable that contains the newline that is being used to terminate the loop? So you’re just hitting length 50 on every name, but you didn’t have that problem on the first iteration. Hmmmm.

Maybe we need to look at the code. We can’t do that in public but I’ll send you a DM about how to proceed.

Thanks paulin. please let me know how to share my code with you.

Here is my implementation part of model(…)

{moderator edit - solution code removed}

It is that line there. Everyplace you see “None”, it means you need to fill in some code. So it never sees the newline character and you hit 50 on every name.

The way you are initializing Y has more problems than just the incorrect newline. In fact you don’t use the newline character at all. It needs to play a role in how Y is defined, right?

1 Like

thanks for pointing out. My bad. But even I update the code for Y like below, I still get similar error:
# Set the labels Y (see instructions above)
ix_newline = char_to_ix[‘\n’]
Y = single_example_ix+[ix_newline]

That looks correct to me and I tried exactly your implementation and it worked for me. Are you sure you clicked “Shift-Enter” on the “model” cell before you ran the training again? Just typing new code in a function cell and then calling it again runs the old code. Or maybe there is still something else wrong somewhere else …

Try “Kernel → Restart and Clear Output” followed by “Cell → Run All” and see if that works. That makes sure that “What you see is what you get”. If it still fails, please show us your output results.

Thanks paulingpaloalto. After Kernel restart, it works. You are so wonderful, thanks again

It is great news that it was something simple like that. So that proves that your code was actually correct, but the runtime state of the notebook was not inconsistent, because your new code had not been “compiled” (well, intepreted) yet.