WHAT is the problem? For N=107 images, computing ∇θJ once means a full forward+backward pass over 10 million images before taking a single step. You'd get maybe a few dozen updates a day. Learning would crawl.
The key statistical insight: the true gradient is an average. Any average can be estimated from a random sample. So pick a random subset B (the mini-batch) of size m≪N:
Write the mini-batch gradient estimator. → gB=m1∑i∈B∇θℓi
Is it biased? → No, E[gB]=∇J.
How does its std scale with m? → σ/m.
Steps per epoch for N=1000,m=100? → 10.
Why is m=1 (SGD) sometimes preferred? → Noise escapes bad minima; cheapest step.
Recall Feynman: explain to a 12-year-old
Imagine you want the average height of everyone in a huge school. Measuring all 5000 kids takes forever. Instead you grab a random handful of 30, average their heights, and use that as a good guess. It's not perfect, but do it again with a new handful and it's usually close. Training a neural network is the same: instead of looking at every photo before nudging the network, you look at a small random pile of photos, figure out which way to nudge, and nudge. Small piles = many quick nudges. Sometimes a pile is odd and nudges you the wrong way, but over thousands of piles you drift the right direction. That's mini-batch gradient descent.
Dekho, neural network train karne ke liye hume loss ka gradient chahiye poore dataset pe. Lekin agar dataset mein 1 crore images hain, toh har ek step lene se pehle saari images dekhna padega — bahut slow. Dusra extreme yeh hai ki sirf ek image dekh ke step lo (SGD), par woh bahut noisy hota hai. Mini-batch gradient descent beech ka rasta hai: har baar ek chhota random batch (jaise 32, 64, 128 examples) lo, unka average gradient nikaalo, aur ek step le lo. Isse GPU bhi efficiently use hota hai aur updates fast aate hain.
Sabse important baat — yeh estimate unbiased hota hai. Matlab average nikaalo toh E[gB]= sacha gradient. Har single batch thoda galat direction de sakta hai, par hazaaron steps ke baad noise cancel ho jaata hai aur aap sahi jagah pahunch jaate ho. Aur noise ka size batch size m pe depend karta hai: standard deviation =σ/m. Isliye batch 4 guna badhao toh noise sirf aadha hota hai — diminishing returns, isliye bahut bada batch waste hai.
Ek aur mazedaar point: thoda noise acha hota hai. Woh model ko sharp/kharab minima aur saddle points se nikaal deta hai aur flat minima ki taraf le jaata hai jo better generalise karte hain. Isliye full-batch (jisme koi noise nahi) hamesha best nahi hota.
Practical tips: har epoch mein data shuffle karo taaki batches i.i.d. rahein; batch size badhao toh learning rate bhi thoda badhao (linear scaling rule); aur single step ka loss upar-neeche ho toh ghabrao mat — epoch average dekho. Bas yaad rakho: "root-m rules" aur "Mini is Just-Right".