Help (C5-W1-WB2) Loss is lower than expected result

Hi,

I don’t know what I am doing wrong.

In the Course 5 (Sequence modeling), Week 1, Dinosaur Test, for the the “model” assignment I get a loss (19.746477) which is lower than the expected value (22.728886). I am unsure what I could be doing wrong. I need some help debugging the problem. Could someone please help me?

Thanks,

We can’t directly see your notebooks, but we can try to help. For starters, it might help to see the complete output that you get or at least the output from the last set of iterations. How do the names compare to the “expected” values?

One common mistake is to use the sorted name list as the input, instead of the scrambled version of the list that they generate for you in the template code. That will give different, but reasonable looking, names, although I think the cost in that case is pretty close to the 22.xxxx value.

Hi Paul,

Thank you for your response. The last iteration looks reasonable:

Iteration: 22000, Loss: 19.746477

Leutosaurus
Ikeda
Iutosaurus
Lacadroma
Yston
Ecadosaurus
Utodonatetitos

I checked to see if I was using the shuffled list, and yes, I am:

# Build list of all dinosaur names (training examples).
examples = [x.strip() for x in data_x]

# Shuffle list of all dinosaur names
np.random.seed(0)
np.random.shuffle(examples)

And this is how I am creating the idx and the single examples:

    # Set the index `idx` (see instructions above)
    idx = j % len(examples)
    
    # Set the input X (see instructions above)
    single_example = examples[idx]

It is possible I am using idx wrong.

Thanks,

All the code you show looks perfectly fine to me. But I do get different results:

Iteration: 22000, Loss: 22.728886

Onustreofkelus
Llecagosaurus
Mystolojmiaterltasaurus
Ola
Yuskeolongus
Eiacosaurus
Trodonosaurus


last_name Trodonosaurus

All tests passed!

Of course there is more code in this routine than that, so the difference must be elsewhere. BTW I assume all your previous subroutines passed their test cases. It may be time to graduate to looking at source code for real. Please check your DMs for a message from me.

1 Like

Just to close the loop on the public thread here: Saurav and I had a DM conversation to look at the code. It turns out the issue is that you need to “prepend” the element [None] to the X input list before passing it to optimize. They discuss this in the instructions, pointing out that doing that tells rnn_forward that it is starting on a new word and results in x^{<0>} being set to 0. If you look carefully at how the logic works, it turns out that the main purpose of X in this code is to initialize Y, which is used as the “labels” to drive training. It’s only the prepended first element that is actually used directly from the X list as input.

1 Like

Thank you, Paul, for your help. This helped me to keep going forward. I shall come back to this again at some later time to play.