All courses

Exposure bias and compounding errors

Explain that training always conditions on true prefixes while generation conditions on the model's own outputs. Explain why an early wrong token can derail everything after it unless the model has learned to recover.

Builds on: Autoregressive generation loop, Shifted targets and parallel training

▶ Watch this lesson Start the whole course

What the animation says

Trained on truth

Training reports a low loss: given real text, the model predicts each next token well. Yet a long generated answer can drift, or build a whole page on one early slip. Same network, same task. So what differs? In training, every prefix is real text. That's called teacher forcing. If the model guesses Sydney here, the next step still sees the true word, Canberra. The mistake never enters its input. Now generation. The model writes Sydney. What does the next step see?

Exposure bias

Its own wrong word. In generation, the prefix is the model's own output. So the slip stays in the context for good, and every later step reads it. The model rarely saw text containing its own errors, so it often continues them as if correct. This mismatch is called exposure bias. The training loss only ever averages over true prefixes. It never measures the model on its own.

Small slips, long answers

Suppose a test on true prefixes shows a derailing token only zero point two percent of the time. So each token stays on track with chance ninety-nine point eight percent. With no recovery, an answer stays on track only if every token does. The chances multiply. For three hundred tokens, that's about e to the minus zero point six: roughly fifty-five percent. Now make it a thousand tokens. What share of runs stays on track?

Slips invite slips

About fourteen percent. A tiny per-token slip rate sank most of the long answers. And the real damage is worse than this count shows. After a slip, the prefix is unlike training text, so later predictions get less reliable. One slip invites more, and the answer keeps degrading. Even harmless oddities push a prefix away from real text and raise the slip chance. That's the compounding.

Simulating recovery

So how do long answers survive at all? Let's simulate a hundred thousand runs. This array holds one flag per run: on track or not. All start on. At every token, each run draws a random number u. An on-track run slips if u is below eps. An off-track run returns if u is below recover. We try recover at zero, then at one in ten. Which line lets a derailed run come back?

Recovery saves long outputs

The last line. Off-track runs come back when u falls below recover. Without recovery, about fifty-five percent are on track at token three hundred. With it, about ninety-eight. The share settles where leaving balances returning: slip rate times on equals recover times off. So on track is recover over recover plus slip rate: about ninety-eight percent. Training feeds true prefixes; generation feeds the model its own. The cure is mostly learning to recover.

Why do good models still go off the rails?

Training reports a low loss: given real text, the model predicts each next token well. Yet a long generated answer can drift, contradict itself, or build a whole page on one early slip. Training and generation run the same network on the same task. So what differs between them, and why can one bad token damage everything after it?

Trained on truth, run on its own output

In training (teacher forcing), every prefix is real text. If the model mispredicts position 50, the prediction at position 51 still sees the true token, so its mistakes never enter its own input. In generation, the prefix *is* its output, and a slip stays in the context for good. It rarely saw text containing its own errors, so it often continues them as if correct. This mismatch is **exposure bias**.

Two different kinds of prefix

Training minimizes $\mathcal L=-\frac{1}{T-1}\sum_{t=1}^{T-1}\log p_\theta(x_{t+1}\mid x_{\le t})$, where every prefix $x_{\le t}$ is real text. Generation draws $\hat x_{t+1}\sim p_\theta(\cdot\mid\hat x_{\le t})$, where the prefix is the model's own tokens. $\mathcal L$ never measures the model on its own prefixes. If each step derails with chance $\varepsilon$ and nothing recovers: $$P(\text{on track after }n)=(1-\varepsilon)^n\approx e^{-\varepsilon n}$$

99.8% per token, 14% per answer

Suppose a teacher-forced test shows a derailing token only 0.2% of the time, so $\varepsilon=0.002$. - $n=300$: $0.998^{300}\approx e^{-0.6}\approx 0.55$ - $n=1000$: $\approx e^{-2}\approx 0.14$ The real damage is worse than this count shows. After a slip, the prefix is unlike training text, so later predictions get less reliable: one slip invites more, and the answer keeps degrading. Even small, harmless oddities push a prefix away from real text and raise $\varepsilon$. That is the compounding.

Recovery is what saves long outputs

This simulates runs where each on-track token slips with chance ε. Once off track, a run gets back on with chance `recover` per token. The on-track share settles where leaving balances returning: ε·on = recover·off, so on = recover/(recover+ε) = 0.1/0.102 ≈ 98%. Without recovery it is about 55% at token 300. So the cure is mostly learning to recover, not only slipping less.
import numpy as np
rng = np.random.default_rng(0)
eps, n, trials = 0.002, 300, 100_000  # slip chance, length, runs
for recover in [0.0, 0.1]:            # chance per token to get back
    on = np.ones(trials, bool)        # is each run on track?
    for _ in range(n):
        u = rng.random(trials)
        on = np.where(on, u >= eps, u < recover)
    print(recover, on.mean())
# 0.0 -> ~0.55   0.1 -> ~0.98

Remember this

Training always conditions on true prefixes, while generation conditions on the model's own tokens. Each slip enters the context and makes later prefixes unlike anything seen in training. Without learned recovery, the chance of staying on track decays roughly like $e^{-\varepsilon n}$. With recovery, it settles near recover/(recover+ε).

On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.