Week 3 assignment: bug in the test

hi Rashmi
thanks
Here is the error I got in nn_model cell:

Cost after iteration 0: 0.692739
Cost after iteration 1000: 0.000218
Cost after iteration 2000: 0.000107
Cost after iteration 3000: 0.000071
Cost after iteration 4000: 0.000053
Cost after iteration 5000: 0.000042
Cost after iteration 6000: 0.000035
Cost after iteration 7000: 0.000030
Cost after iteration 8000: 0.000026
Cost after iteration 9000: 0.000023
W1 = [[-0.65848169 1.21866811]
[-0.76204273 1.39377573]
[ 0.5792005 -1.10397703]
[ 0.76773391 -1.41477129]]
b1 = [[ 0.287592 ]
[ 0.3511264 ]
[-0.2431246 ]
[-0.35772805]]
W2 = [[-2.45566237 -3.27042274 2.00784958 3.36773273]]
b2 = [[0.20459656]]


AssertionError Traceback (most recent call last)
in
----> 1 nn_model_test(nn_model)

~/work/release/W3A1/public_tests.py in nn_model_test(target)
292 assert output[“b2”].shape == expected_output[“b2”].shape, f"Wrong shape for b2."
293
→ 294 assert np.allclose(output[“W1”], expected_output[“W1”]), “Wrong values for W1”
295 assert np.allclose(output[“b1”], expected_output[“b1”]), “Wrong values for b1”
296 assert np.allclose(output[“W2”], expected_output[“W2”]), “Wrong values for W2”

AssertionError: Wrong values for W1

1 Like

(Post deleted by author.)

1 Like

Hi Sahar,

Ai_curious has already given you the clue. Work on that structure to get the right outcome.

1 Like

thanks
solved by updating the notebook (I had done it before but did not know that I have to write the code again in new ipynb file)
the code was fine

1 Like

Oh great! glad you worked it out on your own!

1 Like

Hi @Mubsi @paulinpaloalto
I am getting an assertion error in Week 3 exercise 8 (nn_model)
I would appreciate it if you could help me to find out what is wrong
I checked every single code multiple times but still wonder why the result of every iteration is nan
my id is ebylrvbd

Cost after iteration 0: 0.693198
Cost after iteration 1000: nan
Cost after iteration 2000: nan
Cost after iteration 3000: nan
Cost after iteration 4000: nan
Cost after iteration 5000: nan
Cost after iteration 6000: nan
Cost after iteration 7000: nan
Cost after iteration 8000: nan
Cost after iteration 9000: nan
W1 = [[ -16151.48761099   40094.87691492]
 [-360708.80502007  896694.73776285]
 [  17194.29194027  -42664.68066471]
 [ 209432.69985165 -519775.95648378]]
b1 = [[  -9454.14941358]
 [-211131.57910882]
 [  10053.6841467 ]
 [ 122511.81043522]]
W2 = [[  -9.46131057 -211.85626202   10.08675527  122.71208997]]
b2 = [[1998.68544]]
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-53-1243cded3c7d> in <module>
----> 1 nn_model_test(nn_model)

~/work/release/W3A1/public_tests.py in nn_model_test(target)
    292     assert output["b2"].shape == expected_output["b2"].shape, f"Wrong shape for b2."
    293 
--> 294     assert np.allclose(output["W1"], expected_output["W1"]), "Wrong values for W1"
    295     assert np.allclose(output["b1"], expected_output["b1"]), "Wrong values for b1"
    296     assert np.allclose(output["W2"], expected_output["W2"]), "Wrong values for W2"

AssertionError: Wrong values for W1

kind regards,
Sarah

1 Like

The first place I would check is your “update parameters” logic. Are you sure that function passed its tests? E.g. make sure you are subtracting the update term, not adding it. Your W and b values are crazy large.

1 Like

Yes, its tests passed

1 Like

Hmmm, ok, then it looks like we need a new theory. So the bug must be in the nn_model routine. Are you sure that the variable names are consistent for the parameters and gradient dictionaries from when you call forward and back prop versus the names you pass to “update parameters”?

1 Like

Everything seems to be right
I really don’t know what the problem is
Is it possible for you to check my code directly using my lab id? or I can send them to you in a direct message if I’m allowed

1 Like

Only the course staff can see other people’s work. The mentors do not have that “superpower”. Please check your DMs for a message from me.

1 Like

It turns out that it’s a variant of the problem that I theorized about there. Look carefully at how you store the return values from forward propagation. You misspelled one of the variable names which results in the wrong data being used.

1 Like

Hello! my id is “nzwpnnsn”.
I couldn’t solve the problem even though there are similar problems in this thread.
Other tests are passed except nn_model_test(nn_model) . I’ve attached the screenshot.

Thank you in advance.

1 Like

Hi, Aashish.

Only the course staff can actually look at anyone’s notebook by using the notebook ID. The mentors are just fellow student volunteers and we do not have that “superpower”. But check your DMs for some alternate ways to approach this type of problem.

1 Like

It looks like your output is the ones when you set the seed for a random number generator to 2.
This test sets “np.random.seed(3)” and compares results. If you (or any of functions that you use) override this seed, then, the output will be different from expected.
Possible cases are

  1. inside "initialize_parameters()
  2. in “nn_model()” before calling “initialize_parameters()”.

I think it’s worth to check.

1 Like

Thank you Nobu_Asai, It resolved the problem but I had to copy the initialize function which I think affected the grading system and now got stuck with 5.2 - Test the Model on the Planar Dataset It shows the following error:

1 Like

Hi, Aashish,

Check the way you are putting the value inputs for the cost function. There should be 2 instead of 3.

2 Likes

Initialize_parameters() is already in this note book. I’m afraid that you copy/paste some functions, and also modified functions itself to pass additional parameters. That should cause additional problems.

Please revert back all functions to original forms.

2 Likes

Yes, Aashish!

Nobu is right. I have mentioned the same thing in my previous reply. You are passing an additional parameter instead of two.

2 Likes

Hi! Nobu_Asai,
If I changed the initialize_parameters function’s np.random.seed(2) to 3 then it causes problem in test case right after that cell but works fine for nn_model function which had an issue before.
That’s why I had to clone the function.

Thank you.

1 Like