Resources/Model training/What happens during training

Metric

Overfitting and underfitting

Overfitting is when a model memorises its training examples instead of learning the pattern behind them, so it does well on those examples and worse on new ones. Underfitting is the opposite: it hasn't learned the pattern at all.

Chapter 64 min read4 references

What it is

A training set is a sample of the situations a model will meet. It contains a pattern you want learned, such as how your assistant answers and in what tone and format, and noise you don't: the exact wording of one reply, a typo, the quirks of one customer's question. A model generalises when it picks up the pattern. It overfits when it also fits the noise, and it underfits when it hasn't picked up the pattern.

Underfittingmisses the patternA good fitfollows the patternOverfittingmemorises the noise
The same ten training examples, three models. The underfit model is wrong everywhere. The overfit model scores perfectly on these ten points but will be wrong on the next one, because it learned their noise. Fine-tuning a language model fails the same way: it starts reproducing your examples instead of the behaviour behind them.

How to spot it

The clearest signal is in the loss curves. Training loss can keep falling for as long as the model can memorise more. Validation loss, measured on conversations the model never trained on, stops falling when the model has learned what generalises, and rises once it starts memorising.

OVERFITTINGSTOP HEREepoch 1epoch 2epoch 3highlowlosstraining lossvalidation loss
Training loss keeps falling because the model can always memorise more. Validation loss is the honest one: when it turns upward, the model has started learning your examples rather than the pattern behind them.

In a fine-tuned language model, overfitting also shows in the answers themselves.

  • Verbatim copying: phrases, whole sentences, even names and numbers from training replies turn up in answers to unrelated questions.
  • Canned answers: one well-represented reply is given to questions that only resemble its original question.
  • Lost flexibility: questions phrased like the training data go well, differently phrased ones stumble, and general tasks the base model handled have become worse.
  • Confident invention: the model imitates the style of specific, detailed replies, such as named menus and numbered steps, without the knowledge behind them, and invents the specifics.

Why it happens

CauseWhy it leads to memorising
Too few examplesWith little data, memorising each reply is the easiest way to lower the loss
Too many epochsEach pass shows the same replies again, until the model recognises them
Learning rate too highLarge updates fit individual examples quickly
Duplicates and repeated repliesA reply that appears many times is learned as a fixed answer
Narrow dataThe model never sees how real questions vary, so it can't learn what varies
Too much capacity for the dataFull fine-tuning or a large adapter on a small set has room to store examples

How to prevent it

  • Stop at the best point. Use the number of epochs at which validation loss was lowest, or a checkpoint from that point. This is early stopping, the simplest and most effective guard.
  • Fewer epochs or a lower learning rate. Both limit how far the weights move from the base model.
  • More, and more varied, data. Cover the different ways people really ask, including short and vague questions. A few hundred varied examples teach more than a thousand near-duplicates.
  • Remove duplicates and over-repeated replies before training.
  • Regularisation: LoRA dropout, weight decay, or simply a smaller adapter rank, which limits how much can be stored.
Two runs on the same 150 conversations (illustrative)
  1. Run A: 6 epochs, multiplier 2. Training loss reaches 0.15. Validation loss is lowest after epoch 2 and ends well above that minimum. In the test chat, answers reuse whole sentences from training replies.
  2. Run B: 2 epochs, multiplier 1. Training loss ends at 0.6 and validation loss ends near its minimum. Answers keep the house style but are worded freshly for each question.
  3. Takeaway: Run A's lower training loss is the problem, not the achievement. Run B generalises, and cost a third as much to train.

Underfitting

Underfitting is the opposite failure: neither training nor validation loss falls much, and the tuned model answers much like the base model. The causes are too little training (too few epochs or steps, or too low a learning rate) or data with no consistent pattern, such as replies that answer similar questions in contradictory ways. Check the data first. Raising epochs or the learning rate on inconsistent data mostly teaches the inconsistency.

Common mistakes

  • Judging a run by its training loss. The lowest training loss usually belongs to the most overfit run.
  • Trying to fix a weak model with more epochs on the same small dataset.
  • Skipping the validation split to keep every example for training, and losing the only way to see overfitting.
  • Letting duplicates or one canned reply dominate the data.
  • Validating on conversations that also appear in training, which hides overfitting completely.

References and further reading

External sources open in a new tab.

  1. 01OverfittingGoogle Machine Learning Crash Course · developers.google.comGeneralisation, overfitting and the role of a held-out set, with interactive examples.
  2. 02OverfittingWikipedia · en.wikipedia.org
  3. 03Early stoppingWikipedia · en.wikipedia.orgStopping at the point of lowest validation error, the most common guard against overfitting.
  4. 04Regularization for Deep LearningGoodfellow, Bengio & Courville · Deep Learning, chapter 7 · deeplearningbook.orgThe textbook treatment of weight decay, dropout, early stopping and data augmentation.

Turn weeks of expert work into minutes

See how Scalata fits your team, your data, and your controls.