In the assignment, the function used to test the implemented backward_propagation function in Exercise 6 is backward_propagation_test in the public_tests.py file. I encountered the error AssertionError: Wrong values for dW1, even after several correct indications like my implemented code matching the formulas in the slide, my output being the same as expected output and all the code cells after executing perfectly, matching their expected output too. I downloaded the workspace and inspected that file, and I want to address these two things I noticed:
The main problem was the predefined expected_output dictionary. I inspected the values by slightly modifying that function in my local environment and found out that the values in the arrays dW1 and db1 were way off from those present in grads returned by the learner’s implementated function, enough that the assertion using np.allclose would fail (although dW2 and db2 were fine). It would be really appreciated if the values were checked once, it is probably some minor calculation issue as dW2 and db2 are fine.
This is more on the conceptual side. I noticed in the same backward_propagation_test function, a test value of parameters W and b of both layers were randomly generated; clearly understandable as they would be used to verify further calculations. But the cache values (A and Z for both layers) were also being generated randomly. Shouldn’t these values be calculated from the already initialized W’s and b’s, and then passed into target /backward_propagation ? My reasoning being the gradient has to be taken out at a particular point defined by the current state of values in parameters and the input X, which also determine the values of cache at that instant. So this random generation of the cache values caught my eye.
I have attached some relevant screenshots, particularly for the first issue. Thank you for having a look.
Thanks for your careful analysis of what is happening here. Yes, you’re right that the test case here is a bit sketchy. This issue has been known for a long time: here’s a thread about it from November 2021. I filed a bug about this in March 2023, but the course staff has decided that it is low priority enough that they have not done anything about it yet. Note that they literally wrote out the correct code for g^{[1]'}(Z^{[1]}) for you in the instructions. See the “Tips” section right before the function:
then it passes the first visible test in the notebook, but it fails the one you pointed out that is imported because in that test case it is not true that:
One other interesting note in following up on this:
I checked in the new version of DLS that is now on the DeepLearning.AI Learning Platform (as opposed to Coursera) and there they have fixed the grader so that it will accept the mathematically correct version of the implementation of dZ1 that uses (1 - np.tanh(Z1)**2) as the derivative term. Interestingly they didn’t change the backward_propagation_test logic to fix the incorrect test case there, so you still fail the test in the notebook with the alternate (but mathematically correct) implementation even though you pass the grader. My guess is that they wanted to keep the public_tests.py file the same between the two versions of the course (the Coursera version and the DLAI LP version).
Ah! Thank you for looking in this Paul. I should have searched a little more properly on W3A1, somehow I missed that thread from 2021. Anyways, I did understand it now and got what you are saying in the second reply. Really appreciate it.