Log inStart free
LESSON 2.27 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

SGD and mini-batches

Watch noisy small batches race the full gradient down the same ravine.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 2.27 · BATCH BAYL(w₀) = 15.4 · saddle L = 1 · minima L = 0
01
Stage 1 of 6 · Data and loss
Each example tilts the objective L by its own aᵢ·w. The tilts add to zero, so L is the mean.
Explain it simply

The map shows the loss L over two weights. It has a narrow ravine along w₁, a saddle in the middle, and two lowest points. Each of the 8 examples sees the same surface, tipped a little by its own arrow in the panel. The arrows cancel out, so the average loss of the 8 examples is exactly L.

A contour map of L over w₁ from −3 to 3 and w₂ from −1.5 to 1.5. A narrow ravine runs along w₁. It has a saddle at (0, 0), where L = 1. The minima at (−2, 0) and (2, 0) have L = 0. The start w₀ = (0.02, 1.2) has L = 15.4. The panel shows 8 teal arrows, the tilts of the 8 examples. They add to (0, 0).

examples and their tiltsweights w and their pathloss, gradients, noisefull batch, to compare
objective L(w): the mean loss of 8 examples1411−3−2−10123−101w₁w₂w₀ = (0.02, 1.2)each example tilts L by aᵢ·wℓᵢ(w) = L(w) + aᵢ·wthe 8 tilts add to (0, 0)12345678the 8 exampleseach with its own tilt aᵢ12345678objective L(w): the mean loss of 8 examples1411−3−2−10123−101w₁w₂w₀ = (0.02, 1.2)each example tilts L by aᵢ·wℓᵢ(w) = L(w) + aᵢ·wthe 8 tilts add to (0, 0)12345678the 8 exampleseach with its own tilt aᵢ12345678
Toy: the 2.C2 surface · 2 weights · 8 examples · w₀ = (0.02, 1.2) · 100 steps
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
ℓi(w)=L(w)+ai⋅w,L=1N∑i=1Nℓi\sy{ell}{grad}{\ell_i}(\sy{w}{param}{w}) = \sy{L}{grad}{L}(\sy{w}{param}{w}) + \sy{a}{data}{a_i}\cdot \sy{w}{param}{w},\qquad \sy{L}{grad}{L} = \frac{1}{\sy{N}{data}{N}}\sum_{i=1}^{N} \sy{ell}{grad}{\ell_i}
L(w0)=(0.022−4)216+10⋅1.22=15.4L(w_0) = \tfrac{(0.02^2 - 4)^2}{16} + 10\cdot 1.2^2 = 15.4

Each example's loss is L, tipped by its own tilt.

Common mix-ups

MYTHEvery SGD step lowers the loss.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01If B goes from 1 to 4, does the spread of the batch gradients shrink or grow?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.