My code fails some test cases, I feel it is because I use the wrong parameters for AL. I give AL parameters A_prev, parameters[‘W’+str(l)], parameters[‘b’+str(l)], “sigmoid”
Note that it is not iterating but taking the last value of l, Is this correct?
I printed the value of AL, below is also screenshot of the output
Hi @Olamilekan_Waliyu_Ra , thanks and welcome to the discourse community! I assume this is exercise 5 of week 4?
In the exercises, you have two implement two forward activation steps, one in a loop (which is the RELU one), and one at the end (which is the SIGMOID one). I am not sure which one you are referring two, as the forward activation steps are slightly different in both cases. It seems that you are talking about the activation steps that is in the loop. If so, what would be the activation function that you need to use?
Yes, thats correct. Its the Exercise 5 of week 4. I think the first function with relu works fine but the sigmoid own is where I have the issues. AL is the final output which I used the linear_activation_forward function written earlier in the notebook which the parameters I stated in the earlier comment. What am I doing wrong, I can’t seem to figure where I am getting it wrong.
To reiterate, the first part uses same function but the W[l] and b[l] of each iteration to update A and caches, the second part uses same function with the the last values of W and b (W2 and b2). Is that correct/
Ok @Olamilekan_Waliyu_Ra , if that is the case, note that the for-loop that you just passed has range (1, L), which means it is running from 1 to L-1. So what is the value of l at the end of the for loop? And what is the value of A_prev at the end of the for loop? Based on that, have a think about whether you are passing the correct values to the final forward_activation. That might help you understanding whether there is an issue in it.
2 Likes
Note that the shape of your AL value is even wrong. It should be 1 x 4, but yours is 3 x 4. Also notice that the test throws lots of other errors. I think you should step back and start by looking at the “dimensional analysis” on this test case. Here’s a thread about that.
Then I added print statements to my code to show the intermediate results at all the layers. Try adding similar prints and compare your values.
A1 = [[0. 3.18040136 0.4074501 0. ]
[0. 0. 3.18141623 0. ]
[4.18500916 0. 0. 2.72141638]
[5.05850802 0. 0. 3.82321852]]
A2 = [[ 2.2644603 1.09971298 0. 1.54036335]
[ 6.33722569 0. 0. 4.48582383]
[10.37508342 0. 1.63635185 8.17870169]]
A3 = [[0.03921668 0.70498921 0.19734387 0.04728177]]
AL = [[0.03921668 0.70498921 0.19734387 0.04728177]]
A1 = [[0. 3.18040136 0.4074501 0. ]
[0. 0. 3.18141623 0. ]
[4.18500916 0. 0. 2.72141638]
[5.05850802 0. 0. 3.82321852]]
A2 = [[ 2.2644603 1.09971298 0. 1.54036335]
[ 6.33722569 0. 0. 4.48582383]
[10.37508342 0. 1.63635185 8.17870169]]
A3 = [[0.03921668 0.70498921 0.19734387 0.04728177]]
A1 = [[0. 3.18040136 0.4074501 0. ]
[0. 0. 3.18141623 0. ]
[4.18500916 0. 0. 2.72141638]
[5.05850802 0. 0. 3.82321852]]
A2 = [[ 2.2644603 1.09971298 0. 1.54036335]
[ 6.33722569 0. 0. 4.48582383]
[10.37508342 0. 1.63635185 8.17870169]]
A3 = [[0.03921668 0.70498921 0.19734387 0.04728177]]
A1 = [[0. 3.18040136 0.4074501 0. ]
[0. 0. 3.18141623 0. ]
[4.18500916 0. 0. 2.72141638]
[5.05850802 0. 0. 3.82321852]]
A2 = [[ 2.2644603 1.09971298 0. 1.54036335]
[ 6.33722569 0. 0. 4.48582383]
[10.37508342 0. 1.63635185 8.17870169]]
A3 = [[0.03921668 0.70498921 0.19734387 0.04728177]]
All tests passed.
Note that the test cell runs a bunch of tests besides the “2hidden” one. Just try analyzing the first set of A1 to A3 values. Perhaps this counts as belaboring the obvious, but the fundamental point of forward propagation is that the output of each layer is the input to the next one. So as soon as one of them is wrong, everything further down the line is doomed.
I eventually got it. Works now, Thanks!