The update
Every parameter moves a small step in the direction that reduces the loss fastest, which is the direction opposite the gradient.
- : every parameter in the model, as one vector, at step .
- : the gradient: how much the loss changes per unit change in each parameter.
- : the learning rate, the one number you choose.
The minus sign is the whole idea. The gradient points uphill, so you go the other way.
Why the gradient is the steepest direction
For a small step , the change in loss is approximately the dot product of the gradient with that step.
A dot product is most negative when the two vectors point in exactly opposite directions.
So among all steps of a given length, the one that reduces the loss most is the one straight down the gradient.
This is a local statement and only a local one: it says nothing about where the minimum is, only which way is downhill right here.
What the learning rate does
The gradient decides the direction and the relative size of each parameter's move; scales all of them together.
Too small and training crawls, taking thousands of steps to cross a region a handful would have covered.
Too large and the step overshoots the valley floor and lands higher up the opposite side, so the loss rises instead of falling.
The threshold between the two sits at roughly , where is the largest curvature of the loss surface.
So the safe learning rate is a property of the problem, not of your taste.
One step, in order
- Run a forward pass and compute the loss.
- Run backward and get the gradient for every parameter.
- Multiply the whole gradient by the learning rate.
- Subtract that from the parameters.
- Throw the gradients away and start again.
The version nobody actually runs
Written this way the gradient is an average over the entire training set, so one step needs a pass over all of it.
That is called batch gradient descent, and on a dataset of any size it is unusable. A single step could take an hour.
What is actually run estimates that average from a small random sample instead, which is stochastic gradient descent.