Part I, Optimisation, generalisation, adaptation
Downhill
Training a network is walking down a surface you cannot see, one gradient at a time. How big a step you take matters more than almost anything else.
Assumes partial derivatives, eigenvalues of a symmetric matrix.
Every network you will train in this course is fitted the same way. You have parameters , a loss that measures how wrong the network is on the training data, and the gradient , which points uphill. You step the other way:
The step size is called the learning rate.“Rate” is a misnomer we are stuck with. It is a length scale, not a speed: the distance moved is times the length of the gradient. Real networks have millions of parameters, but almost everything that goes right or wrong with gradient descent can be seen with two. The figure below shows two parameters, their loss as contour lines, and the path the parameters take.
The step that is too large
Start on the bowl at a step size of 0.60 and drag it upward. At first the path just gets there sooner. Past 1 it starts to zig-zag across the steep direction of the bowl, and past 2 it stops converging and flies off.
That threshold is no accident. Near a minimum every smooth loss looks like a quadratic, , where is the Hessian. Write in the eigenbasis of , with eigenvalues . Each coordinate then evolves on its own:
A coordinate shrinks only if , that is, if . The largest curvature sets the limit for the whole problem:
In the bowl here, , so the edge is at .The readout beside the figure reports for the bowl. Watch it cross 2.
The direction that is too flat
The other coordinate shrinks by each step. If the step is held under the limit set by the steep direction, the flat direction crawls. The ratio , the condition number, measures how bad the mismatch is. Push the bowl’s elongation κ up and watch the number of steps needed grow roughly in proportion.
Badly conditioned losses are the normal case in deep learning, not the exception. Much of what follows in this course, including normalisation layers, careful initialisation and adaptive optimisers, is about making smaller, or acting as if it were.
Momentum
Heavy-ball momentum keeps a running velocity:
Along the steep direction, successive gradients alternate in sign and largely cancel. Along the flat direction they agree and accumulate. Set momentum to 0.9 on the elongated bowl and compare the step counts. Then try the valley surface, Rosenbrock’s banana, where the floor curves and momentum has to turn a corner.
Adam goes further and rescales each coordinate by a running estimate of its gradient’s size.Kingma and Ba, 2015. In effect it is a cheap, diagonal guess at the curvature. On the bowl it is nearly indifferent to κ. On the saddle surface, start near the ridge and compare how long plain descent and Adam take to escape it.
For the quadratic with fixed step , find the that makes the slowest coordinate shrink as fast as possible, and the resulting rate.
Solution
The worst factor is . It is smallest when the two are equal, at . The rate is then per step, which is close to 1 when is large.
On the bowl with κ = 50 and a step size of 0.6, use the figure to find the momentum that reaches within 0.001 of the minimum in the fewest steps. Explain what goes wrong as β approaches 1.