Overfitting occurs when a model performs well on training data but poorly on unseen inputs. The model has learned the training examples too closely instead of generalizing. section 2.2.1 section 2.4.1
Training loss alone cannot identify the best model. A validation set supports hyperparameter selection and reveals when additional training stops improving generalization. section 2.2.1 section 2.4.1
A practical training workflow uses separate data and a stopping rule:
- Divide the original training data into a training set and a validation set; one example uses 50,000 and 10,000 observations. section 2.4.1
- Load training, validation, and test sets separately with PyTorch DataLoader objects. section 2.4.1
- Track validation loss while training and stop after it fails to improve for a chosen patience period; the example uses patience=10. section 2.4.1
- Evaluate the trained model on the test set after selecting when to stop. section 2.2.1
A GPT model memorizing passages
A decoder-only GPT model is trained to predict the next token. Training for too long can make its generated text identical to passages in the novels used for training. Comparing checkpoints saved every 10 epochs shows the tradeoff: the 40-epoch model is highly coherent but may copy passages, while the 20-epoch model is less likely to copy but can contain grammatical errors. section 12.1.2 section 12.0
Figure 2.1 The steps involved in training a deep learning model
Use the training-process figure to follow prediction, loss calculation, backpropagation, and weight updates as the model learns. section 2.2.1























