Concepts / Text Generation with a Language Model

Text Generation with a Language Model

A training run records loss values as the model learns to generate text.

  • Programming

Two Losses, Two Measures

A training run records loss values as the model learns to generate text. One number is not enough to tell whether the model is learning useful patterns or merely getting better at reproducing its practice material. Read training loss and validation loss together: they measure fit on different data, so their trends reveal whether learning carries beyond the training examples.

Training dataTraining lossFit on seen materialHeld-out dataValidation lossFit on held-out material
Which data contributes to each loss, and what does each loss tell you?

Loss is a single number summarizing how far the model's predictions are from the text it was supposed to produce. A lower value generally means better fit on the data used to measure it. Training loss measures fit on the material the model sees during training. Validation loss measures fit on held-out material. Because both are recorded at the same stages, you can compare how each changes as training proceeds.

Trace the Run Across Epochs

Worked example

Reading the recorded values

In the source run, training loss starts at 9.781 and falls to 0.391 by the end. Validation loss starts at 9.933, also decreases, and is 6.452 after the tenth epoch. What do these values tell you?

  1. 1
    Compare the starting values

    Both losses begin high, with validation loss slightly higher than training loss.

  2. 2
    Follow the early trend

    Both losses decrease early in training. A shared decrease indicates that the model is learning patterns that help on both the training and held-out text.

  3. 3
    Compare the later behavior

    Training loss reaches 0.391, while validation loss remains much higher at 6.452 after the tenth epoch. The training fit has continued to improve without the same improvement carrying over to held-out data.

Result

The early shared decrease is a sign of learning. The later gap is evidence that the run is overfitting rather than continuing to improve its fit to held-out text.

Early epochsBoth losses fallAbout epoch twoTrends begin to separateLater epochsTraining falls; validationstagnates
How do training loss and validation loss move together at first, and what changes later?

At the start of the run, both losses fall sharply. That shared improvement suggests the model is learning patterns useful on both sets of text. The pattern changes after about the second epoch: training loss keeps falling, but validation loss stagnates. The two trends no longer tell the same story.

What do you think happens?

After validation loss has stopped decreasing while training loss continues to fall, what should you infer from the next part of the curve?

  • The model is still improving equally on both sets of text.

  • The model may be fitting the training text without improving on held-out text.

  • The validation loss is measuring fit on the training text.

Reveal answer
Answer:

The model may be fitting the training text without improving on held-out text.

Training loss measures fit on the training data, while validation loss measures fit on held-out data. A falling training loss paired with stagnant validation loss is the divergence associated with overfitting.

Find the Generalization Break

Before divergenceBoth losses decreaseAfter about epoch twoValidation loss stagnatesLater trainingTraining loss keeps falling
At what point does progress on training data stop matching progress on held-out data?
PatternWhat the losses showInterpretation
GeneralizingTraining and validation loss decrease togetherLearning is helping on both training and held-out text
OverfittingTraining loss falls while validation loss stagnatesThe model is fitting the training material without a matching improvement on held-out material

Compare the direction of both losses, not just the training loss by itself.

Generalization means that a fit learned from the training material carries over to held-out material. Overfitting is the contrasting pattern: the model memorizes its training data rather than generalizing from it. That is why the gap matters. If training loss keeps improving while validation loss does not, the model is getting better on what it practiced, but that improvement is not showing up on the data held aside for validation.

In the real world

The run begins with a model that, according to the source description, can mainly append commas to its starting context or repeat a word. By the end, it produces grammatically correct text. That improvement accompanies falling training loss. But the training curve alone does not establish that the model learned patterns that transfer to held-out text; the validation curve supplies that second check.

Respond to Signs of Memorization

Compare both lossesBoth decreaseContinue monitoringValidation stagnatesTraining still fallsStop extending therunDo not chase training lossaloneReconsider data andepochsUse more data or fewerepochs
What should you do when training loss keeps falling but validation loss stops improving?

Treat the point where validation loss stops improving while training loss continues to fall as a warning that the run is no longer making the same progress on held-out text. A practical response is to stop extending the run just to push training loss lower and to reconsider the training setup. The source identifies a very small dataset trained over many epochs as a setting where memorization is likely. It contrasts this with training on a much larger dataset, typically for only one epoch.

In the real world

In the described run, searching generated text reveals verbatim snippets from the training text, including a passage about irony in a story. This confirms that the model is reproducing material it saw. The source connects the outcome to the very small dataset and many training epochs.

Check Your Reading

MEDIUM

Use the recorded run: training loss starts at 9.781 and reaches 0.391; validation loss starts at 9.933 and is 6.452 after the tenth epoch. The source says both losses decrease early, then training loss keeps falling while validation loss stagnates after about the second epoch. Identify the point that signals overfitting, explain what the two losses tell you there, and name one practical change to consider.

Hints
  • First identify what data each loss measures.
  • Look for the point where the two trends stop moving together.
  • The source discusses dataset size and number of epochs as factors related to memorization.
  • Common mistake

    Judging a run by training loss alone.

    What it looks like

    Training loss keeps falling, so the model must still be improving.

    Why it fails

    That value measures fit on training data only. It does not show whether the fit carries over to held-out data.

    Do this instead

    Read validation loss alongside training loss and compare their trends.

  • Common mistake

    Treating any decrease in validation loss as proof that overfitting is impossible.

    What it looks like

    Validation loss decreased early, so later training must also be helping.

    Why it fails

    In the described run, both losses fall early, but validation loss later stagnates while training loss continues to fall.

    Do this instead

    Follow both losses across the run and identify when their trends separate.

  • Common mistake

    Treating a loss gap as direct proof of copied passages.

    Why it fails

    The gap signals overfitting, while the source checks for verbatim reproduction by searching generated text for passages from the training material.

    Do this instead

    Use the gap as a warning and inspect generated output for verbatim passages when checking for memorization.

Key Takeaways

  • Training loss measures fit on training data; validation loss measures fit on held-out data.
  • A shared decrease early in training indicates that learning is helping on both sets of text.
  • When training loss keeps falling but validation loss stagnates, the divergence signals overfitting.
  • Treat that divergence as a reason to stop extending the run just to lower training loss and reconsider dataset size and training duration.
  • The loss gap is a warning sign; searching generated text for verbatim training passages is a direct check for memorization.

Related concepts

More concepts starting with T