Lensa ML
Lensa ML

How Weight Initialization Works

Step 1 of 5

Constant Initialization

Why zeros and ones both fail as starting weights

Tap a node to see its calculationInputHidden 1Hidden 2Output0.80-0.500.300.290.290.290.290.520.520.520.520.780.78ALL IDENTICALALL IDENTICALALL IDENTICAL

Weight

0.50

H1 Value

0.291

H2 Value

0.525

Unique Out

1

All weights identical → every neuron in a layer is a clone. Gradients are identical too — the network can never learn different features. Random values are needed to break this symmetry.

Step 1 of 5: Constant Initialization

Why zeros and ones both fail as starting weights

Tap a node to see its calculationInputHidden 1Hidden 2Output0.80-0.500.300.290.290.290.290.520.520.520.520.780.78ALL IDENTICALALL IDENTICALALL IDENTICAL

Weight

0.50

H1 Value

0.291

H2 Value

0.525

Unique Out

1

All weights identical → every neuron in a layer is a clone. Gradients are identical too — the network can never learn different features. Random values are needed to break this symmetry.

Step 2 of 5: Random Initialization

Random values beat constants, but the scale matters

Tap a node to see its calculation0.80-0.500.300.02-0.480.210.00-0.130.06-0.05-0.310.150.144/4 unique4/4 unique2/2 uniqueInputHidden 1Hidden 2OutputActivation distributions (60 inputs through the same network)InputHidden 1Hidden 2OutputGradient magnitude (backward pass ←)0.3220.4920.6521.000

Bound

0.50

H1 Std

0.385

H2 Std

0.238

Grad @ Input

0.322

Symmetry broken! Each neuron computes a different value (see the network above). The histograms show healthy spread across layers. But does this scale work for all layer widths? We need a principled rule.

Step 3 of 5: The 1/√n Rule

A simple recipe that adapts initialization to layer width

323232323232(1/√n = 0.177, 0.177, 0.177, 0.177, 0.177)
Tap a layer to inspect a neuron’s calculation×w×w×w×w×w32Input32L132L232L332L432L5Naive: W ~ U[-0.5, 0.5] (fixed scale, ignores layer width)L1 (32)std=0.756L2 (32)std=0.699L3 (32)std=0.650L4 (32)std=0.645L5 (32)std=0.643Recipe: W ~ U[-1/√nᵢₙ, 1/√nᵢₙ] (adapts per layer)L1 (32)std=0.476L2 (32)std=0.263L3 (32)std=0.144L4 (32)std=0.079L5 (32)std=0.047

Shape

Uniform

Widths

32→32→32→32→32

Naive L5 Std

0.643

Recipe L5 Std

0.047

The recipe y = 1/√n scales initialization to the layer width. Uniform sampling keeps activations stable (L5 std = 0.047) while naive uniform drifts (L5 std = 0.643).

Step 4 of 5: Xavier, He & Activations

Named methods tuned for specific activation functions

161616161616
Tap a layer to inspect a neuron’s calculation×w×w×w×w×w16Input16L116L216L316L416L5Xavier: W ~ N(0, 2/(nᵢₙ+nₒᵤₜ))L1std=0.638L2std=0.475L3std=0.399L4std=0.361L5std=0.329He: W ~ N(0, 2/nᵢₙ)L1std=0.726L2std=0.618L3std=0.582L4std=0.589L5std=0.576

Shape

Uniform

Widths

16→16→16→16→16

Xavier Last Std

0.329

He Last Std

0.576

Both Xavier and He are variations of the 1/√n rule. Each comes in two flavors: Normal (sample from a Gaussian) and Uniform (sample from a flat distribution with the same variance). Currently using Normal: Xavier ~ N(0, √(2/(n_in+n_out))), He ~ N(0, √(2/n_in)). Xavier (Glorot, 2010) averages fan-in and fan-out for symmetric activations (tanh, sigmoid). He (Kaiming, 2015) uses only fan-in with a ×2 factor for ReLU. With tanh: Xavier last std = 0.329, He last std = 0.576.

Step 5 of 5: Training Comparison

Watch how different initializations affect actual learning

Architecture: 1 → 16 → 16 → 1 (ReLU, MSE loss, mini-batch SGD)1InputReLU16Hidden 1ReLU16Hidden 2linear1OutputTask: learn y = sin(x) from 16 data points
Epoch 0
0.520.21Training EpochsLoss0.290.370.44ZerosOnesRandom1/√n
Weight distribution (1/√n, epoch ~0)

Epoch

0

1/√n Loss

0.378

Best

Ones

Weight Std

0.191

1/√n recipe → fastest convergence (loss = 0.378). Weight distribution stays centered near zero with controlled spread. This is what the W&B article demonstrates: principled initialization beats everything.