3.5.13 · D1Sequence Models

Foundations — Teacher forcing

1,892 words9 min readBack to topic

Before you can understand that sentence fully, you need to know what a "token", a "sequence", a "probability of the next thing", a "product over time", and a "log-loss" actually are — as pictures, not just symbols. This page builds every one of them from zero, in the order the parent note secretly assumes them.


1. A token, and a sequence of tokens

Read the notation slowly:

  • — the whole list (the finished sentence "HELLO").
  • — the token sitting at position (the little subscript is just an address, like a house number on a street).
  • — the total length, the house number of the last token.

The picture: a row of boxes, left to right, each box holding one token. Position matters — "am I" and "I am" use the same tokens but are different sequences.

Figure — Teacher forcing

Why the topic needs it. Teacher forcing is entirely about what we put in each box's slot at training time. If you don't picture the row of boxes with numbered positions, none of the later equations mean anything.


2. "Given the past" — conditional probability

The model does not guess out of thin air. It guesses it given everything before it.

Two new pieces of notation, defined:

  • — shorthand for the slice , i.e. all tokens before position . The colon : means "from ... up to".
  • — a probability: a number between and saying "how likely". = never, = certain, = fairly likely.
Figure — Teacher forcing

Why "given" and not just ? Because language is context-dependent. After "HELL" the next letter is almost surely "O"; on its own, "O" is rare. The bar is what lets the model use the history, and teacher forcing is a fight over what history to condition on.


3. Ground truth vs. prediction — the hat "^"

The single most important distinction on the whole page:

The picture: two rows of boxes.

  • Top row — the answer key, filled in ink (ground truth ).
  • Bottom row — the model's attempt, filled in pencil (predictions ), which may have eraser marks where it went wrong.
Figure — Teacher forcing

Why the topic needs it. Teacher forcing is exactly the choice: when the model needs a "previous token" to condition on, do we hand it the ink row (, teacher forcing) or the pencil row (, free running)? Without the hat you cannot even state the question.


4. Autoregressive — the pencil feeds itself

The picture: an arrow that loops from the bottom-row box at position back up into the model to produce position . The pencil literally feeds itself.

Why it matters. Because of this self-feeding loop, a single wrong pencil mark at position becomes the input at position , which corrupts position , and so on — errors compound. Teacher forcing breaks the loop during training by feeding the ink row instead. See 4.2.3-Autoregressive-models for the general family.


5. The product over time — the ∏ symbol

To score a whole sentence, we multiply the per-position guesses:

New notation, defined:

  • — the big "pi" means multiply together, one factor for each from to . (It is to multiplication what is to addition.)
  • — the input / condition (e.g. the French sentence we're translating from). It sits inside every factor because every guess may depend on it.

Why the topic needs it. This product is the quantity we are trying to make large — a good model makes the true sentence highly probable. Teacher forcing is a recipe for how to compute each factor while training.


6. Turning products into sums — the log

Multiplying hundreds of tiny probabilities gives a ridiculously small number (like ), which computers round to zero. The fix is the logarithm.

Apply to the product and it becomes a sum:

Newly-earned symbols:

  • — "sigma", add up one term per position.
  • — the objective (script L), the number we want to steer.
  • — "theta", the bundle of all the model's tunable weights. Writing means "the probability as computed by the model with settings ."
Figure — Teacher forcing

Why the topic needs it. Every "Loss" column in the parent note's worked tables is one value. Understanding that curve — flat-and-tiny near , exploding near — is why a cascade of wrong tokens (small 's) makes the loss "explode" in the free-running example.


7. The teacher-forcing ratio — ε

  • — "is a member of"; — the closed range from to inclusive.
  • The picture: a dial from to . Turn it up for stable training, ease it down so the model learns to survive its own mistakes — that easing is 3.5.14-Scheduled-sampling, a cousin of 2.4.5-Curriculum-learning.

How the foundations feed the topic

Token and sequence y_t

Conditional p given past

Product over time

Log makes it a sum

Cross entropy loss

Ground truth vs prediction hat

Autoregressive self feeding

Teacher forcing choice

Epsilon mixing dial

Scheduled sampling and exposure bias

The left branch builds the objective (); the right branch builds the input-choice (ink vs pencil). Teacher forcing sits where they meet, and the exposure-bias gap (5.3.8-Exposure-bias) is what happens when the training input-choice differs from inference.


Equipment checklist

Cover the right side; can you answer each before revealing?

What does mean, and what does the subscript represent?
The token at position in the sequence; is just its position/address in the row of boxes.
What is the difference between and ?
is the ground-truth token from the answer key; (with the hat) is the model's own prediction, which may be wrong.
Read out loud: .
The probability of the token at position , given all tokens before it and the input .
What does the "" bar mean?
"Given" — everything to its right is known context the model conditions on.
Why do we take the product of per-step probabilities?
Chain rule of probability: the chance of the whole sequence is each token's chance given the ones before it, all multiplied.
Why apply to that product?
turns the tiny product into a sum (), avoiding underflow and giving cross-entropy loss.
Why is large when is small?
of a number near is a big negative, so its negation is large — a wrong, low-probability guess is heavily penalised.
What does "autoregressive" mean and why does it cause error cascades?
The model's own output feeds back as its next input; one wrong prediction corrupts every later step downstream.
What is and what do and mean?
The teacher-forcing ratio (chance of using ground truth); = pure teacher forcing, = pure free running.
What is in ?
The bundle of all the model's tunable weights/parameters.

When every line above is easy, you're ready for the full Teacher Forcing derivation and the 3.6.2-Seq2seq-architecture it lives inside.