Weight Initialisation (Xavier and He)
Chooses the starting weights so signals keep a healthy size through every layer.
The idea
If the initial weights are too small the signal shrinks layer after layer to nothing; too large and it explodes. Xavier (Glorot) sets the variance to 2/(fan_in + fan_out), suiting tanh and sigmoid. He initialisation uses 2/fan_in, which compensates for ReLU zeroing half of the activations.
Xavier: Var(w) = 2/(nᵢₙ + nₒᵤₜ); He: Var(w) = 2/nᵢₙ
Watch it run
This is a real computation, not a drawing. Pause, step, change the settings, or try new random data.
- vanishing
- saturating
- stable
Three ways to pick starting weights for an 8-layer network. Bars will show how spread-out the signal is at each layer.
- layers done:
- 0
- xavier spread:
- –
Bar height is the spread of activations at that layer in a real random network.
Step by step
- 1Count the inputs (fan-in) and outputs (fan-out) of the layer.
- 2Pick the variance: Xavier 2/(fan_in + fan_out) or He 2/fan_in.
- 3Sample the weights from a normal or uniform distribution with that variance.
- 4Set biases to zero.
Where it is used
Every deep network.
Watch out for
Wrong pairing (Xavier with deep ReLU stacks) slowly shrinks the activations.