Skip to content
StackDecode
AI & ML Atlas
Neural NetworkstechniqueInteractive simulation

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.

too small (σ=0.05)L1L2L3L4L5L6L7L8too large (σ=1.0)L1L2L3L4L5L6L7L8Xavier (σ=1/√n)L1L2L3L4L5L6L7L8
  • 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:
–
1/9

Bar height is the spread of activations at that layer in a real random network.

Step by step

  1. 1Count the inputs (fan-in) and outputs (fan-out) of the layer.
  2. 2Pick the variance: Xavier 2/(fan_in + fan_out) or He 2/fan_in.
  3. 3Sample the weights from a normal or uniform distribution with that variance.
  4. 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.

Related