Hello,
For the week 3 assignment for the backward_propagation function my result are identical to the expected ones but it seems that the tests do not pass. I double checked and I seems that I have the right function (I think) (the dW1 do not pass)
And I tried to make following question and all the tests pass
Lab ID: eefwivcunsqm
Thanks in advance
Note that there is more than one test case there. It’s possible to pass one test, but not all the tests, if you “hard-code” something such that it matches the first test.
Please show us the complete output that you get by running the test cell for backward_propagation
.
Also note that there is no real point in showing your lab ID: no-one but the course staff can actually see your work directly and they are usually too busy to be watching every post here.
Thanks for quick answer:
Output:
dW1 = [[ 0.00301023 -0.00747267]
[ 0.00257968 -0.00641288]
[-0.00156892 0.003893 ]
[-0.00652037 0.01618243]]
db1 = [[ 0.00176201]
[ 0.00150995]
[-0.00091736]
[-0.00381422]]
dW2 = [[ 0.00078841 0.01765429 -0.00084166 -0.01022527]]
db2 = [[-0.16655712]]
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-19-a06d396e2b09> in <module>
7 print ("db2 = "+ str(grads["db2"]))
8
----> 9 backward_propagation_test(backward_propagation)
~/work/release/W3A1/public_tests.py in backward_propagation_test(target)
187 assert output["db2"].shape == expected_output["db2"].shape, f"Wrong shape for db2."
188
--> 189 assert np.allclose(output["dW1"], expected_output["dW1"]), "Wrong values for dW1"
190 assert np.allclose(output["db1"], expected_output["db1"]), "Wrong values for db1"
191 assert np.allclose(output["dW2"], expected_output["dW2"]), "Wrong values for dW2"
AssertionError: Wrong values for dW1
I added some extra print statements in my code and here’s what I see for that cell:
W1.shape (4, 2)
w2.shape (1, 4)
A1.shape (4, 3)
A2.shape (1, 3)
dW1 = [[ 0.00301023 -0.00747267]
[ 0.00257968 -0.00641288]
[-0.00156892 0.003893 ]
[-0.00652037 0.01618243]]
db1 = [[ 0.00176201]
[ 0.00150995]
[-0.00091736]
[-0.00381422]]
dW2 = [[ 0.00078841 0.01765429 -0.00084166 -0.01022527]]
db2 = [[-0.16655712]]
W1.shape (9, 3)
w2.shape (1, 9)
A1.shape (9, 7)
A2.shape (1, 7)
All tests passed!
So you’re right that your values for the visible test look correct. But then how could the other test fail? You can see from my print statements that the other test case involves differently shaped objects. Are you sure you don’t reference any global variables instead of the parameters being passed in? E.g. directly referencing t_X
and t_Y
in your code would have this kind of effect.
You can look at the test case by clicking “File -> Open
” and reading the file public_tests.py
. One thing to note is that by the time it hits that failing assertion, it has already checked the shapes of your dW1, dW2, db1 and db2 values. So that puts some big limits on where the mistake actually is. My guess is maybe you have hard-coded the m value somehow.
that weird I haven’t changed m
I printed the shape and I seems that I have the same
I I found it seems that the value in the cache
I Found the problem ! It seems that the value they give us in A1 (in cache) is not equal to the value Z1 (in cache) applied to the activation function
Ah, good point. So when you implement the derivative of tanh
, you have to use A1
and not tanh(Z1)
. That is a bit weird that their data is not really consistent, but that’s the easier way to write it in any case.
Glad to hear that you found the solution!
Update: it would be easy for them to fix this. Technically your code is correct, even though you are working slightly harder than you really needed to. But still you could legitimately consider this a bug in the test case. I’ll file it and see what they say …
1 Like