Skip to main content
Luxara Academy

Archive — one question answered

What does mini-batch size 32 mean?

Why not update after every email or after the whole dataset?

A mini-batch is the set of examples used together for one gradient before each update. With 128 emails and batch_size = 32, each epoch has 128/32=4128 / 32 = 4 steps — each step averages loss and gradients over 32 messages.

Three styles:

  • Online (batch 1): 128 steps/epoch, noisy, slow on vector hardware.
  • Full batch (128): one gradient/epoch, stable but heavy on memory, hard to escape bad plateaus on large data.
  • Mini-batch 32: middle ground — on the course’s later 1 797 digit images, 1797/32≈571797 / 32 \approx 57 steps/epoch.
python
n, batch = 128, 32
assert n % batch == 0
steps_per_epoch = n // batch  # 4

Same seed and shuffle order must reproduce the same loss trace — why the course pins seeds when teaching batches. On CPU-only homework, a batch of 32 often fits L2 cache better than scanning all 1797 digits at once, which is why the course introduces mini-batch before the full MNIST loop.