Mini-Batch Gradient Descent
Training a model is basically a long series of tiny parameter tweaks that make its predictions less wrong. Mini-batch gradient descent is a practical way to decide how much data to look at before making each tweak, balancing speed, stability, and memory use.
What it is and how it works
In supervised learning you choose a loss function (like cross-entropy for classification or MSE for regression) and try to minimize it. Gradient descent does this by computing the gradient (the direction that increases loss) and stepping the parameters the other way. Mini-batch gradient descent computes that gradient using a small subset of the training data—a mini-batch—instead of the whole dataset (batch GD) or a single example (stochastic GD). A typical update looks like:
for each mini-batch B:
g = (1/|B|) * sum_{(x,y) in B} ∇θ L(fθ(x), y)
θ = θ - η * g
Why mini-batches matter
- Efficiency: Vectorized mini-batches run fast on GPUs/TPUs and fit in memory.
- Less noisy than single-example updates: Gradients are more reliable, so training is steadier.
- More flexible than full-batch: You don’t need to load or process the entire dataset per step, which can be painfully slow.
Practical intuition and examples
Think of estimating an average: using the whole dataset gives the cleanest estimate but is expensive; using one point is cheap but jittery; a mini-batch is a good compromise. In spam detection or credit scoring with millions of rows, mini-batches (e.g., 32–1024 samples) let you train models like neural networks efficiently. In PyTorch, this is the default pattern with a DataLoader and its batch_size; in Keras, it’s the batch_size argument to model.fit. Batch size also interacts with learning rate and convergence: larger batches usually allow larger, smoother steps; smaller batches inject noise that can help escape sharp, brittle solutions.
Mini-Batch Gradient Descent is an iterative optimization method that updates model parameters using gradients computed on small subsets (“mini-batches”) of the training data rather than the full dataset or single examples. It balances the stability of full-batch updates with the computational efficiency and regularizing noise of stochastic updates, enabling scalable training on large datasets and efficient use of vectorized hardware (e.g., GPUs) in supervised learning.
Imagine you’re trying to improve a soup recipe by tasting it. You could taste the whole pot every time (slow), or just one spoonful (fast but unreliable). A smarter approach is tasting a small bowl each time—enough to get a good signal without taking forever.
Mini-Batch Gradient Descent is that “small bowl” idea for training AI models. Instead of updating the model after looking at every single training example, it updates after looking at a small chunk (a mini-batch). This usually makes training faster and steadier, and it works well with modern hardware like GPUs, which like processing data in chunks.