What a loss surface shows
A loss function is a number that measures how badly a model fits its data. A model with two parameters has a loss value for every pair of parameter values. Plotting that value as height above the parameter plane gives a loss surface.
Low points on the surface are good parameter choices. The goal of training is to find a low point, ideally the lowest one. With millions of parameters the surface cannot be drawn, but the same idea applies.
How the update rule works
The gradient is the vector of partial derivatives of the loss with respect to each parameter. It points in the direction of steepest increase. Gradient descent therefore moves the opposite way.
The update rule is: new parameter = old parameter minus learning rate times gradient. The learning rate is a small positive number that sets the step size. The process repeats until the loss stops falling or a step limit is reached.
Worked example with one parameter
Take the loss L(w) = (w - 3)^2, whose minimum is at w = 3. The gradient is 2(w - 3). Start at w = 0 with a learning rate of 0.25.
Step 1: gradient = 2(0 - 3) = -6, so w = 0 - 0.25 x (-6) = 1.5. Step 2: gradient = 2(1.5 - 3) = -3, so w = 1.5 - 0.25 x (-3) = 2.25. Step 3: gradient = 2(2.25 - 3) = -1.5, so w = 2.25 + 0.375 = 2.625.
Each step halves the distance to 3. The loss falls from 9 to 2.25 to 0.5625 to 0.140625. With a learning rate of 1.1 the same problem would overshoot and diverge, since each step multiplies the distance by -1.2.
Common misconceptions
Gradient descent does not guarantee the global minimum. On a surface with several valleys, it can settle in a local minimum or stall on a flat region. For convex losses, such as the squared error of linear regression, any local minimum is also global.
A smaller learning rate is not simply better. Very small steps make training slow, while large ones can bounce across a valley or diverge. Also, the gradient points uphill locally, not toward the minimum from far away.
Where it shows up
Gradient descent trains linear and logistic regression, and it is the basis of training neural networks, where backpropagation computes the gradient. In practice, stochastic gradient descent estimates the gradient from a small batch of data rather than the full set. Variants such as momentum and Adam adjust the step using past gradients.
Key terms
- Loss function
- A number that measures how far a model's predictions are from the target values.
- Loss surface
- The graph of the loss plotted against the model's parameters.
- Gradient
- The vector of partial derivatives of the loss, pointing toward steepest increase.
- Learning rate
- The positive factor that scales each parameter update.
- Local minimum
- A point where the loss is lower than at nearby points but not necessarily the lowest overall.
- Stochastic gradient descent
- Gradient descent that estimates the gradient from a random subset of the data at each step.
