Following the slope downhill β and the one parameter that decides whether it works.
π Where this lives: the learning rate is the single most consequential number in training a neural network, and it is the first thing anyone tunes. Set it too high and the loss becomes NaN in a few steps; too low and training takes days to reach what it should have reached in minutes. Every practitioner has a story about a model that "would not learn" and a learning rate that was wrong by a factor of ten. Search "learning rate schedule warmup tuning neural networks".
Gradient descent
TRAINING A NETWORK IS AN OPTIMISATION PROBLEM: find the weights
that minimise an ERROR (or LOSS, or COST) function.
THE STANDARD ERROR FUNCTION for regression is the SUM OF SQUARED
ERRORS:
E(w) = Β½ Ξ£β (tβ β yβ)Β²
summed over the training examples p. THE FACTOR Β½ IS THERE ONLY
SO THAT IT CANCELS WHEN DIFFERENTIATED β it has no other
purpose, and some texts omit it.
WHY SQUARED: it is differentiable everywhere (unlike absolute
error at zero), it penalises large errors disproportionately, and
for a linear model it gives a single global minimum.
THE ERROR SURFACE is E plotted against the weights. For n
weights it is a surface in n+1 dimensions, and TRAINING IS THE
SEARCH FOR ITS LOWEST POINT. For a linear unit with squared
error the surface is a PARABOLOID β convex, with one minimum β
which is why the delta rule of the next topic has such clean
guarantees. For a multilayer network it is NOT convex, with many
local minima, plateaux and saddle points.
GRADIENT DESCENT: move each weight in the direction that reduces
E most steeply, which is the negative gradient.
wα΅’ β wα΅’ β Ξ· Β· βE/βwα΅’
THE GRADIENT βE = (βE/βwβ, β¦, βE/βwβ) points in the direction
of STEEPEST INCREASE, so the minus sign is what makes it
descent. Ξ· is the LEARNING RATE, controlling the step size.
A WORKED SINGLE-VARIABLE EXAMPLE, which shows everything that
matters. Minimise f(w) = wΒ², whose derivative is fβ²(w) = 2w and
whose minimum is at w = 0. Start at w = 5.
Ξ· = 0.1: 5.000 β 4.000 β 3.200 β 2.560 β 2.048 β 1.638
steady progress, converging slowly
Ξ· = 0.5: 5.000 β 0.000 β 0.000 β β¦
REACHES THE MINIMUM IN ONE STEP. Here 0.5 is exactly
optimal, because w β 0.5(2w) = 0 for any w.
Ξ· = 0.9: 5.000 β β4.000 β 3.200 β β2.560 β 2.048 β β1.638
OSCILLATES ACROSS the minimum, but the magnitude shrinks,
so it still converges
Ξ· = 1.0: 5.000 β β5.000 β 5.000 β β5.000 β β¦
OSCILLATES FOREVER with no progress at all
Ξ· = 1.1: 5.000 β β6.000 β 7.200 β β8.640 β 10.368 β β12.442
DIVERGES β each step overshoots further than the last
FOUR DISTINCT REGIMES FROM ONE PARAMETER: too small is slow,
optimal is immediate, moderately large oscillates but
converges, and too large diverges. THE BOUNDARY BETWEEN
CONVERGENCE AND DIVERGENCE IS SHARP, and in this example it is
at Ξ· = 1.
IN PRACTICE THE OPTIMAL Ξ· IS UNKNOWN, because it depends on the
curvature of the error surface, which varies from problem to
problem and from region to region within one problem.
Choosing the learning rate
THE SYMPTOMS, and this diagnostic table is the practical content
of the topic:
OBSERVED BEHAVIOUR THE LIKELY CAUSE
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
the loss decreases very slowly Ξ· TOO SMALL
the loss decreases then
plateaus far above zero Ξ· too small, or a local
minimum
the loss jumps up and down but
trends down Ξ· slightly too large
the loss oscillates with no
improvement Ξ· at the stability boundary
the loss increases, or becomes
NaN / infinite Ξ· MUCH TOO LARGE β DIVERGENCE
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
TYPICAL VALUES: 0.001 to 0.1 for most networks, and the standard
practice is to try a geometric sequence β 0.1, 0.01, 0.001 β and
observe the loss curve for a few epochs rather than reasoning
about it.
THE FUNDAMENTAL TRADE-OFF: A LARGE Ξ· MAKES FAST PROGRESS FAR
FROM THE MINIMUM AND OVERSHOOTS NEAR IT. That observation leads
directly to varying Ξ· during training.
LEARNING RATE SCHEDULES:
STEP DECAY multiply Ξ· by a factor (say 0.1) every k
epochs
EXPONENTIAL DECAY Ξ·(t) = Ξ·β Β· e^(βkt)
1/t DECAY Ξ·(t) = Ξ·β / (1 + kt)
COSINE ANNEALING decay following a cosine curve to near
zero β widely used
WARMUP start SMALL and increase for the first few
hundred steps, then decay. Counter-intuitive
and genuinely necessary for large models,
because the early gradients are large and
unreliable while the weights are random.
THE ROBBINS-MONRO CONDITIONS give the theoretical requirement
for stochastic gradient descent to converge:
Ξ£ Ξ·(t) = β the steps must not shrink so fast that
the total distance travellable is finite
Ξ£ Ξ·(t)Β² < β but they must shrink fast enough that the
noise averages out
A schedule like Ξ·(t) = Ξ·β/t satisfies both, which is why 1/t
decay appears in the theory.
MOMENTUM β the most useful single improvement:
v β Ξ²Β·v + Ξ·Β·βE
w β w β v
with Ξ² typically 0.9. The update accumulates a VELOCITY, so
consistent gradient directions build speed while oscillating
directions cancel.
WHY IT HELPS: on a surface that is a long narrow valley β
steep across, shallow along β plain gradient descent
oscillates across the valley and creeps along it. Momentum
damps the oscillation and accelerates the useful direction.
With Ξ² = 0.9 the effective step in a consistent direction
approaches Ξ·/(1 β Ξ²) = 10Ξ·, so momentum gives a tenfold
speed-up along a consistent slope without a tenfold learning
rate.
ADAPTIVE METHODS β a per-weight learning rate:
ADAGRAD divides Ξ· by the accumulated squared gradient, so
frequently updated weights get smaller steps. The
accumulation only grows, so Ξ· eventually vanishes.
RMSPROP uses a decaying average instead of a sum, fixing
that.
ADAM combines RMSProp's scaling with momentum, and is
the standard default in practice.
THESE REDUCE THE SENSITIVITY TO Ξ· WITHOUT REMOVING IT β Adam
still has a learning rate, and it still matters.
Batch, stochastic and mini-batch descent
HOW MANY EXAMPLES CONTRIBUTE TO ONE WEIGHT UPDATE β three
answers, and the difference is practical rather than cosmetic.
BATCH (FULL-BATCH) GRADIENT DESCENT
Compute the gradient over the ENTIRE training set, then take
one step.
β the gradient is exact, so the path is smooth and the
descent direction is the true steepest one
β deterministic and reproducible
β ONE UPDATE PER PASS THROUGH THE DATA, so with a million
examples one update costs a million forward passes
β requires the whole data set in memory
β can settle into a local minimum, with no noise to escape it
STOCHASTIC GRADIENT DESCENT (SGD)
Update after EVERY SINGLE example.
β many updates per pass, so progress per unit of computation
is far higher
β THE NOISE IS USEFUL: a noisy step can escape a shallow
local minimum that batch descent would settle into
β works with streaming data
β the path is erratic and the loss curve noisy
β cannot exploit vectorised hardware β one example at a time
wastes a GPU
MINI-BATCH GRADIENT DESCENT β what is actually used
Update after a small batch, typically 32 to 256 examples.
β the gradient estimate is much less noisy than SGD's
β the batch is ONE MATRIX MULTIPLICATION, so it exploits
parallel hardware β the batching argument from the
mathematical-model topic
β retains enough noise to escape poor minima
β THE DEFAULT, and "SGD" in modern usage almost always means
mini-batch.
THE ARITHMETIC OF THE DIFFERENCE, on 10,000 examples with a
batch size of 100:
full batch: 1 update per epoch
mini-batch: 100 updates per epoch
SGD: 10,000 updates per epoch
The mini-batch run makes a hundred times as much progress per
epoch as full batch, at almost the same computational cost per
epoch β because the hundred small matrix products are only
slightly less efficient than one large one.
TERMINOLOGY, which exams test:
EPOCH one complete pass through the training set
BATCH SIZE the number of examples per update
ITERATION one weight update
so iterations per epoch = training set size / batch size
THE PROBLEMS OF THE ERROR SURFACE that gradient descent must
contend with, and each has a standard response:
LOCAL MINIMA a point lower than its neighbourhood but not
the global lowest. Response: noise from
mini-batching, momentum, several random
restarts.
PLATEAUX flat regions where the gradient is nearly
zero and progress stalls. Response:
momentum, adaptive methods.
SADDLE POINTS a minimum in some directions and a maximum
in others. IN HIGH DIMENSIONS THESE ARE FAR
MORE COMMON THAN LOCAL MINIMA β for a point
to be a local minimum, the surface must
curve upward in EVERY one of thousands of
directions, which is improbable. This is a
genuinely reassuring result: the classical
worry about local minima matters less in
large networks than it does in low
dimensions.
RAVINES long narrow valleys causing oscillation.
Response: momentum.
VANISHING / the multiplicative decay of the activation
EXPLODING functions topic. Response: ReLU, careful
GRADIENTS initialisation, gradient clipping, residual
connections.
THE SUMMARY WORTH KEEPING: GRADIENT DESCENT IS A LOCAL METHOD
THAT ONLY KNOWS THE SLOPE WHERE IT STANDS. Everything in this
topic β the learning rate, schedules, momentum, adaptive rates,
mini-batching β is an attempt to make a purely local rule behave
sensibly on a surface it cannot see.
The five learning rates on one parabola are worth memorising as a picture: too small creeps, optimal jumps straight in, moderately large oscillates inward, and past a sharp threshold it diverges outward forever. All four behaviours come from one number, which is why it is the first thing to tune and the first thing to suspect.
π Go further: the saddle-point result deserves following up because it overturned a long-standing worry. Classical intuition, formed in two or three dimensions, treats local minima as the main obstacle to gradient descent. In high dimensions they are rare: a critical point is a local minimum only if the surface curves upward in every direction, and with a million parameters that is vanishingly unlikely β so almost all critical points are saddles, which gradient descent escapes given momentum or noise. The practical consequence is that large networks train better than small ones partly because they are large. Search "saddle points not local minima high dimensional optimization".
π‘ Exam angle: give the error function E = Β½Ξ£(t β y)Β² and the update rule wα΅’ β wα΅’ β Ξ·Β·βE/βwα΅’, explaining why the gradient is negated. Be ready to trace gradient descent by hand on a simple function such as wΒ² for a stated Ξ·, and to describe the four regimes β too small, optimal, oscillating, diverging. Diagnose a learning rate from described loss behaviour. Distinguish batch, stochastic and mini-batch gradient descent with the advantages of each, and define epoch, batch size and iteration. Explain momentum and why it helps in a ravine, and name the adaptive methods (AdaGrad, RMSProp, Adam). List the error-surface problems: local minima, plateaux, saddle points, ravines.
Syllabus points
Learning rate
Gradient descent
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.