Week 4 Exercise 9 error

Paul I just changed the dA + str(l) for the grads, so the print step showed 2 step passed but 1 failed.

Also I did change the dA + str(L-1) with this step.

Ok, you’re making progress! Now you are getting dA0 output and it’s the correct shape, but it’s got the wrong values. So how could that happen? If your linear_activation_backward function passes the test cases, then you must have called it incorrectly. Did you remember that the activation for the hidden layers is “relu”? It’s only “sigmoid” at the output layer, right?

so now I need to make change in the relu activation code for the backward propagation right?

No, you don’t need to change the ReLU code itself, you need to tell linear_activation_backward to use “relu” for the hidden layers, right? That’s how it worked on forward propagation: we used “relu” for the hidden layers and “sigmoid” for the output layer. So on back prop, it has to be the same.

1 Like

PAUL I MUST SAY YOUR ARE VERY PATIENT WITH LEARNER :see_no_evil:

I hope that means that you have gotten your code to work now. And that some lessons have been learned about how to approach debugging a problem like this. :smile:

The higher level “meta” point here is that people who are learning to program may think that debugging is just an annoying thing that they have to put up with. That’s the wrong way to look at it: it is a key skill that is fundamental to succeeding as a programmer. If you just “know” the language, but don’t know how to solve problems when your code doesn’t work, then you’re not really a programmer yet. What’s the point if your code doesn’t work?

So the point is to treat this type of learning as an important part of the whole process, not as just some annoying side issue.

Onward! :nerd_face:

1 Like

hey Paul, sorry for late reply. I got all the test cleared today. I agree but for a non-IT person it is a challenge especially they are learning. But your replies does help a lot. thank you again.

Error
I’m getting the same values for dA0 and dA1 which is equal to the expected value of dA1. Also, the shape of dA0 is incorrect.

Well, notice that the test case has 2 layers here. Since back prop is exactly the mirror image of forward prop, the output layer happens first and is separate, so that calculation produces dW2, db2 and dA1. Then you go into the loop that goes backwards over the hidden layers and that produces dW1, db1 and dA0. There’s only one iteration of the loop, because it’s a 2 layer network.

So that suggests where to look: it must be the logic in your “for” loop that is incorrect. What is different about that case?

Here’s my output for that first test case:

dA0 = [[ 0.          0.52257901]
 [ 0.         -0.3269206 ]
 [ 0.         -0.32070404]
 [ 0.         -0.74079187]]
dA1 = [[ 0.12913162 -0.44014127]
 [-0.14175655  0.48317296]
 [ 0.01663708 -0.05670698]]
dW1 = [[0.41010002 0.07807203 0.13798444 0.10502167]
 [0.         0.         0.         0.        ]
 [0.05283652 0.01005865 0.01777766 0.0135308 ]]
dW2 = [[-0.39202432 -0.13325855 -0.04601089]]
db1 = [[-0.22007063]

Notice that all your other values are correct. So it’s just the assignment of the dA^{[l]} value in the for loop that is incorrect.