# How Do You Spot Overfitting During Fine-Tuning?

> How to spot overfitting when you fine-tune a model: training loss falling while validation loss rises, and the checks that keep the score honest, for your AI interview.

**In short:** Overfitting in fine-tuning means the model learns its training examples so well that it does worse on new ones. You spot it when training loss keeps falling while validation loss, measured on examples it never trained on, starts rising. Then you stop and keep the best checkpoint.

AI and LLM interview question Q297, Fine-tuning and adaptation. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-do-you-spot-overfitting-during-fine-tuning

## Say it in 30 seconds

Overfitting in fine-tuning means the model memorises its training examples instead of learning the pattern behind them. I spot it by watching two numbers after each pass over the data. Training loss keeps falling, but validation loss, scored on examples the model never trained on, starts rising. When that gap grows, I stop and keep the checkpoint from the best pass. I also check that no validation example is a near copy of a training one, because a copy hides the problem.

## Say it in 2 minutes

Fine-tuning trains a model that already exists on your own examples, such as past claim notes or support chats, so it learns that one job better. The risk is that it learns the examples themselves, typos and one-off wording included, and so misses the pattern behind them. That is overfitting. It is easy to miss, because the model looks better and better on the data it trains on.

I watch two numbers after every pass over the training data, called an epoch. Training loss measures error on the examples the model learns from. Validation loss measures error on held-out examples it never trains on. Early on both fall together. When training loss keeps falling but validation loss starts climbing, the model has begun to memorise. That turn is my signal.

Then I act on it. I keep the checkpoint from the best epoch, even if it is earlier than the last, and I stop once validation has not improved for a set number of epochs. Before I trust the numbers, I check that no validation example is a near copy of a training example, because copies make the score look great. I also test the tuned model on fresh tasks and compare it with the base model, since a lower loss does not prove better answers.

## What is overfitting during fine-tuning, in plain words?

Fine-tuning takes a model that already exists and trains it further on your own examples, such as past claim notes or support chats. The aim is for it to learn the pattern behind those examples. Overfitting is when it learns the examples themselves instead, typos and one-off wording included.

Google's machine learning course puts it simply: "Overfitting occurs when a model performs well on training data but poorly on new, unseen data." The model looks clever on the files it has seen and stumbles on the next one.

Think of a claims adjuster who learns last year's files word for word. A new flood claim arrives on a slightly different form, and she freezes, because she learned the files, not how claims work. A realistic case: a triage model fine-tuned on 4,000 past claim notes (made-up numbers) scores very well on those notes, yet sends genuine new claims to the wrong queue.

- **Epoch:** One full pass through the training examples. Azure's guide describes the number of epochs as the number of complete passes through the training dataset.
- **Training loss:** The error the model makes on the examples it learns from. Lower is better, but only up to a point.
- **Validation loss:** The error on held-out examples the model never trains on. This is the number to trust most when you judge how the model will do on new work.
- **Checkpoint:** A saved copy of the model at one point in training, so you can go back to it.
- **Base model:** The model before your extra training, the starting point you tune.

## Which two numbers do you watch, and what do they tell you?

After every epoch I record two losses. The validation set is the part kept back for checks while training runs: "A validation set performs the initial testing on the model as it is being trained."

*Diagram, Watch the gap between two losses: Read after each epoch. Training loss and validation loss fall together at first. When validation turns up while training still falls, the model has started to memorise, so the best checkpoint is the one just before the turn.*
1. Training loss keeps falling as the model learns the examples.
2. Validation loss is read on examples held back from training.
3. When validation turns up while training falls, the gap widens.
4. Stop after a few epochs with no gain, and keep the best checkpoint.

> "after a certain number of iterations, loss declines or holds steady (converges) for the training set, but increases for the validation set." (Google's machine learning crash course)

So the check is the gap between the two numbers, not one number on its own. A training loss of 0.36 looks great until you see the validation loss sitting at 1.38 beside it.

## Why does a fine-tune overfit so easily?

Three things raise the risk. The first is the number of passes. Microsoft's fine-tuning guide says: "More passes give the model more opportunities to learn, but can increase overfitting."

The second is a small dataset. A narrow job may have only a small set of examples, and a large model can memorise a small set quickly. The third is data that misses real cases. Google lists this as a common cause: "The training set doesn't adequately represent real life data (or the validation set or test set)." The same page names overly complex models as a second common cause.

*Diagram, Causes and fixes: Three things raise the risk, and each can lead to overfitting. The fixes start at the turn: stop after a few epochs with no gain, lower the learning rate multiplier, and clean the split.*
1. Few examples make memorising easy.
2. Many passes over the same rows push it to memorise.
3. Data that misses real cases teaches the wrong pattern.
4. The fixes start at the turn: stop, lower the rate, clean the split.

## How do you pick the checkpoint and stop?

OpenAI's fine-tuning guide says: "We create a full model checkpoint for you at the end of each training epoch." So you can roll back to the best one instead of keeping the last one. OpenAI notes these checkpoints help when a model improves early on but then memorises the training data.

> "Use with metric_for_best_model to stop training when the specified metric worsens for early_stopping_patience evaluation calls." (Hugging Face Transformers docs, early stopping)

Here is the same rule as a short program. The numbers are made up, from a claims triage run. The code stops after two epochs with no better validation loss and keeps the best one.

```python
# Made-up losses from a claims-triage fine-tune, one number per epoch.
train_loss = [1.92, 1.31, 0.88, 0.55, 0.36]
val_loss = [1.97, 1.40, 1.02, 1.11, 1.38]

best_epoch, best_val, bad_epochs = 0, float("inf"), 0
for epoch, (train, val) in enumerate(zip(train_loss, val_loss), start=1):
    print(f"epoch {epoch}: train {train:.2f}  val {val:.2f}  gap {val - train:+.2f}")
    if val < best_val:
        best_epoch, best_val, bad_epochs = epoch, val, 0
    else:
        bad_epochs += 1
        if bad_epochs == 2:  # stop after 2 epochs with no better validation loss
            print("stop: no better validation loss for 2 epochs in a row")
            break
print(f"keep the checkpoint from epoch {best_epoch} (val {best_val:.2f})")
```

Output:

```text
epoch 1: train 1.92  val 1.97  gap +0.05
epoch 2: train 1.31  val 1.40  gap +0.09
epoch 3: train 0.88  val 1.02  gap +0.14
epoch 4: train 0.55  val 1.11  gap +0.56
epoch 5: train 0.36  val 1.38  gap +1.02
stop: no better validation loss for 2 epochs in a row
keep the checkpoint from epoch 3 (val 1.02)
```

Read the output from the bottom up. Epoch 3 had the lowest validation loss, 1.02, so that checkpoint is kept. By epoch 5 the gap was 1.02 and validation had risen to 1.38, so the run was stopped.

> **Tip:** In an interview, say the rule in one line: keep the checkpoint with the best validation score, even if it is earlier.

## How do you keep the check honest?

- **Loss alone: A good number, a weak model.** A low loss can come from copied examples, or from a model that learns the scoring quirks rather than the job.
- **Loss plus checks: Honest, and tested on the job.** Remove near-copies from the validation set, then test on fresh tasks and compare with the base model.

Google's guide on splitting data gives the first rule: "After splitting a dataset into training, validation, and test sets, delete any examples in the validation set or test set that are duplicates of examples in the training set."

Microsoft says the same about the split: "Keep validation and final test examples out of the training set." Azure also lists a learning rate multiplier, a setting that scales how big each learning step is, and says: "A smaller multiplier can help reduce overfitting."

Google's guide for Vertex AI tuning adds a last check: "Evaluate the tuned model using tuning and validation metrics after the tuning job completes." Then test the model on fresh tasks, and compare it with the untuned base model. A tuned model that barely beats the base has learned little.

### What would you check if validation loss looks too good?

1. **Look for copies:** Search the validation rows for near-copies of training rows. Copies make the score look great, so remove them first.
2. **Check the split:** Confirm the split was made before training, and that the same customer or claim never sits on both sides.
3. **Compare with the base model:** Run the same fresh tasks on the untuned model. A small gain means the fine-tune taught little.
4. **Read real answers:** Read twenty outputs by hand, from cases the model never saw. A person spots a copied answer quickly.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] Two losses: training loss, and validation loss on held-out examples.
- [ ] Overfitting shows as a gap that opens after the turn, so watch both numbers.
- [ ] Stop at the turn and keep the best checkpoint, which may be an earlier one.
- [ ] Many epochs, a small dataset, unrepresentative data and overly complex models all raise the risk.
- [ ] A check on fresh tasks against the base model, alongside the loss.
- [ ] A low loss can still hide a weak model, so say so plainly.

**Common traps**

- Trap: "The lower the training loss, the better the model." Better: Training loss can keep falling while the model does worse on new data. Watch validation loss.
- Trap: "Train for more epochs to be safe." Better: More passes can increase overfitting. Stop when held-out loss stops improving.
- Trap: "A perfect score means it is ready to ship." Better: A perfect score can come from copied examples. Check the split and test on fresh tasks first.

## Can you spot the overfit?

**Spot the overfit:** Which run is overfitting, judging by its loss numbers?

A. Training loss 1.92 to 0.36, validation loss 1.97 to 1.02: both still falling.
B. Training loss 1.92 to 0.36, validation loss 1.02 to 1.38: the gap keeps growing.
C. Training loss 1.92 to 1.31, validation loss 1.97 to 1.40: both falling, slowly.
D. Training loss 0.36, validation loss 0.36: the scores match, so it is ready.

**Answer:** B. Validation loss climbed from its low point while training kept falling. That widening gap is overfitting. Read both numbers before you trust a run.

**Quick check:** Validation loss is very low from the first epoch. What do you check first?

A. Whether validation examples have near-copies in the training set
B. Whether the learning rate can go up
C. Whether to add more epochs
D. Whether the model is too small

**Answer:** A. Near-copies make validation look too good, so remove them and judge the run again. Learning rate, epochs and model size are unlikely to explain a score that starts this low.

## Can you answer these from memory?

**Flash cards**

- **What is overfitting in fine-tuning?** The model memorises its training examples, so it does worse on new ones.
- **Which two losses do you watch?** Training loss, and validation loss on examples it never trains on.
- **When do you stop?** When validation loss turns up while training loss still falls.
- **Which checkpoint do you keep?** The one with the best validation score, even if it is earlier.
- **What can hide overfitting?** Near-copies of training examples sitting in the validation set.
- **Which setting can raise the risk?** Too many epochs. More passes can increase overfitting.

## Likely follow-up questions

- Q294 How do you prepare a fine-tuning dataset? https://designervenkat.online/interview/ai/how-to-prepare-a-fine-tuning-dataset
- Q295 How much data do you need? https://designervenkat.online/interview/ai/how-much-data-do-you-need
- Q296 What is catastrophic forgetting? https://designervenkat.online/interview/ai/what-is-catastrophic-forgetting
- Q298 Learning rate and epochs for fine-tuning? (full answer coming)
- Q300 How do you evaluate a fine-tuned model? https://designervenkat.online/interview/ai/how-do-you-evaluate-a-fine-tuned-model
- Q413 Overfitting vs underfitting? https://designervenkat.online/interview/ai/overfitting-vs-underfitting
