Epochs & Batching
What Is an Epoch?
One complete pass through the entire dataset
An epoch is one complete pass through every sample in the dataset. The scanner processes each sample once. After all 16 samples are seen, epoch 1 is complete and the next one begins.
Step 1 of 6: What Is an Epoch?
One complete pass through the entire dataset
An epoch is one complete pass through every sample in the dataset. The scanner processes each sample once. After all 16 samples are seen, epoch 1 is complete and the next one begins.
Step 2 of 6: Stochastic Gradient Descent
Updating weights one sample at a time
Stochastic Gradient Descent updates weights after each single sample. The gradient estimate is noisy because one sample cannot represent the full dataset. Notice the jittery, zigzag path -- each update pulls in a slightly different direction.
Step 3 of 6: Mini-batch Gradient Descent
The practical middle ground between SGD and full-batch
Batch size 4 averages gradients over 4 samples per update. The path is smoother than SGD while still updating 16 times per epoch. This is the sweet spot used in practice.
Step 4 of 6: Full-batch Gradient Descent
Using the whole dataset for each update
Full-batch gradient descent uses every sample to compute each gradient -- the smoothest path but the slowest per-step (and most memory hungry). Compared to the faded full-batch reference, smaller batches are noisier but update weights more frequently per epoch. The tradeoff: memory vs speed.
Step 5 of 6: Shuffling Matters
Why randomizing data order improves training
Shuffling the dataset each epoch ensures that mini-batches are diverse. The model sees samples in a different order every time, preventing it from memorizing patterns in the ordering. The loss curve is smoother and converges to a lower value.
Step 6 of 6: Putting It Together
Epochs times batch size equals training
Training = 10 epochs x 4 steps/epoch = 40 total weight updates. Each epoch processes all 64 samples in batches of 16. Over 10 epochs, the model sees 640 total samples. This is a reasonable number of epochs for most tasks.