Week 02 Prog Assignment exercise 6

Having trouble debugging;

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-22-fb9df09bb7f1> in <module>
      7 epsilon = 1e-2
      8 
----> 9 parameters, v, s, vc, sc  = update_parameters_with_adam(parametersi, grads, vi, si, t, learning_rate, beta1, beta2, epsilon)
     10 print(f"W1 = \n{parameters['W1']}")
     11 print(f"W2 = \n{parameters['W2']}")

<ipython-input-21-8e36476ae0c2> in update_parameters_with_adam(parameters, grads, v, s, t, learning_rate, beta1, beta2, epsilon)
     82         # YOUR CODE STARTS HERE
     83 
---> 84         parameters['W' + str(l)] -= learning_rate * (v_corrected['dW' + str(l)]/(np.sqrt(s_corrected['dW' + str(l)]) + epsilon))
     85         parameters['b' + str(l)] -= learning_rate * (v_corrected['db' + str(l)]/(np.sqrt(s_corrected['db' + str(l)]) + epsilon))
     86 

KeyError: 'dW1'

Hi @wepu , did you run all the previous cells? A key error means that dWi is not recognized, so it might be an error in an earlier cells or not running a previous cell. Otherwise, if you send me your code directly (not on the platform as this is against policy) I can have a look at it.

Note that the dictionaries v_corrected and s_corrected are created and updated by the earlier logic in this same update_parameters_with_adam routine. Maybe you have a bug in how you do that, e.g. some misspelling of the dictionary key names.

If you have a dictionary called myDictionary, you can list the keys by doing this:

print(myDictionary.keys())

If you can’t see the bug based on my suggestion above, it would be worth adding some print statements in the loop before the statement that is “throwing” to see if everything is the way you expect.