C5_W1_A2: Code Cell UNQ_C3: Unexpected error (KeyError('da_next')) occurred during function check

Although My code is giving me correct result during running the notebook.
But when I submit the result I got this:

Code Cell UNQ_C1: Function 'clip' is correct.
Code Cell UNQ_C2: Function 'sample' is correct.
Code Cell UNQ_C3: Unexpected error (KeyError('da_next')) occurred during function check. We expected function `optimize` to return Test 3 failed. Please check that this function is defined properly.
Code Cell UNQ_C4: Function 'model' is correct. 
If you see many functions being marked as incorrect, try to trace back your steps & identify if there is an incorrect function that is being used in other steps.
This dependency may be the cause of the errors.

This is by optimize_test function’s result

Loss = 126.50397572165389
gradients["dWaa"][1][2] = 0.19470931534713587
np.argmax(gradients["dWax"]) = 93
gradients["dWya"][1][2] = -0.007773876032002162
gradients["db"][4] = [-0.06809825]
gradients["dby"][1] = [0.01538192]
a_last[4] = [-1.]
All tests passed!

Expected output

Loss = 126.50397572165389
gradients["dWaa"][1][2] = 0.19470931534713587
np.argmax(gradients["dWax"]) = 93
gradients["dWya"][1][2] = -0.007773876032002162
gradients["db"][4] = [-0.06809825]
gradients["dby"][1] = [0.01538192]
a_last[4] = [-1.]

Where is the problem?

When I run the code in my local machine I got a wrong result for exercise 4:

Piuskrangmiaus
Miea
Musus
Pecaerope
Xuspangosaurus
Eiaantoe
Trodon


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In [66], line 2
      1 parameters, last_name = model(data.split("\n"), ix_to_char, char_to_ix, 22001, verbose = True)
----> 2 assert last_name == 'Trodonosaurus\n', "Wrong expected output"
      3 print("\033[92mAll tests passed!")

AssertionError: Wrong expected output

So which function is actually wrong? Though I got a correct result for exercise 3.

The problem is your code doesn’t work correctly when the grader tests it with a different set of data.

Most often this problem is due to your code in the notebook using a global variable that isn’t supported by the grader.

The error suggests you’re using the variable ‘da_next’ incorrectly.

Sorry, but we don’t support debugging the assignment whne you run it in your local machine. We can only help with your results using Coursera Labs via your browser.

1 Like

Hello @TMosh ,

Thank you. I just created a new notebook and copied the solution here. Now its working.I think in the previous notebook I had created some new cells and forgot something to remove. Anyway, its working now.

One thing I want to ask you that, the notebook giving me right result on the Coursera lab, so in my local machine. only the model function giving me a different result for the same notebook as I showed before. I assume its because of the random function ( as the function is correct only it gives a different result). Is that so? I don’t need any answer. I just wanted to know you thoughts. Anyway, thank you once again.

Sorry, but I don’t have any opinion about how the notebooks run on your local machine.

Hi TMosh:
I also get the message: Code Cell UNQ_C3: Unexpected error (KeyError(‘da_next’)) occurred during function check. We expected function optimize to return Test 3 failed. Please check that this function is defined properly. for Week 1 assignment 2.
But I do not have any da_next variables… And I run from scratch my notebook and pass all the tests but grader fails my UNQ_C3 test. Can you give a hint how to debug? Thank you

Starting a new thread would be more appropriate given that this thread is over a year cold.

Please post a screen capture image that shows the entire error message.