Deep learning and neural networksLoading progress…

Dropout and schedules

Diagnose an unstable training run using losses, gradient magnitudes, initialization, normalization and regularization.

Dropout: train a different sub-network each step

Dropout randomly sets a fraction p of the activations to zero during training, so the network cannot rely on any one unit. The survivors are scaled up by 1 / (1 − p) ("inverted" dropout) so the average activation is unchanged. At evaluation dropout is switched off entirely: no zeroing, no scaling, because the average already matches.

drop probability p0.5
unit12345678910mean
activation42615372464.00
kept?noyesyesyesnoyesyesyesnono
output (train)0.004.0012.002.000.006.0014.004.000.000.004.20
output (eval)42615372464.00

Kept values are divided by (1 − p) = 0.5, i.e. multiplied by 2.00. One mask is noisy, but over many masks the average output equals the evaluation output, which is why evaluation can simply switch dropout off.

One mask over ten activations. Draw new masks and compare the mean of the training output with the evaluation output.

Predict first. With keep probability 0.5, what is a kept activation multiplied by in inverted dropout?

dropout ptrain loss (dropout off)validation losstrain accuracy
00.0000.037100%
0.20.0070.243100%
0.50.0170.06199%
0.80.3830.45282%
A real regularisation effect on a wider network: more dropout means less fitting of the training set.

Learning-rate schedules

The best learning rate changes during training. A warm-up ramps it up from near zero in the first steps, when the gradients and (for Adam) the running statistics are least reliable. Then a decay lowers it so the weights settle into a minimum instead of bouncing around it. Common shapes are a step decay (divide by a fixed factor every N steps) and a cosine curve.

warm-up steps0
0.100.0step (0 to 199)learning rate
learning rate (constant)
peak 0.1, 200 steps: step 10 → 0.1000 step 100 → 0.1000 step 120 → 0.10000 step 199 → 0.100000
Shape the schedule and read the learning rate at a few steps.
Chapter context

A differentiable model can still be difficult to train. Learning rate, parameter scale, data scale and optimizer state interact. Inspect the run before changing many settings at once.

Chapter reference: math, worked example & code

This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.

Math and notation

Norm clipping uses

g′=gmin⁡(1,c∥g∥2).g'=g\min\left(1,\frac{c}{\|g\|_2}\right).

For inverted dropout with keep probability q, h~=mh/q\tilde h=m h/q where m∼Bernoulli⁡(q)m\sim\operatorname{Bernoulli}(q), so E[h~]=hE[\tilde h]=h. This expectation is over masks, not a claim that each individual masked output is unchanged.

Worked example

The gradient [3,4] has norm 5. Clipping its norm to 2 yields [1.2,1.6], preserving direction. For a scalar activation 4 and keep probability 0.5, dropout gives either 8 or 0 with equal probability, averaging to 4.

Reference code

The following example uses the Python standard library and does not call a remote service.

from math import sqrt, isclose
g = [3,4]
scale = min(1, 2/sqrt(sum(v*v for v in g)))
clipped = [v*scale for v in g]
assert all(isclose(a,b) for a,b in zip(clipped,[1.2,1.6]))
assert isclose(sqrt(sum(v*v for v in clipped)),2)
assert .5*8+.5*0 == 4

Python examples are provided for study and local execution; this page does not execute Python.

Common mistakes

Clipping is not the same as normalizing every gradient to the limit. Lower training loss can accompany worse validation. A numerical fix should not conceal invalid data or labels.