Take one gradient step

Keep a steady rhythm through each period. · 136 words

A gradient gives the local slope of a loss function. A training rule subtracts the learning rate times the gradient from a weight. Start with a weight of five, a gradient of two, and a learning rate of one half. The update subtracts one and leaves a weight of four.

To see why the sign matters, picture a bowl with the lowest loss at the bottom. A positive slope means that moving a small distance to the right increases the loss. Subtracting a positive amount moves the weight to the left. If the slope is negative, the same rule moves the weight to the right. A large step can cross the bottom and climb the other side. Check the loss again after the update, since the slope described the starting point rather than the entire journey.

Check your recall

What weight would a learning rate of one quarter produce?

Check your answer

Five minus one quarter times two equals four and one half.

Worked exercise

A model predicts w times x. Calculate the loss before and after the update.

x, y, w = 1, 3, 1
loss = (w * x - y) ** 2
gradient = 2 * (w * x - y) * x
w = w - 0.25 * gradient
Check your reasoning

The prediction starts at 1, so the squared error is 4. The gradient is -4 and the new weight is 2. The new squared error is 1.

Sources and credits

Original KeyTouch lesson. Background reading · Zhang et al. · Dive into Deep Learning.