Skip to the content

fatehi.devx2Learning

Deep learning

Optimisers

The rules that turn gradients into weight changes: plain gradient descent, momentum, and Adam, which gives every weight its own step size.

From gradient to step

Training computes, for every weight, the gradient of the loss: which way and how steeply the loss rises. An optimiser decides how far to move each weight against it. Plain gradient descent takes the same fraction of every gradient, the learning rate η: w ← w − η g. Computed on a random batch rather than all the data, it is stochastic gradient descent.

Two problems follow. Gradients from one batch to the next are noisy and zig-zag; and weights differ widely in how large their gradients are, so one learning rate is too large for some and too small for others.

Momentum and Adam

Momentum moves along a running average of past gradients instead of the last one, which smooths the zig-zag. Adam (Kingma and Ba, 2015) keeps two running averages per weight: m of the gradient and v of its square, and divides one by the square root of the other.

m←β1m+(1−β1)g,v←β2v+(1−β2)g2,w←w−ηm^v^+ε

g is the weight’s gradient on this batch; β1 and β2, close to 1, set how long the averages remember; m̂ and v̂ are m and v corrected for starting at 0 (divided by 1 − βt after t steps); ε keeps the division safe.

Dividing by √v̂, the typical size of the weight’s own gradient, gives every weight a step of about η in size, whatever the scale of its gradients: Adam gives each weight its own learning rate.

The learning rate over time

The learning rate is rarely kept fixed. Early on the averages are poor and the weights random, so large steps can throw training off; a warm-up raises the rate from near 0 over the first steps. Later, smaller steps settle the weights; the rate is lowered, a decay.

The paper’s learning rate over the first 40,000 steps: a straight rise for 4,000 steps, then a slow fall as one over the square root of the step.

Test yourself

  1. What problem does dividing by √v̂ solve?

    Weights whose gradients are of very different sizes: dividing by each weight’s typical gradient size gives every weight a step of similar size, as if each had its own learning rate.

  2. Why warm up the learning rate at the start?

    At first the weights are random and Adam’s averages rest on few gradients, so large steps can throw training off; a small rate that grows avoids that.

  3. At which step does the paper’s learning rate peak, and at what value?

    At step 4,000, at 512−0.5 · 4000−0.5 ≈ 0.0007.

Where it leads

Kept in this browser only, never sent.

Paths through it