TL;DR
Most language tasks look different on the surface. Translation maps a sentence to a sentence, summarising maps a document to a shorter text, and classification maps a sentence to a label. The text-to-text framework treats all of them as one problem: the input is a string, the output is a string, and a single model learns the mapping between them.
Because every task shares the same input and output format, one model architecture, one training objective and one set of settings can be reused across tasks. A task is named by a short text prefix in the input, so switching tasks means changing the words you send rather than the network.
Where you'll see it: in the T5 family of models, in multi-task training mixes where one model answers many tasks, and in the instruction-following style of prompting that later large language models adopted.
Intuition
One interface for every task
Imagine a translation office where every request arrives on the same form. The form has a box for the request and a box for the answer, and the clerk never needs a different desk for each kind of job. The clerk reads the request, which says what job it is, and writes the answer in the second box. Adding a new kind of job means writing a new request format, not building a new desk.
Before this framework, most systems had a separate output layer for each task. A classifier had a head that produced a label distribution. A tagger had another. A regression model had a number output. Each head was trained from scratch for its task, so the knowledge from pretraining reached only the shared body of the network. The text-to-text idea removes the special heads. Every answer is generated token by token, the same way a language model writes text.
The flow looks like this. A short prefix in the input names the task, the encoder-decoder reads the whole input, and the decoder writes the output string.
flowchart LR A["translate English to German: That is good."] --> M[Encoder-decoder model] B["summarize: a long news article"] --> M C["sst2 sentence: a lovely film"] --> M M --> D["Das ist gut."] M --> E["a short summary"] M --> F["positive"]
Classification is no longer special. The label "positive" is just a short string, and the model learns to spell it out. The same is true for a score, which is written as digits.
The math
The objective
The decoder writes the target one token at a time, so the probability of the whole target factors into a product of next-token probabilities:
Here is the -th target token, is every target token before it, and is the target length. Training minimises the cross-entropy of the true target, which is the negative log-likelihood:
Every task uses this same loss, so mixing tasks in one training run needs no special handling beyond sampling the pairs.
Task prefixes
A prefix is a short string such as "translate English to German" or "summarize". The model input is the concatenation
so two tasks that share the same raw text but different prefixes ask for different outputs. The prefix is what lets one network know which job it is doing.
Denoising by span corruption
Text-to-text models are usually pretrained on a fill-in-the-blank task rather than a plain next-token task. The original T5 work corrupted about 15 percent of the input tokens, grouped into spans with an average length of about three. Each dropped span is replaced in the input by a unique placeholder marker, and the target lists the placeholder followed by the missing tokens. The encoder reads the corrupted text, and the decoder reconstructs the dropped spans. Only the target tokens enter the loss.
Worked examples
Start from the sentence "Thank you for inviting me to your party last week."
- Choose two spans to drop: "for inviting" and "last".
- Replace each span in the input with a placeholder, numbered X and Y for the first two. The input becomes
Thank you X me to your party Y week. - Write the target: the placeholder, the dropped tokens, then the next placeholder. The target is
X for inviting Y last Z, where Z marks the end. - Count the loss tokens. The target has 6 items for 2 dropped spans (3 dropped words and 3 placeholders), while the corrupted input has 9 items. The decoder predicts all 6 target items, but the target is still short because it holds only the dropped words and markers, not the whole sentence.
Interpretation: the model never sees the masked words, so it must use the words around each gap to fill them in. That is the same pressure that masked language modeling applies, now written as text in and text out.
Suppose the target is the two-token string "for inviting", and the model gives probability to "for" given the input, and to "inviting" given the input and "for".
- Apply the factorisation: .
- Take the negative log of each term: and .
- Add them: .
- Average over the two tokens for a per-token figure: .
If the model had given "for" only instead of , the first term alone would be . A confident wrong token costs far more than a weakly wrong one, which is why cross-entropy trains the decoder to commit to the right tokens.
A team needs answers for ten language tasks. Suppose a base-sized encoder-decoder has about 220 million parameters.
- With one fine-tuned model per task, the team stores parameters.
- With the text-to-text framework, one shared model is fine-tuned on all ten tasks with prefixes. The team stores parameters, a tenth of the first total.
- The cost is one set of weights to host and one training pipeline to maintain.
Interpretation: the saving is largest when tasks are small or many. The trade is that a shared model can be pulled toward one task at the expense of another, which the mixing schedule has to manage.
Tradeoffs and failure modes
The framework is convenient, but it moves some difficulty into the text itself.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Classification with many labels | Each label must be spelled and decoded, which is slower and can yield invalid strings | Constrain decoding to the label set, or use a classification head for speed |
| Numeric regression | Numbers are written as digits, so precision and rounding depend on the tokenizer | Use a regression head when fine-grained values matter |
| Tasks with very different lengths in one mix | Long inputs dominate the batch and skew the learning signal | Balance the mixture or cap lengths per task |
| Prefixes that look alike | The model confuses tasks whose prefixes differ by one word | Use distinct, descriptive prefixes and test each one |
| Output that drifts from the label set | The decoder may write a near-miss string such as a synonym | Use constrained or exact-match decoding and check outputs |
History
Colin Raffel and colleagues at Google published the framework in 2019 as the T5 model, short for Text-to-Text Transfer Transformer. The paper compared pretraining objectives, datasets and model sizes across a wide range of tasks, and then tested one encoder-decoder model on all of them as text. Their large clean web corpus, called C4, supplied the pretraining text. The models ranged from tens of millions of parameters up to about 11 billion.
The idea grew out of earlier work on fill-in-the-blank pretraining, especially masked language modeling in BERT, which appeared in 2018, and on transfer learning in which a single pretrained model is adapted to many tasks. T5 combined those threads and made the task interface uniform. Later instruction-tuned variants showed that a shared text interface also handles new tasks described in plain language. In the early 2020s most large chat models adopted the same principle in a decoder-only form, where the prompt carries the task.
Check yourself
QuestionWhy does the text-to-text framework use one loss for every task instead of a separate head per task?Show answer
A separate head maps the shared representation to a task-specific output, so each task needs its own trained parameters. When every answer is a string, the same decoder and the same cross-entropy loss apply to all tasks. Pretraining knowledge then flows through every part of the network, and adding a task only requires new text pairs and a prefix.
QuestionA target string has three tokens with probabilities , and under the model. Compute its loss and its per-token loss.Show answer
Compute each term: , , and . The sum is . Dividing by three gives a per-token loss of . The weakest token, at , contributes the most.
QuestionIn span corruption, why is only the target part of the loss, not the whole input?Show answer
The encoder's job is to build a representation of the corrupted input, and its outputs are not scored directly. The decoder is what writes the missing spans, so the loss is computed on its predictions for the target. Scoring the input would ask the model to reproduce text it was shown, which teaches nothing about filling gaps.
QuestionA team wants a single model that handles translation and sentiment labels. What is one risk of writing the sentiment label as a word, and how would you reduce it?Show answer
The decoder may produce a string that is close to a valid label but not one of the allowed labels, such as a synonym or a misspelling. To reduce it, constrain decoding so only the label strings can be generated, or check each output against the label set and treat anything else as an error.