liveBook · Manning

Overfitting

As explained in Generative AI in Action

Overfitting is a modeling condition in which learned patterns fit training data too closely and fail to generalize well to new examples.

Overfitting occurs when a model learns the particular patterns of its training data so well that it struggles with new examples. A fine-tuned LLM may perform well on familiar inputs yet prove less reliable on unseen requests. This is an important trade-off when adapting a general model to an enterprise task. section 2.8.6 section 2.5

Watch for overfitting at two different points:

  • During fine-tuning, compare performance with a baseline and evaluate the model on data it did not train on. Monitor results as the dataset changes; data quality and task complexity both matter. section 9.1.2
  • During prompt design, avoid excessive direction. An overspecified prompt can cause an LLM to echo the prompt or leave too little room for novel output. This is overfitting to a prompt by analogy, not the same as fitting training data. section 6.7

For fine-tuning, keep a validation dataset separate from the training dataset used to update model parameters. Check validation performance while adjusting the learning rate, number of epochs, or other hyperparameters. Reserve a test dataset for measuring final accuracy. A longer context window can also increase model complexity and overfitting risk when training data is limited, so more context is not automatically better. section 9.3.1 section 2.8.6

A narrowly tailored response task

Suppose an LLM is fine-tuned to return emoji responses to user messages. Prepare curated training examples and separate validation examples for the same task. If training examples appear successful but validation results are poor, revisit the data and training settings rather than treating training performance as proof that the model will handle new messages. section 9.3.1

Aim for enough high-quality examples to represent the target task, then compare the adapted model with a baseline on new inputs. Prompt wording, dataset size, training settings, and context-window length each involve trade-offs; choose them by observed performance rather than by training results alone. section 9.1.2 section 9.3.1

How Generative AI in Action covers it

How deep it goes
Defines the failure mode and gives validation-based monitoring guidance without deriving a mathematical test for overfitting.
Examples
Uses emoji-response fine-tuning examples to illustrate the need for separate training and validation data.
What it assumes
Assumes a fine-tuning task has been identified while defining the distinct roles of training, validation, and test datasets.
What you can do after
Diagnose/debug with validation results and baseline comparisons, then adjust fine-tuning settings when generalization is weak.
How it connects
Connects overfitting to fine-tuning, validation datasets, hyperparameters, prompt engineering, and context windows.

Also explained in

Compare how 24 books explain overfitting →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Generative AI in Action. The section links point to the parts of the book it draws on.