W 3 A1 | Ex-6 | Unit test assertion: np.allclose() is False

The unit test is asserting that np.allclose() is False, but it should be True. To be sure, I ran it manually and I got True. It’s only off by 10^-8, so it should still pass. Can someone please fix this or am I missing something?

Hey Justin @ch3njus,

Welcome to this community!

I think this is not a MLS assignment, and I do not have access to it. Which course is this assignment from? I can move this thread to the right category for you this time.

From your screenshot, it appears that you passed the first test but not passing one of the other tests embedded in backward_propagation_test(...). As a general tips, there should be something not right in your implementation so it cannot always calculate the correct dW1, and you may want to run your implementation with a simple set of inputs, then print out all intermediate variables used in your implementation to keep track of the progress of your code, and find out which step doesn’t go as expected.


Sorry I meant to label this under Deep Learning specialization week 3.

The assignment sets np.random.seed(2), so it should produce exactly the same result as what’s expected by the unit test. Here, it’s only off by 10^-8, so the unit test should pass whether it’s exactly the same or approximately the same.

Hello @ch3njus,

I agree that this ↓
Screenshot from 2022-10-08 12-40-40

matches with this ↓
Screenshot from 2022-10-08 12-40-45

and I see that you verified that by ↓

What I am trying to say is, all of the above is only about the first test. If you look at the first screenshot again and focus on this particular line:

Screenshot from 2022-10-08 12-44-45

It says that the error you are encountering comes from the set of tests in backward_propagation_test(...).

Knowing that you passed the first test but not all of them, I made my previous suggestion.


Hello CH3NJUS.

Welcome to the community.

As Raymond says, there is definitely something wrong you are implementing while doing backpropagation and that is why you are receiving wrong values for db2, dW1, db1 & dW2.

The formulas have already been given in the instructions of the notebook. Please have a closer look to each of the implementations.

I found my bug. I was using cache['Z1'] instead of A1 for computing dZ1.


I’m confused tho. The note say that the input to the derivative of tanh should be Z1, but the tip says (1 - np.power(A1, 2))

Screen Shot 2022-10-08 at 11.09.12 AM

Why are we using A1 instead of cache['Z1']? I think this is where I generally get confused when implementing neural networks.

Hello Justin,

If you have gone through the slides and the instructions then it is clearly stated over there on how you have to implement dZ1 for calculating the gradient descent while doing the backpropagation.

Each of the terms have clearly been mentioned in the tips. You’re working on a whole equation for the computation.

𝑔1 is the tanh activation function, if 𝑎=𝑔1 then 𝑔[1]′(𝑧)=1−𝑎2. So you can compute 𝑔[1]′(𝑍[1]) using (1 - np.power(A1, 2))

Ah I see. That’s specifically for tanh. I was being careless. Thank you for pointing that out.