I understand your concern about the "jump" in loss at the beginning of each epoch when using the standard shuffling approach (Option 1). This phenomenon occurs because, at the start of a new epoch, the model encounters examples it hasn't seen in the current epoch yet, leading to a temporary increase in loss until it "re-adapts" to the new data. This can make training curves look noisier and may not accurately reflect the model's true progress.
To address this issue and achieve a smoother training process there are several strategies you can consider which go beyond the two options you initially presented. Here are some effective approaches:
1. Continuous Shuffling (Option 3)
Instead of shuffling the entire dataset at the beginning of each epoch you can implement continuous shuffling. This means that you shuffle the dataset once at the beginning of training and then iterate through it in a circular manner.
How it works:
- Shuffle the entire dataset once at the beginning of training.
- Divide the shuffled dataset into mini-batches.
- Train on these mini-batches sequentially.
- When you reach the end of the dataset continue from the beginning without re-shuffling until you reach the desired number of epochs.
Pros:
- No Epoch Boundaries: Since there are no distinct epoch boundaries the loss will not “jump” at the start of each epoch
- Smoother Training: Provides a more continuous and smooth training process, as the model is constantly seeing new combinations of examples without the reset that occurs at epoch boundaries
- Effective Shuffling: The initial shuffle ensures that the order of examples is randomised, maintaining the benefits of shuffling.
Cons:
- Lack of Re-shuffling: Examples maintain the same relative order throughout training which might lead to some bias over very long training periods. However this is generally a minor issue compared to the benefits
2. Reservoir Sampling
Reservoir sampling is a technique to randomly select k samples from a stream of data. This can be used to create a new “epoch” on the fly without the need to shuffle the entire dataset.
How it works:
- Initialise a reservoir of size k (the number of examples you want per epoch).
- For each example in the dataset:
- With a certain probability replace a random example in the reservoir with the current example.