Gradient LabStart the lesson

Lessons › Chapter 8: Neural networks

Batch normalization

batch normalization measures the mean and spread of each layer’s outputs for the current batch, then shifts and squeezes them to mean 0 and spread 1, just like standardizing features.

Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.

Start the interactive lesson

Step by step

Story

Shaky training

Every training run behaves differently and progress is unsteady.

Problem

Each layer sees shifting numbers

As earlier layers learn, the numbers they pass on keep drifting: their center and spread change from batch to batch. Later layers are trying to hit a moving target.

Key idea

Re-center and re-scale each batch

batch normalization measures the mean and spread of each layer’s outputs for the current batch, then shifts and squeezes them to mean 0 and spread 1, just like standardizing features.

Build

Then let the layer adjust

Two learnable numbers (γ and β) then re-scale and shift the result if that helps. The upshot: faster, steadier training that is less sensitive to the learning rate and to initialization.

Real life

In real life: grading on a curve

Three classes take different tests: one easy, one hard, one in between. Raw scores aren’t comparable, so the teacher grades on a curve: each class is re-centered and re-scaled. Batch norm does this for every layer, every batch.

Quick check: What does batch normalization do to a layer’s outputs?

It standardizes activations per batch, then applies a learnable scale and shift.

Pseudocode

for each batch of examples, at one layer:
    mean = average of the activations
    std  = spread of the activations
    normalized = (activation − mean) / std
    output = γ × normalized + β      # learnable re-scale and shift

Key terms

batch normalization
Re-centering and re-scaling a layer’s outputs for each batch so training stays stable.