Visual walkthrough — T5 and text-to-text framework
Step 1 — A sentence is a list of numbered slots
WHAT. Before any maths, we need to agree what "text" even is to a computer. A piece of text is chopped into small pieces called tokens (roughly: word-chunks). We line them up and number them left to right.
WHY. Everything T5 does is "read a string, write a string." If we cannot describe a string precisely, we cannot describe the model. So the very first tool we introduce is just indexing — giving each slot a position number so we can talk about "the 3rd token."
PICTURE. In the figure, the input string sits in the top row of boxes labelled (the amber row). The output string sits below as (the cyan row).

Notice and can differ — the input "translate English to German: dog" is long, the output "Hund" is short. That is fine; strings have no fixed length.
Step 2 — Every task becomes the same pair of rows
WHAT. We take four totally different jobs — translation, grammar-checking, similarity-scoring, summarising — and write each one as a top row (input) and a bottom row (target).
WHY. This is the whole idea of T5, and we want to see it before we prove anything. If all four jobs look identical on paper (two rows of boxes), then whatever formula scores one row can score them all.
PICTURE. Four stacked pairs of rows. On the left, the top row always starts with a task prefix (highlighted amber) telling the model which job it is. On the right, the bottom row is the answer — and crucially, even the number 3.8 and the label positive are just boxes of tokens, no different in shape from Hund.

The key visual takeaway: the target row is always just text. The label "positive" is tokens. The number "3.8" is tokens 3, ., 8. So if we can score "how good is a predicted target row," we have scored every task at once.
Step 3 — Reading a string one box at a time (the chain rule)
WHAT. We want a single number: how likely is this exact target row , given the input row ? Call it (read: "probability of given "). We build it by predicting one box at a time, left to right.
WHY THIS TOOL. Why not predict the whole sentence in one shot? Because the number of possible sentences is astronomically large — you could never list them. Instead we use the chain rule of probability, a fact that is always exactly true, with no independence assumption whatsoever: the joint probability of a sequence equals the product of "each next box, given all the boxes before it." The conditioning on earlier tokens is precisely what lets the factors capture dependence between tokens. This turns one impossible question ("which of infinitely many sentences?") into small, answerable questions ("which single token comes next?").
PICTURE. The decoder is drawn as a machine that, at each step , looks at (a) the full input row via cross-attention (the long cyan arrows going up to the encoder), and (b) the target boxes it has already committed to, (the short cyan arrows). It then outputs a probability for the next box .

Each factor is produced by one softmax over the vocabulary — a recipe that turns raw scores into probabilities.
Step 4 — Turning "probability of the row" into a loss
WHAT. We now convert (bigger = better) into a loss (smaller = better) that training can push downhill.
WHY LOG, WHY MINUS. Two problems with the raw product from Step 3:
- Multiplying numbers each below 1 gives a tiny value (e.g. ) — the computer underflows to zero. The fix is the logarithm, because turns the fragile product into a robust sum.
- Probabilities live in , so their log is (negative). We want a loss we minimise (a positive "badness"), so we flip the sign with a minus.
Maximising is exactly the same as minimising — is increasing, so it preserves the ranking; the minus just flips "up is good" into "down is good."
PICTURE. Left panel: the raw product shrinking to a near-zero sliver. Right panel: after , each token contributes a positive bar you add up; a confident-and-correct token gives a short bar (small loss), a surprised token gives a tall bar (big loss).

Step 5 — Teacher forcing: why we feed the true previous tokens
WHAT. During training, at slot the decoder needs to see . We feed it the ground-truth previous tokens, not the model's own guesses. This is called teacher forcing.
WHY. If early in training the model guessed slot 1 wrong, and we fed that wrong guess into slot 2, the error would snowball and no slot would ever get a clean learning signal. By feeding the true prefix, every slot is judged fairly ("given the correct history, did you predict the next token?"). It also lets us compute all factors in parallel — we already know the whole target row, so we can score every slot at once.
PICTURE. Two lanes. Top lane "teacher forcing (training)": the true target row is shifted right by one and fed back in as the decoder's input; green check-arrows show each slot getting the real history. Bottom lane "free-running (inference)": the model's own output is fed back — one wrong box can drift the rest. The contrast is the point.

Step 6 — The collapse: one loss, every task
WHAT. Now we cash in. We drop three different jobs into the exact same loss from Step 4 and watch nothing change.
WHY. This is the parent note's central result — "why can one loss train all tasks?" We prove it by substitution: since every target is a string of tokens (Step 2), and only cares about "the tokens of " (Step 4), the machinery is identical regardless of what the string means.
PICTURE. Three funnels — a translation target Hund, a classification target positive, a regression target 3.8 — all pouring into one shared box labelled . No per-task head, no per-task loss. One pipe out.

Step 7 — Edge & degenerate cases (the ones that could bite you)
WHAT. We check the corners the smooth story skipped: a one-token target, the empty target, an off-vocabulary answer, and the pretraining (span-corruption) case.
WHY. The contract: the reader must never meet a scenario we did not show. Losses and formulas have to survive , a zero-length target, weird outputs, and the training-time span-corruption objective.
PICTURE. Four small panels, each a mini row-pair with a note on what the loss does.

The one-picture summary
Everything above, on one page: the input row flows into the bidirectional encoder; the decoder emits target boxes one at a time, each box's probability read off a softmax, each box's surprise stacked into a bar; the bars sum to ; and three example targets (word, label, number) all feed the same .

Recall Feynman retelling — the whole walkthrough in plain words
Imagine a fill-in-the-blank machine. You slide in a strip of word-boxes (the input), and it writes back word-boxes one at a time (the answer). Every time it's about to write a box, it makes a bet: "I think the next word is X, and I'm this-percent sure" — and the way it turns its gut scores into percentages that add to 100 is called softmax (it sums over every word in its whole vocabulary). If the real word matches its bet and it was confident, that's a tiny "oops" score; if the real word blindsides it, that's a huge "oops." We add up all the oops-scores across the answer — that total is the loss (for one example this is the negative log-likelihood; averaged over all your data it's the cross-entropy). The bets chain together honestly: each guess is allowed to see everything written before it, so we never pretend the words are unrelated. And here's the magic: it doesn't matter whether the answer is a German word, the label "positive", or the number "3.8" spelled out — they're all just word-boxes chopped into pieces the machine already knows, so the same oops-adding rule trains every job. Even the warm-up game — blank-the-spans, where we erase a few words, tag the gaps with pointers, and have it write the missing pieces back — is scored by that very same rule. During practice we always show it the true previous words (so one early slip can't ruin the rest), and every answer ends in a stop-mark so there's always at least one box to score. One machine, one scoring rule, a hundred jobs.
Active Recall
Does the chain-rule product assume independent tokens?
Why on the product?
Write the softmax formula.
Why is always?
</s> token, so even an empty answer is the one-token row </s>; the loss sum always has at least one term.Is cross-entropy or NLL?
Why is there no out-of-vocabulary target in T5?
How does span-corruption pretraining reuse the loss?
Connections
- Cross-entropy loss — the loss we built in Step 4.
- Transformer encoder-decoder architecture — the encoder/decoder machine drawn in Step 3.
- Multi-task learning with prefixes — why the amber prefix in Step 2 lets one model do many jobs.