Contents
03The learning rate
3.1One dimension: a bowl
Take the simplest loss, a bowl J(\theta)=\frac a2\theta^2 with curvature a>0 and minimum at 0. Its gradient is a\theta, so the update (2) is
Everything depends on the factor 1-\eta a (Figure 1, with a=1 and \theta_0=-2.5):
- 0<\eta a<1: we approach from one side; at \eta a=0.1 each step removes only 10\% of the distance: we crawl.
- \eta a=1: the factor is 0 and we land on the minimum in one step (Newton’s step, \eta=1/a).
- 1<\eta a<2: the factor is negative, so we overshoot and bounce, but still converge (-0.5 at \eta a=1.5).
- \eta a>2: every step overshoots more than the last; at \eta a=2.1 the distance grows 10\% and the loss 21\% per step.
So gradient descent converges on the bowl if and only if 0<\eta<2/a.
3.2Many dimensions: the eigenvalues decide
Near a minimum, any smooth loss looks like a quadratic, J(\theta)\approx J^*+\frac12(\theta-\theta^*)^{\top}H(\theta-\theta^*), with gradient H(\theta-\theta^*). The error e_t=\theta_t-\theta^* then evolves as
Write e_t in the eigenvectors of H. Each coordinate is an independent bowl with curvature \lambda_i and is multiplied by 1-\eta\lambda_i at every step. All coordinates converge if and only if |1-\eta\lambda_i|<1 for all i, that is
The steepest direction sets the speed limit. The slowest direction sets the speed: the error shrinks by \max_i|1-\eta\lambda_i| per step. The best constant learning rate balances the flattest and steepest directions, \eta=2/(\lambda_{\min}+\lambda_{\max}), and gives the rate
With \kappa=100 the error shrinks by only 99/101=0.980 per step, so it takes about 115 steps to gain one decimal digit. A large condition number means a long, narrow valley: the steep walls force a small learning rate, and the flat floor is then crossed at a crawl (Goodfellow et al., 2016, §4.3, §8.2).
Worked example 1 (The regression is a narrow valley). For least squares the Hessian is H=\frac1n\sum_i\;(x_i,1)^{\top}(x_i,1), a constant matrix. In the running example its eigenvalues are 0.114 and 11.229, so \kappa=98.9 and the learning rate must stay below 2/11.229=0.178; we use 0.05. The valley is narrow because the inputs are not centered: x averages 3.011, so changing the slope w also shifts every prediction, and w and b fight each other. Replacing x by x-\bar x makes the Hessian eigenvalues 1.0 and 1.275, \kappa=1.27, and gradient descent would reach the bottom in a handful of steps. This is why inputs are normalized to zero mean and unit variance before training (LeCun et al., 1998, §4.3).
Pause and think. Your training loss suddenly becomes NaN after a few hundred steps. What is the first thing to try?
Show the answer
Lower the learning rate: an exploding loss is the signature of \eta above 2/\lambda_{\max} in some direction (or of a curvature that grew during training). Learning-rate warmup and gradient clipping protect against the same failure.