Optimization

Batch Normalization

Normalize activations using batch statistics to stabilize deep training (and understand the train vs inference mismatch).

status: reviewimportance: importantdifficulty 3/5math: undergraduateread: 14mprediction probe

Concept Structure

Batch Normalization

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Commit a prediction against the code witness.

1prerequisites
1next concepts
2related links

Learner Contract

What this page should let you do.

You are here becauseNormalize activations using batch statistics to stabilize deep training (and understand the train vs inference mismatch).

This Optimization concept is the current object: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.

Before thisBackpropagation

1 prerequisite listed; refresh them before leaning on the math or code.

By the end4/4 sections ready | code witness expected | prediction probe

Explain the mechanism, trace the main notation, and answer the prediction probe against the code witness.

Do this firstIntuition

Read the intuition before the notation; the math should name a mechanism you already felt.

Then go nextLayer Normalization & RMSNorm

Follow this edge after making one prediction here; the next page should reuse the result, not restart the route.

Test the linkUse the prediction probe to commit to the mechanism before moving on.Then continue to Layer Normalization & RMSNorm

Claim/source review status

Claim review not recorded

No structured claim checks yet; source metadata is not enough to establish support.Metadata-derived; review may be AI-assisted. Not a human certification.
Claims0/0 reviewed
Sources0 cited
Codeattached
Demoplanned
Reviewednot recorded
Updatedpage 2026-06-29

Object flow

4/4 sections readyAsk about thisResearch room
ConceptBatch NormalizationOptimization
Local snapshot ready
concept:optimization/batch-normalization
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

BatchNorm was one of the key tricks that made very deep convolutional networks train reliably.

The basic idea is simple: for each feature channel, normalize activations using the mean and variance computed over the current mini-batch. This keeps activations in a stable numeric range and often makes optimization easier.

But BatchNorm has an important downside: it introduces a train vs inference mismatch. During training you use batch statistics; at inference you use running averages. This is one reason transformers prefer LayerNorm/RMSNorm.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

For a batch of activations xRm×dx\in\mathbb R^{m\times d} (batch size mm, features dd), BatchNorm normalizes each feature dimension:

x^b,j=xb,jμjσj2+ϵ,\hat x_{b,j} = \frac{x_{b,j} - \mu_j}{\sqrt{\sigma_j^2 + \epsilon}},

where

μj=1mb=1mxb,j,σj2=1mb=1m(xb,jμj)2.\mu_j = \frac{1}{m}\sum_{b=1}^m x_{b,j},\qquad \sigma_j^2 = \frac{1}{m}\sum_{b=1}^m (x_{b,j} - \mu_j)^2.

Then apply learned scale and shift:

yb,j=γjx^b,j+βj.y_{b,j} = \gamma_j\,\hat x_{b,j} + \beta_j.

The learned γj\gamma_j and βj\beta_j are important: normalization gives the optimizer a stable coordinate system, but the model can still recover whatever feature scale and offset are useful. During backpropagation, each example's normalized value depends on the other examples in the same mini-batch through μj\mu_j and σj2\sigma_j^2, so the layer is not example-independent while training.

At inference, you typically use running averages of (μj,σj2)(\mu_j,\sigma_j^2) accumulated during training instead of per-batch values.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
import numpy as np

rs = np.random.RandomState(0)
x = rs.randn(6, 4) * 3.0 + 5.0  # batch activations with nonzero mean/scale
eps = 1e-5

mu = x.mean(axis=0, keepdims=True)
var = ((x - mu) ** 2).mean(axis=0, keepdims=True)
xhat = (x - mu) / np.sqrt(var + eps)

print("per-feature mean before:", np.round(x.mean(axis=0), 3))
print("per-feature mean after :", np.round(xhat.mean(axis=0), 3))
print("per-feature var after  :", np.round(xhat.var(axis=0), 3))
04

04

Interactive Demo

Use the authored prediction probe to test the mechanism without a live widget.

Section prompt

Prediction check: before running the witness, predict the four feature means and variances after normalization. Then change the batch size from 6 to 2 and watch how the estimated statistics become more dependent on the specific examples in the mini-batch.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

Normalize activations using batch statistics to stabilize deep training (and understand the train vs inference mismatch).

Demo notes open01 / Intuition
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Batch Normalization should make visible.

Visual Inquiry

Make the image answer a mathematical question

Normalize activations using batch statistics to stabilize deep training (and understand the train vs inference mismatch).

4/4 stages readyDemo notes connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Batch Normalization easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

Source gapNo canonical references are listed yet.

Add source metadata before treating this page as source-grounded.

Claim Review

Normalize activations using batch statistics to stabilize deep training (and understand the train vs inference mismatch).

StatusSubstantive claim review pending

Source IDs and witness objects are attached for review; they are not proof by themselves.

SourcesNo references

Add source metadata before claiming support.

Witnesses3 local objects

Use equation, code, and demo objects to check whether the source support is operational.

Practice Loop

Try the idea before it explains itself

Normalize activations using batch statistics to stabilize deep training (and understand the train vs inference mismatch).

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Batch Normalization.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Object research drawerClose
ConceptBatch NormalizationOptimization

Research Room

Attach the question to an exact object

Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptOptimization

Batch Normalization

Anchored question

What is the smallest example that makes Batch Normalization click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays locally in this browser for concept:optimization/batch-normalization.

No local draft saved.
Evidence to inspect
  • Definition, prerequisite, and contrast concept links
  • The equation or code witness that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Batch Normalization Object key: concept:optimization/batch-normalization Context: Optimization Anchor id: concept/concept-notebook/optimization/batch-normalization Open question: What is the smallest example that makes Batch Normalization click without losing the math? Evidence to inspect: - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

Open source object
concept/concept-notebook/optimization/batch-normalization concept:optimization/batch-normalization