# C5W1 dinosaurus exercise 4

**URL:** <https://community.deeplearning.ai/t/c5w1-dinosaurus-exercise-4/567251>\
**Category:** Sequence Models\
**Tags:** week-module-1, coursera-platform\
**Created:** [February 7, 2024, 5:04pm UTC](https://community.deeplearning.ai/t/c5w1-dinosaurus-exercise-4/567251 "2024-02-07T17:04:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kejun\_Zhang](https://avatars.discourse-cdn.com/v4/letter/k/f6c823/32.png) [@Kejun\_Zhang](https://community.deeplearning.ai/u/Kejun_Zhang)\
**Post date:** [February 7, 2024, 5:04pm UTC](https://community.deeplearning.ai/t/c5w1-dinosaurus-exercise-4/567251/1 "2024-02-07T17:04:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [February 7, 2024, 5:28pm UTC](https://community.deeplearning.ai/t/c5w1-dinosaurus-exercise-4/567251/2 "2024-02-07T17:28:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kejun\_Zhang](https://avatars.discourse-cdn.com/v4/letter/k/f6c823/32.png) [@Kejun\_Zhang](https://community.deeplearning.ai/u/Kejun_Zhang)\
**Post date:** [February 7, 2024, 6:19pm UTC](https://community.deeplearning.ai/t/c5w1-dinosaurus-exercise-4/567251/3 "2024-02-07T18:19:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [February 7, 2024, 6:25pm UTC](https://community.deeplearning.ai/t/c5w1-dinosaurus-exercise-4/567251/4 "2024-02-07T18:25:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [February 8, 2024, 12:09am UTC](https://community.deeplearning.ai/t/c5w1-dinosaurus-exercise-4/567251/5 "2024-02-08T00:09:29Z")

</div>

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.
