Training a model means making its loss small. Gradient descent does it by repeatedly stepping downhill, and the step size and choice of optimizer shape the path it takes.
Imagine standing blindfolded on hilly terrain, trying to reach the lowest point. You can't see the landscape, but you can feel the slope under your feet: which way is downhill and how steep it is. Gradient descent repeats one move: take a small step downhill, feel the slope again, and step again.
In machine learning, the "terrain" is a loss surface: a function that measures how wrong your model is. The horizontal axes are the model's parameters. The vertical axis (or color, in a map view) is the loss. Training a model means finding parameters that make the loss as small as possible.
With two parameters, a loss surface reads like a topographic map: contour lines join points of equal loss, valleys are low loss and ridges are high. Where a walker starts matters. Some reach the global minimum; others settle into a local minimum, with a deeper valley past the ridge.
Each walker stops where the ground is flat. The update rule uses only the local slope, so it cannot distinguish a local minimum from the global one.
The gradient tells you which direction to step, but not how far. That distance is the learning rate. Too small, and you need hundreds of steps to reach the minimum. Too large, and you overshoot the valley, bouncing across it or flying off entirely. In between, you reach the bottom in a handful of steps.
The best learning rate depends on the shape of the loss surface, which changes as you move through it. This curve bends twice as sharply at the bottom as far up its walls, which is why the large rate can bounce forever: its steps are too long to settle near the bottom but not long enough to throw the dot out. Modern optimizers adapt the step size during training for this reason.
Plain gradient descent struggles in long, narrow valleys. The gradient points mostly across the steep walls instead of along the floor, and a learning rate large enough to make progress along the floor overshoots across it. The path zigzags from wall to wall and makes slow progress toward the minimum.
Momentum adds a velocity term that keeps a fraction β of the previous step. Across the valley the gradient flips sign from step to step, so those pushes partly cancel in the velocity; along the floor they point the same way and add up. Too much momentum brings the oscillation back: at the learning rate used below, β = 0.9 is still swinging across the valley after 20 steps. Adam keeps running averages of each parameter's gradient (the first moment, its mean) and of its squared gradient (the second raw moment, the mean squared gradient), and divides each parameter's step by the square root of the second, so every parameter moves at a pace set by the learning rate rather than by how steep its own direction is.
Adam is not always the best choice, as this valley shows. On some problems, well-tuned stochastic gradient descent with momentum (the mini-batch version described next) also generalizes better than adaptive methods, and the choice is often made by trying several.
Everything above assumes you compute the gradient using your entire dataset. Real datasets are large, so instead you estimate the gradient from a small random subset, a mini-batch. The estimate is noisy: a single sample points roughly the right way but wanders, and a larger batch is cleaner but costs more. Using mini-batch estimates is what makes it stochastic gradient descent (SGD). Figure 4 fits a straight line, ŷ = w x + b, to 64 simulated data points, so the two parameters are the slope w and the intercept b.
The noise can also help, by bouncing the optimizer out of a shallow local minimum into a better one. Keskar et al. (2017) found that small-batch training tends to land in flatter minima that generalized better than the sharp minima large batches found, and attributed it to the gradient noise. Whether flatness itself explains generalization is debated: Dinh et al. (2017) showed that a network can be reparametrized to make a minimum arbitrarily sharp without changing what it computes.
Every step above needs the gradient of the loss with respect to each parameter. For the line in Figure 4 that is two partial derivatives. A neural network has many layers of weights, and Part 2 shows how backpropagation computes the gradient for all of them.