[Week 4] Building your NN step by step Exercise 9


I have a question for the week 4 hw1, for the L-layer NN backward propagation.

I have the error message like this:
in L_model_backward(AL, Y, caches)
40 current_cache = caches[L-1]
—> 41 dA_prev_temp, dW_temp, db_temp = linear_activation_backward(grads[“dA” + str(L)],current_cache, “sigmoid”)
42 grads[“dA” + str(L-1)] = dA_prev_temp
43 grads[“dW” + str(L)] = dW_temp
KeyError: ‘dA2’

I believe this should be the mistake in indexing, since in the test data, we shall have A0 and A1, but no A2. can anybody tell me where I did it wrong? thanks!

Hi @nunally and welcome to the DL specialization. I agree that you have a mistake in the indexing. The ‘KeyError’ is telling you that dA2 is not an item in the dictionary grads. The for statement provided to you in the L_model_backward(...) function is

for l in reversed(range(L-1)):

In this statement l is the index, not L. The latter just helps define the terminal element of the sequence (or, the ‘range’ of the sequence.

Also note that you are not allowed to post your code solutions in the Discourse forum. Please use only the output and error messages (i.e. ‘exceptions’) in all future posts. Thanks!

Getting the same error. Unable to figure out .