27/32
Part 6 of 6 · What interviewers ask nextLearn and do

Clipping shrinks every gradient by the same factor

Clipping is the fix you apply after the fact, when a step explodes anyway.

grads = {"W": np.array([[3.0, 0.0], [0.0, 4.0]]), "b": np.array([12.0])}
max_norm = 6.5

norm = np.sqrt(sum((g ** 2).sum() for g in grads.values()))
clipped = clip(grads, max_norm)
print(norm)
print(clipped["W"].tolist(), clipped["b"].tolist())
Predict

The gradients' total length is 13, and max_norm is 6.5. What does clipping do to W's 3 and 4 and b's 12?

Pick one to see what it prints.
Pick an answer above to see the rest