Epochs
An epoch is one complete pass through the entire training dataset. Neural networks usually need multiple epochs because one pass through the data is rarely enough to learn a useful pattern.
What Is an Epoch?
An epoch means that the neural network has gone through the entire training dataset once.
For example, suppose we have 5 training examples:
Training Data
Example 1
Example 2
Example 3
Example 4
Example 5
When the neural network processes all 5 examples once, that is 1 epoch.
Example 1
Example 2
Example 3
Example 4
Example 5
↓
1 Complete Pass
↓
1 Epoch
A Simple Example
Imagine that we want to train a neural network to predict whether a student will pass based on study hours.
Student Study Hours Result
A 1 Fail
B 2 Fail
C 4 Pass
D 5 Pass
E 7 Pass
We have 5 training examples.
If the neural network processes all 5 students once, it has completed one epoch.
What Happens During One Epoch?
During an epoch, the neural network goes through the training data and learns from it.
Training Data
↓
Student A
↓
Prediction → Loss → Weight Update
Student B
↓
Prediction → Loss → Weight Update
Student C
↓
Prediction → Loss → Weight Update
Student D
↓
Prediction → Loss → Weight Update
Student E
↓
Prediction → Loss → Weight Update
↓
Epoch 1 Complete
After the network has processed the entire dataset once, the first epoch is finished.
Why Do We Need Multiple Epochs?
One pass through the training data may not be enough for the neural network to learn the patterns properly.
So we allow it to see the same training data again.
Epoch 1
↓
Network learns a little
Epoch 2
↓
Network improves
Epoch 3
↓
Network improves more
Epoch 4
↓
Network improves again
Epoch 5
↓
Network may become much better
Each epoch gives the model another opportunity to adjust its weights and reduce its errors.
Epochs and Loss
During training, we often watch the loss to see whether the model is improving.
Epoch 1
Loss = 1.20
Epoch 2
Loss = 0.80
Epoch 3
Loss = 0.52
Epoch 4
Loss = 0.31
Epoch 5
Loss = 0.20
In this example, the loss is decreasing as training continues.
That suggests the model is learning from the training data.
Easy Way to Understand an Epoch
Think about studying a textbook.
Read the entire textbook once
↓
1st pass
Read the entire textbook again
↓
2nd pass
Read the entire textbook again
↓
3rd pass
Each complete pass through the textbook is similar to an epoch.
Similarly, each complete pass through the training dataset is one epoch.
Dataset vs Epoch
These two terms are different.
Dataset
↓
The complete collection of training examples
Epoch
↓
One complete pass through that dataset
For example:
Dataset = 1,000 training examples
1 Epoch
= Process all 1,000 examples once
5 Epochs
= Process the 1,000 examples five times
Epochs in Python
In Python, we can represent multiple epochs using a loop.
epochs = 5
for epoch in range(epochs):
print("Epoch:", epoch + 1)
This runs the training process five times.
Epoch: 1
Epoch: 2
Epoch: 3
Epoch: 4
Epoch: 5
In a real neural network, the training code would run inside this loop.
Epochs Inside a Training Loop
A simplified training loop can look like this:
epochs = 5
for epoch in range(epochs):
prediction = model(training_data)
loss = calculate_loss(prediction, target)
gradients = calculate_gradients(loss)
update_weights(gradients)
print("Epoch:", epoch + 1)
print("Loss:", loss)
The important part is that the complete training process is repeated for each epoch.
Epoch
↓
Prediction
↓
Loss
↓
Gradients
↓
Weight Update
↓
Next Epoch
What If We Use Too Few Epochs?
If we stop training too early, the neural network may not have learned enough from the training data.
Epoch 1
Epoch 2
↓
Training stops too early
↓
Model may still have high loss
↓
Model may not have learned enough
This situation is commonly associated with underfitting.
Can We Use Too Many Epochs?
Yes. More epochs are not automatically better.
If we keep training for too long, the model may start fitting the training data too closely and perform worse on new, unseen data.
Too Few Epochs
↓
Model has not learned enough
Good Number of Epochs
↓
Model learns useful patterns
Too Many Epochs
↓
Possible overfitting
This is why we do not simply choose the largest possible number of epochs.
Important: An Epoch Is Not One Weight Update
This is a common beginner mistake.
One epoch means one complete pass through the dataset. The number of weight updates depends on how the data is divided into batches.
Epoch
↓
Many training examples
↓
Processed in batches
↓
Weight updates
↓
Complete dataset processed
↓
Epoch complete
We will learn exactly how this works when we study batch size and iterations.
Epoch vs Iteration
Do not confuse these terms.
Epoch
→ One complete pass through the entire dataset.
Iteration
→ One training step using one batch of data.
For example, if we have 100 training examples and use batches of 20:
100 examples
÷
20 examples per batch
=
5 iterations per epoch
So:
1 Epoch
= 5 Iterations
10 Epochs
= 50 Iterations
We will study this relationship in detail in the next topics.
Remember This
Epoch
=
One complete pass through the entire training dataset.
Example:
1,000 training examples
1 Epoch
= Model processes all 1,000 examples once.
10 Epochs
= Model processes all 1,000 examples ten times.
The simplest definition to remember is: one epoch = one complete pass through the training dataset.
Check Your Understanding
What is an epoch?
One complete pass through the entire training dataset.
If there are 500 training examples, how many
examples are processed in one epoch?
All 500 examples.
If we train for 10 epochs, how many times does the
model see the complete dataset?
Ten times.
Does one epoch always mean one weight update?
No. An epoch can contain many weight updates when the
data is divided into batches.