Skip to content
GenAI Learn/Neural Networks From First Principles
Browsing as a guest. Sign in to save your progress and earn XP as you complete chapters.

Training Stability: Initialization, Normalization & Gradient Problems

8 min read

You'll learn to

  • -Understand why random weight initialization matters, and what goes wrong with a bad choice
  • -Understand vanishing and exploding gradients as a direct consequence of repeated multiplication across layers
  • -Understand batch normalization as a second, complementary fix for the same underlying problem

Backpropagation explained how a gradient gets computed. This chapter is about what can go wrong with that process once a network gets deep, and the two standard fixes every practitioner reaches for. This is genuinely practical territory. Get initialization or normalization wrong and a network that should train perfectly well simply does not.

Why Not Just Start With All Zeros?

It seems natural to initialize every weight to zero, but that choice quietly breaks training before it even starts. If every weight in a layer starts identical, every neuron in that layer computes the exact same output and receives the exact same gradient during backpropagation. They stay identical forever, no matter how long you train. This is called the symmetry problem, and it is why weights always start as small random numbers instead of a fixed value.

Vanishing Gradients: Shrinking on the Way Back

Recall from the backpropagation chapter that a hidden layer's error signal is the output error multiplied by a weight and an activation derivative, layer after layer. Stack ten or twenty layers, and that gradient gets multiplied by roughly the same small factor ten or twenty times in a row. A factor just below 1, repeated enough times, shrinks toward zero fast. By the time the signal reaches the earliest layers, there may be almost nothing left to learn from. Those layers barely update at all, even while later layers train just fine.

Exploding Gradients: The Opposite Failure

The same multiplication can run the other way. A factor just above 1, repeated across many layers, grows exponentially instead of shrinking. The gradient can blow up to enormous values, causing wild, unstable weight updates that can wreck a training run in a single bad step.

Try all three below and watch the same ten-layer network behave in completely different ways depending on nothing but how it was set up.

Gradient Magnitude, Layer by Layer

Backpropagation multiplies the gradient once per layer on its way back to the input. A small repeated shrink (or growth) compounds fast.

10987654321

layer (10 = output side, 1 = input side) · bar height is log-scaled

Weights scaled to the layer size. The gradient survives the trip.

Gradient at layer 1 (input side): 8.34e-1 (started at 1.00 at the output)

Weight Initialization: Scaling the Starting Point on Purpose

The fix is to choose the initial random weights carefully, scaled to the size of each layer, so the signal neither shrinks nor grows much as it passes through. Two standard schemes handle this, and they are genuinely named after the papers that introduced them.

Xavier (Glorot) Initialization
w ~ Uniform(−√(6/(nᵢₙ+nₒᵤₜ)), √(6/(nᵢₙ+nₒᵤₜ)))
nᵢₙ and nₒᵤₜ are the number of neurons feeding into and out of this layer. The wider the layer, the smaller each individual weight starts, keeping the overall signal magnitude stable. Common default for sigmoid and tanh activations.
He Initialization
w ~ Normal(0, √(2/nᵢₙ))
A close cousin of Xavier, tuned for the ReLU activation function specifically, since ReLU zeroes out roughly half its inputs and needs a slightly larger starting variance to compensate. The standard default for ReLU networks today.

Batch Normalization: Fixing It Mid-Network Too

Good initialization only guarantees a stable start. As training proceeds and weights change, the distribution of values flowing into each layer can still drift. Batch normalization addresses this directly, at every layer, throughout training, not just at the start. For each mini-batch, it rescales that layer's inputs to have a mean of 0 and a standard deviation of 1, then lets the network learn a small correction on top if needed.

Batch Normalization
x̂ = (x − μ_batch) / √(σ²_batch + ε) , y = γx̂ + β
μ_batch and σ²_batch are the mean and variance computed across the current mini-batch. γ and β are learned parameters that let the network undo the normalization if that turns out to work better for a particular layer. ε is a tiny constant to avoid dividing by zero.
Two Fixes, Same Underlying Goal
Gets the signal off to a stable start, once, before training begins
Weight initialization
Keeps the signal stable throughout training, at every layer, on every batch
Batch normalization
Both let you train deeper networks and use higher learning rates safely
Shared benefit

In practice, you specify the initialization scheme and add batch norm layers with one line each. PyTorch's nn.init.kaiming_normal_ implements He initialization by name (Kaiming is He's given name), and nn.BatchNorm1d or nn.BatchNorm2d adds a batch normalization layer wherever you place it. Both are one-line calls built on exactly the formulas above.

Interview Signal is part of Pro

See a real weak answer next to a real strong one for this exact topic.

Quiz is part of Pro

Test what you just read with a short quiz, and bank the XP.

ScaleDojo Logo
Initializing ScaleDojo