(course 1, week 3, exercise 8) AssertionError: Wrong values for W1

I am getting AssertionError: Wrong values for W1 in the nn_model function. My output and the expected output is completely identical.

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
7 print("b2 = " + str(parameters[“b2”]))
8
----> 9 nn_model_test(nn_model)

~/work/release/W3A1/public_tests.py in nn_model_test(target)
273 assert output[“b2”].shape == expected_output[“b2”].shape, f"Wrong shape for b2."
274
→ 275 assert np.allclose(output[“W1”], expected_output[“W1”]), “Wrong values for W1”
276 assert np.allclose(output[“b1”], expected_output[“b1”]), “Wrong values for b1”
277 assert np.allclose(output[“W2”], expected_output[“W2”]), “Wrong values for W2”

AssertionError: Wrong values for W1

image

2 Likes

Hi, Mukul.

Would you please try an experiment for us and see if that changes the results? Click “File → Open” to get the file explorer view of the assignment. Then delete all the “utility dot py” files, like public_tests.py, test_utils.py and so forth. Just click the check box and then click the trash can icon and confirm the dialog. Then click “Help → Lab Help → Get Latest Version”. That will replace all those files with the current (latest) version.

Once you’ve done that, please run the tests again and let us know if that changes the results or not.

Thanks!
Paul

Where is “Help” button that i had to click

It is in the upper right corner of the window as highlighted in this screen shot:

Hi,
I also experienced the same issue even after I updated the files version. However, if I put the variables in front of the called function, i got an error “UnboundLocalError: local variable ‘parameters’ referenced before assignment”.

Would you be able to help with this?

Welcome to the community !

The error message said that you did not define “parameters” in this nn_model(). There are two possibilities.

  1. You forgot to implement one line of code above. It is to initialize “parameters”.
  2. Or, you initialize different variable, like “parameter”.

Please double check.

By the way, pasting code is not recommended. (traceback should be OK). Please remove it, thank you.

I got it working.

Thank you!

i’m having same issue cost function values are same as expected but the value of W1 is wrong i tried to run intialize parameters which also showed wrong values for W1 im using np.random.rand((a,b))*0.01. Can anybody help

That is the wrong rand function. Please have another careful look at the instructions. Notice that your values are all positive, but the expected values are both positive and negative. That’s also the wrong syntax for invoke one of the np.random functions: it is np.zeros and np.ones that take tuples as arguments.

1 Like

Thanks a lot it really helped find my error

1 Like

Hello Paul,

I am also getting the same AssertionError: Wrong values for W1, although all previous tests were passed. I followed your instructuctions on getting latest versions of files but it didn’t help.
Can you please help me with it?

Thank you!

I am getting following output:
Cost after iteration 0: 0.693497
Cost after iteration 1000: 0.693497
Cost after iteration 2000: 0.693497
Cost after iteration 3000: 0.693497
Cost after iteration 4000: 0.693497
Cost after iteration 5000: 0.693497
Cost after iteration 6000: 0.693497
Cost after iteration 7000: 0.693497
Cost after iteration 8000: 0.693497
Cost after iteration 9000: 0.693497
W1 = [[ 0.01788628 0.0043651 ]
[ 0.00096497 -0.01863493]
[-0.00277388 -0.00354759]
[-0.00082741 -0.00627001]
[-0.00043818 -0.00477218]]
b1 = [[0.]
[0.]
[0.]
[0.]
[0.]]
W2 = [[-0.01313865 0.00884622 0.00881318 0.01709573 0.00050034]]
b2 = [[0.]]

Notice that your cost values are not changing at all. The first thing to look for would be some problem in how you are doing the “update parameters” step. E.g. using the wrong variable name for the dictionary containing the parameters that is returned from the update parameters call.

Yes, I purposely made the mistake I described above and I get exactly the same incorrect values that you show:

Cost after iteration 0: 0.693497
Cost after iteration 1000: 0.693497
Cost after iteration 2000: 0.693497
Cost after iteration 3000: 0.693497
Cost after iteration 4000: 0.693497
Cost after iteration 5000: 0.693497
Cost after iteration 6000: 0.693497
Cost after iteration 7000: 0.693497
Cost after iteration 8000: 0.693497
Cost after iteration 9000: 0.693497
W1 = [[ 0.01788628  0.0043651 ]
 [ 0.00096497 -0.01863493]
 [-0.00277388 -0.00354759]
 [-0.00082741 -0.00627001]
 [-0.00043818 -0.00477218]]
b1 = [[0.]
 [0.]
 [0.]
 [0.]
 [0.]]
W2 = [[-0.01313865  0.00884622  0.00881318  0.01709573  0.00050034]]
b2 = [[0.]]

Yes, update_parameters was also my first checkpoint. Thank you for the help. A silly spelling mistake in nn_model was causing the issue. Fresh eyes could spot it. Sorry for the trouble.

1 Like

In the future, I recommend you check the age of a thread before you post a reply. In this case, the thread had been cold for 3 years.

Fortunately Mentor Paul is still active, but in many cases, old threads are no longer monitored. In that case, starting a new thread is a better strategy.

1 Like