How do you detect overfitting and underfitting in practice, and what do you do about each?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Watch train and validation loss over training. Underfitting: both losses are high and close together, or train loss is still steadily decreasing when you stop - the model hasn't extracted the available signal. Overfitting: train loss keeps falling while val loss plateaus and then rises - the model is memorizing.
Full worked answer with diagram
Watch train and validation loss over training. Underfitting: both losses are high and close together, or train loss is still steadily decreasing when you stop - the model hasn't extracted the available signal. Overfitting: train loss keeps falling while val loss plateaus and then rises - the model is memorizing.
For underfitting: increase capacity (width/depth/params), improve features or input representation, train longer, raise the learning rate if optimization is stalling, reduce regularization strength.
For overfitting, in rough order of preference:
- More or better data - almost always the highest-leverage fix.
- Data augmentation - cheap synthetic diversity.
- Regularization - weight decay, dropout, label smoothing.
- Early stopping - checkpoint on val loss, keep the best.
- Reduce model size - usually the last resort in deep learning.
Karpathy's training recipe is the practical framing interviewers like: first deliberately overfit a small batch to near-zero loss to prove the model and pipeline can learn at all, then regularize back toward generalization. If you can't overfit 100 examples, you have a bug, not a regularization problem.
Two traps worth naming: (1) a val loss that's suspiciously better than expected often means leakage, not brilliance; (2) in LLM fine-tuning, "overfitting" often shows up as behavioural regressions (loss on the SFT set drops while general capability degrades - catastrophic forgetting), so you monitor held-out capability evals, not just the fine-tuning loss.
Worth sketching. Drawing the gate before the regularization branch shows you separate bugs from generalization problems.
flowchart TD
A["New model and pipeline"] --> B{"Can you drive loss to<br/>near zero on 100 examples?"}
B -->|"no"| C["It is a bug: check labels,<br/>masking, LR, data loader"]
C --> B
B -->|"yes"| D["Train on full data,<br/>watch train against val"]
D --> E{"Val loss rising<br/>while train falls?"}
E -->|"yes"| F["More data, augmentation,<br/>weight decay, early stop"]
E -->|"no, both high"| G["More capacity<br/>or train longer"]
What a good answer covers
- Watch train and validation loss over training
- Underfitting: both losses are high and close together, or train loss is still steadily decreasing when…
- Overfitting: train loss keeps falling while val loss plateaus and then rises - the model is memorizing
- For underfitting: increase capacity (width/depth/params), improve features or input representation,…
- For overfitting, in rough order of preference: 1
Key terms: Underfitting · Overfitting · More or better data · Data augmentation · Regularization · Early stopping
In the glossary: Weight decay · Dropout · Early stopping · Fine-tuning · SFT · Catastrophic forgetting
Interviewer follow-ups to expect
Why start by overfitting a single batch?
Your SFT loss is decreasing nicely but users say the model got worse - what happened?
When would you accept some overfitting deliberately?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep