Week 1, Programming assignment 2, graded ex. 3 issue

Sorry, it’s been a while since I read the template code for clip. Here it is:


def clip(gradients, maxValue):
    Clips the gradients' values between minimum and maximum.
    gradients -- a dictionary containing the gradients "dWaa", "dWax", "dWya", "db", "dby"
    maxValue -- everything above this number is set to this number, and everything less than -maxValue is set to -maxValue
    gradients -- a dictionary with the clipped gradients.
    gradients = copy.deepcopy(gradients)
    dWaa, dWax, dWya, db, dby = gradients['dWaa'], gradients['dWax'], gradients['dWya'], gradients['db'], gradients['dby']
    ### START CODE HERE ###
    # Clip to mitigate exploding gradients, loop over [dWax, dWaa, dWya, db, dby]. (≈2 lines)
    for gradient in None:
        np.clip(None, None, None, out = None)
    ### END CODE HERE ###
    gradients = {"dWaa": dWaa, "dWax": dWax, "dWya": dWya, "db": db, "dby": dby}
    return gradients

So even if you do your version where you use gradients.keys() as the range in the loop, instead of the explicit list of the gradients you care about as they suggested in the comment, you still would have been ok, if you had left that last assignment statement that creates a new version of gradients in place. But you must also have deleted that.

I don’t disagree that this is all a bit of a distraction and they shouldn’t have written the grader code to care about that, since it doesn’t really matter. I think I filed a bug about this a while back and it either got rejected or shelved into the “maybe someday” category. But to be fair to the course staff, you did go out of your way to step on this landmine and it’s only happened a few times historically, so maybe fixing it is not worth it. :nerd_face: