TL;DR
T5 turns every language task into text in, text out. A question about translation, a sentiment label, or a summary all pass through one encoder-decoder Transformer with one loss function. The model is pre-trained on a large cleaned web corpus with a span-corruption objective, then fine-tuned. The paper is also a controlled study: under one fixed setup it compares architectures, pre-training objectives, data and scale, and its largest model, with 11 billion parameters, reaches state of the art on many benchmarks.
Where you'll see it: the standard reference for encoder-decoder pre-training and for text-to-text instruction tuning, including later instruction-tuned variants such as Flan-T5.
The problem
By 2019, transfer learning in NLP had split into camps. Encoder-only models such as BERT were used for classification. Decoder-only language models were used for generation. Encoder-decoder models were used for translation and summarisation. Each camp had its own output heads, input formats and pre-training data, and papers often changed several things at once. It was hard to say which choice caused which gain. Practitioners had no common frame, and no fair comparison under the same compute.
Key idea
Make every task a text-to-text problem. Translation becomes the input "translate English to German: That is good." and the target "Das ist gut." Classification outputs the label as a word, such as "entailment". Even a regression task like the similarity score in STS-B is written out as text. One model, one maximum-likelihood loss and one decoding procedure then cover all tasks.
Pre-training uses a fill-in-the-gaps exercise. Spans of the input are blanked out with markers, and the model must write the missing words after the same markers. Think of a cloze test where the answers are generated as one continuous passage rather than one blank at a time.
The method
The model
The model is an encoder-decoder Transformer that stays close to the original design. The encoder is a stack of blocks, each with self-attention and a small feedforward network. The decoder adds cross-attention to the encoder output. Layer normalization is applied to the input of each sub-block and only rescales the activations, with no additive bias. A residual connection wraps each sub-block, as described in Residual Connection.
Position is handled by a learned relative scheme. The offset between a query and a key selects one of 32 learned scalars, added to the attention logit. The offset ranges grow logarithmically in size up to 128, and every longer offset shares one scalar. The scalars are shared across layers but differ per attention head. This replaces the sinusoidal or learned absolute embeddings of the original Transformer. The vocabulary has 32,000 SentencePiece wordpieces, shared across English, German, French and Romanian for the translation tasks. Pre-training uses the AdaFactor optimizer with an inverse square root learning-rate schedule.
Background for this section: Transformer, Attention Mechanism, Positional Encoding, Encoder-Decoder Architecture and Subword Tokenization.
Span corruption
BERT-style objectives mask each corrupted token separately and ask the model to reconstruct the whole text. The paper's objective corrupts about 15 percent of the input and replaces each run of consecutive corrupted tokens with a single unique sentinel token. Take "Thank you for inviting me to your party last week." and drop the two spans "for inviting" and "last". The input and target become:
- Input: "Thank you
<X>me to your party<Y>week." - Target: "
<X>for inviting<Y>last<Z>"
The target contains only the dropped spans, plus the sentinels. This is shorter than reconstructing the whole sentence and cheaper to decode. Two variants are worth separating. The baseline in the paper's experiments chooses each token independently with probability 15 percent, so runs of consecutive corrupted tokens (which get one sentinel) are short and accidental. The span-corruption objective proper chooses contiguous spans on purpose. With a mean span length of 3 it slightly outperformed the independent version on most non-translation benchmarks (SuperGLUE 72.53 against 71.36) and produced shorter sequences, so the final T5 models use it. The idea is related to the per-token masking of Masked Language Modeling as used by BERT, but the targets are much shorter.
Data: C4
The authors built the Colossal Clean Crawled Corpus from the April 2019 Common Crawl snapshot, about 750 GB of English text after cleaning (the paper's text says "about 750 GB", while its Table 8 lists C4 as 745GB, so treat the size as roughly 750 GB). The cleaning rules are simple: keep only lines that end in terminal punctuation, drop pages with offensive words, code (a curly bracket) or boilerplate, remove duplicated three-sentence spans, and keep pages a language detector rates as English with probability at least 0.99. The rules are heuristic, and the paper tests them: removing the filtering makes performance worse on every task.
Training and fine-tuning
The baseline has 220 million parameters. It is pre-trained for steps with batch size 128 and sequence length 512. That is about billion tokens, a small fraction of C4. It is then fine-tuned on each task.
The paper compares fine-tuning strategies and finds that updating all parameters works best. Adapter layers and gradual unfreezing are cheaper but worse (SuperGLUE 60.40 to 64.30 for adapters and 70.79 for gradual unfreezing, against 71.36). It also tests multi-task training, where examples from several tasks are mixed in each batch. Mixing in proportion to dataset size, with a cap so that large datasets do not swamp the rest, is the reasonable default, but multi-task training on its own did worse than pre-train then fine-tune. Multi-task pre-training followed by per-task fine-tuning matched it (GLUE 83.11 against 83.28), and that is the recipe used for the final models.
Background: Fine-Tuning and Transfer Learning.
Results
Architecture and objective
Under a matched budget, the encoder-decoder with denoising pre-training is best on almost every task. The table below shows averages from the paper's architecture comparison.
| Architecture and objective | Parameters | GLUE | SuperGLUE |
|---|---|---|---|
| Encoder-decoder, denoising | 2P | 83.28 | 71.36 |
| Encoder-decoder, shared weights, denoising | P | 82.81 | 70.73 |
| Prefix LM, denoising | P | 81.82 | 68.11 |
| Decoder-only language model, denoising | P | 74.70 | 55.02 |
Here P is the parameter count of a BERT-base sized stack. Sharing weights between encoder and decoder halves the parameters with only a small loss. The language-model objective, predicting every token, does worse than denoising in every setting. Deshuffling objectives also underperform denoising.
Scale
Scaling helps. The released models are Small (about 60 million parameters), Base (the 220 million parameter baseline architecture), Large, 3B and 11B, and the final ones are pre-trained for about 1 trillion tokens rather than the baseline's 34 billion. Scores rise steadily with size. The largest model reaches a GLUE average of 90.3 and a SuperGLUE average of 88.9, up from 84.6 for the previous best. The paper reports state of the art on 18 of the 24 tasks it evaluates. In the baseline-scale study, ensembling four fine-tuned models is another way to spend extra compute and gives a gain over a single model (GLUE 84.77 against 83.28).
Data quality
Removing the heuristic filtering from C4 makes results worse on all tasks. Pre-training on a single domain (news, a WebText-like Reddit filter, Wikipedia plus books) can beat C4 on tasks from that domain, but those datasets are much smaller. Repeating a small dataset over the 34 billion token budget costs little at 64 repeats (GLUE 82.87 against 83.28) and 256 repeats (82.62), but hurts at 1,024 repeats (79.55) and 4,096 repeats (76.34). The paper suspects memorization, and for the 1 trillion token final runs it kept C4 for that reason.
Why it mattered
The paper made the text-to-text format the default way to frame a task for a pre-trained model. Its architecture and objective survived into later instruction-tuned models, and the systematic study became a reference for choices that had previously been decided by habit. C4 became a common pre-training corpus, and the paper's scaling results fed the wider interest in Neural Scaling Laws and Compute-Optimal Training.
The authors were explicit that they proposed no new method. Their contribution is the comparison itself, and that is also its limit. Each choice was tested one at a time against a fixed baseline, so interactions between choices, such as whether span corruption and the largest model combine as cleanly as the separate tests suggest, are only partly measured. The model is also large and expensive to fine-tune in full, which is why the paper's advice to update every parameter is costly in practice. Later work on parameter-efficient fine-tuning, such as Low-Rank Adaptation (LoRA), was in part a response to that cost.
Reading guide
Read the sections in this order, and keep these prerequisites close:
- Section 2.1 (the model): Transformer, Attention Mechanism, Layer Normalization, Residual Connection, Positional Encoding.
- Section 2.2 (C4) and Section 2.4 (input and output format): Subword Tokenization, Text-to-Text Framework.
- Section 3.1 (the baseline) and Section 3.3 (unsupervised objectives): Language Model, Masked Language Modeling, Cross-Entropy Loss.
- Section 3.2 (architectures): Encoder-Decoder Architecture, Language Model, BERT.
- Section 3.4 (data) and Section 3.5 (training and fine-tuning): Fine-Tuning, Transfer Learning.
- Section 3.6 (scaling): Neural Scaling Laws.
- Section 3.7 and Section 4 (putting it together and the takeaways) need nothing new.
Check yourself
QuestionRecall: what does a text-to-text model output for a classification task such as MNLI?Show answer
It outputs the label written as text, such as "entailment", "neutral" or "contradiction". The input carries the task name and both sentences as a single string, so the same decoder and loss handle classification, translation and summarisation.
QuestionComputation: the baseline uses pre-training steps, batch size 128 and sequence length 512. Roughly how many tokens does it see?Show answer
Each step processes tokens. Over steps that is tokens, which is about billion. The paper stresses that this is a small fraction of the full C4 corpus.
QuestionWhy: why is predicting only the dropped spans, with sentinels, cheaper than a BERT-style reconstruction of the whole text?Show answer
The BERT-style variants ask the decoder to reproduce the entire uncorrupted sequence, which means self-attention over a long target. Replacing each run of corrupted tokens with one sentinel and predicting only the dropped spans makes the target much shorter, so training is faster, and the paper finds quality is about the same. Corrupting contiguous spans on purpose shortens sequences a little further than independent corruption.
QuestionApplied: you need one checkpoint that can summarise, translate and classify, without a task-specific head for each. Which property of T5 lets you do this, and what is the cost?Show answer
The shared text-to-text format means one model, one loss and one decoding procedure cover all tasks, selected by a task prefix in the input. The cost is that each output is generated token by token, so a classification label takes several decoding steps where a dedicated classifier head would need one forward pass.