The elegant idea: everything is text-to-text
Imagine a single model that solves all these tasks:
- Sentiment: read "Excellent movie!" and generate "positive"
- Translation: read "Hello" and generate "Bonjour"
- Summarization: read a 1,000-word article and generate 3 lines
- Sentence similarity: read "Sentence A" and "Sentence B" and generate "0.95" (a numerical score, as text)
- Extraction: read "Pierre lives in Paris" and generate "Pierre | Paris"
Same architecture. Same training process. Zero task-specific component.
T5 (Text-to-Text Transfer Transformer, Google, 2020) poses this simple idea: every language task is a transformation of text into text. Classification? The model generates the label as a word. Translation? It generates the translation. Summarization? It generates the summary. Everything fits the same mold.
Before T5, each NLP (Natural Language Processing) task needed a specialized "head" bolted on top of the model: a classification layer for sentiment, a sequence layer for translation, a span-tagging layer for extraction. T5 removes all those heads and replaces them with a single decoder that emits text. Radically simple.
Exploring the Limits of Transfer Learning with a Unified Text-to-Text TransformerHow it works in practice
The key: a text prefix that indicates the task to perform, followed by the input text. The model reads everything and generates the answer:
| Input | Output |
|---|---|
sentiment: Excellent movie! | positive |
translate English to French: Hello | Bonjour |
summarize: [1,000-word article] | [3-line summary] |
stsb: Sentence A ||| Sentence B | 3.8 (similarity on 0-5 scale) |
The stsb prefix refers to STS-B (Semantic Textual Similarity Benchmark), a sentence-similarity dataset in which human annotators score each pair from 0 (unrelated) to 5 (same meaning). It is one of the nine tasks in GLUE (General Language Understanding Evaluation), the leaderboard that served as the reference at the time.
The task is encoded in the text, not in the architecture. No switch, no special mode, no dedicated layer. Just a different prefix. That uniformity is T5's real strength.

- A single model to train, deploy, and maintain, instead of one architecture per task.
- Natural multi-task learning: tasks are mixed during training, and the model learns to recognize which one is being asked.
- Flexibility: adding a task means inventing a new prefix, with no change to the architecture.
- Transfer: the tasks reinforce each other, which improves each of them.
Architecture: the encoder-decoder
T5 reuses the complete encoder-decoder architecture of the original Transformer (the one from Attention Is All You Need, explained in encoder and decoder), unlike BERT (encoder-only) or GPT (decoder-only):
- Encoder: reads the input text with bidirectional attention (each word sees all others). It "understands" the full context and produces a rich representation.
- Decoder: generates the output token by token with causal attention (each word sees only the previous ones), plus cross-attention to the encoder. It "speaks" while continually consulting the encoder's understanding.
A natural division of labor:
- BERT (encoder-only): excellent at understanding, unable to generate text.
- GPT (decoder-only): excellent at generating, but handles input and output in one stream, with no separate comprehension step.
- T5 (encoder-decoder): comprehension by the encoder, generation by the decoder.
The variants
The authors released five sizes. The parameter counts are those announced when the models were published:
| Variant | Parameters | Typical usage |
|---|---|---|
| T5-Small | 60M | Quick prototyping, modest hardware |
| T5-Base | 220M | Good performance / cost balance |
| T5-Large | 770M | Markedly better, one professional graphics card |
| T5-3B | 3 billion | Several cards required |
| T5-11B | 11 billion | The strongest of the set |
Relative positions: the technical trick
BERT and GPT use absolute position vectors: each position (0, 1, 2, 3...) has its own learned vector. The problem: if the model is trained on 512-token sequences, it has never seen position 513 and does not know what to do with it.
T5 uses relative positions: instead of encoding "I am at position 42", each attention head learns how to treat "the word one slot from me" versus "the word five slots from me". What counts is the gap between two words, not their absolute place in the sequence. The positional encoding lesson covers both families.
The concrete advantage: T5 can generalize to longer sequences than those seen during training. BERT trained on 512 tokens struggles if you give it 1,000. T5 handles this much better, because relative distances stay the same regardless of total length.

For structured transformation tasks (translation, summarization, extraction), encoder-decoder was the more economical choice: the encoder condenses the input into a dense representation, the decoder unrolls it into output. Rather like a compiler, which parses first and emits second.
For universal flexibility (conversation, free generation, reasoning), decoder-only wins. That is why conversational large language models (LLMs) are all built on a decoder-only stack, and why encoder-decoder shrank to a specialist role before being largely displaced there too.
Technical corner: training by span corruption
BERT masks individual tokens, one word at a time: that is MLM, masked language modeling. T5 innovates by masking entire spans, runs of consecutive words:
| Step | Text |
|---|---|
| Original | "The black cat sleeps on the couch" |
| Masked spans | "The <extra_id_0> sleeps on <extra_id_1>" |
| Target to generate | "<extra_id_0> black cat <extra_id_1> the couch" |
Each <extra_id_0>, <extra_id_1> is a unique special token (a sentinel) marking the location of a masked span. The model must reconstruct what is missing.

Why spans instead of individual tokens?
-
Shorter target, so faster training: replacing three consecutive words with a single sentinel shortens the input sequence, and the model only has to emit the missing words rather than reproduce the whole text. The paper puts it this way: replacing an entire span with a single token yields shorter sequences to process.
-
Semantic coherence: masking "black cat", a group that means something together, forces the model to reason about groups of words rather than isolated ones.
-
Closer to generation: T5 is built to generate text. Reconstructing a multi-word span, one word after another, resembles the real task far more than guessing a single word.
The C4 corpus
T5 trains on C4, the Colossal Clean Crawled Corpus. The paper gives both the recipe and the numbers. Common Crawl, the public web archive, produces roughly 20 TB of text per month. After filtering (keep English only, require terminal punctuation, drop pages that are too short, remove offensive content by word list, deduplicate) about 750 GB remain. A reduction factor of roughly 25.
T5's reasoning: 750 GB of carefully cleaned web text beats the raw 20 TB, which is saturated with duplicates, navigation menus and machine-generated filler. That lesson (data quality matters at least as much as quantity) has been confirmed repeatedly since, notably by Chinchilla and by work on pre-training datasets.
C4 became a standard building block: several later open models, the LLaMA family among them, include a share of it in their data mix. Not to be confused with GPT-3, published the same year, which built its own Common Crawl filtering and does not use C4.
The real contribution: systematic ablations
The T5 paper is important, but not primarily for the T5 model itself. Its true value is in the systematic research it conducts.
The authors methodically test dozens of training decisions, one by one, isolating each variable:
| Decision | Options tested |
|---|---|
| Architecture | Encoder-decoder, decoder-only, prefix LM, a decoder-only stack whose opening segment is read bidirectionally; LM stands for language model |
| Pre-training objective | BERT-style MLM, span corruption, denoising |
| Mean span length | 2, 3, 5 and 10 tokens |
| Pre-training data volume | several subsets of C4, of decreasing size |
For each variable, they measure the effect on performance. This isn't "look at our idea", it's "here is the measurable effect of each design choice." Two main results: for transformation tasks, encoder-decoder beats decoder-only; and span corruption beats masking isolated tokens.
The lesson: scientific ablation
This methodical approach became the standard in serious language research. Rather than presenting a model as a block and asserting it is better, you decompose each decision and measure its isolated effect. It revealed that many "innovations" are really better data or better settings, not new architectures.
FLAN-T5: instruction tuning
FLAN-T5 (Google, 2022) pushes T5 further. FLAN stands for Finetuned Language Net. You start from T5 and fine-tune it on hundreds of different tasks, but phrased as natural instructions rather than technical prefixes:
Classic T5 input:
sentiment: Excellent!FLAN-T5 input: "Determine the sentiment of the following text. Reply with 'positive' or 'negative'. Text: Excellent restaurant!"
Output: "positive"
FLAN-T5 saw hundreds of different instructions during training: translation, summarization, question answering, classification, extraction, logical reasoning.
The result: FLAN-T5 generalizes well in zero-shot. You give it a task never seen during training, phrased as an ordinary instruction, and it usually understands. As if the model had learned the general shape of "following a directive", beyond the specific tasks it met.
Two ways to adapt a model to new tasks:
Instruction tuning (as in FLAN-T5): fine-tune the model on a large number of varied instructions. Expensive at training time, but the resulting model is robust and no longer needs examples in the prompt.
In-context learning (in-context learning): no fine-tuning; the examples go straight into the prompt. Immediate adaptation, but the examples consume context on every request.
The two have since merged into one practice: today's large instruction-tuned models are instruction-tuned and used in context. See fine-tuning overview.
Encoder-decoder or decoder-only: the strategic choice
Two philosophies, with distinct strengths.
T5 (encoder-decoder)
Strengths:
- Well suited to transforming text: translation, summarization, extraction.
- The encoder reads the whole input before the decoder starts producing.
- More constrained generation: the decoder knows precisely what it must emit.
Weaknesses:
- Two modules to train, hence harder to scale.
- Poorly suited to free dialogue.
GPT (decoder-only)
Strengths:
- Simple architecture: a single stack of layers, a direct flow.
- Scales readily, up to hundreds of billions of parameters.
- Handles classification, generation, summarization and dialogue in one mode.
Weaknesses:
- No separate comprehension step over the input.
- At equal size, less economical on heavily structured transformations.
What the industry settled on
From 2018 to 2022, encoder-decoder (T5) and encoder-only (BERT) competed seriously with decoder-only (GPT).
From 2022 on, decoder-only won, for two reasons: universal flexibility beat targeted efficiency (one model that does everything is more useful than a translation specialist) and scaling it proved technically simpler.
Why this matters
T5 makes three lasting contributions:
-
Conceptual unification: showing that every language task can be written as text transformed into text radically simplified system design. The idea carried straight into today's large models, where everything (a question, a document, a tool call) is presented as text.
-
Span corruption: demonstrating by measurement that masking runs of consecutive words beats masking isolated tokens changed pre-training practice.
-
Systematic ablation: the paper set a methodological standard, measure each decision separately, under controlled conditions.
FLAN-T5 adds a fourth lesson: instruction tuning yields good zero-shot behaviour without a prompt cluttered with examples.
Where T5 stands in July 2026
T5 and FLAN-T5 are no longer common choices for a new system. The tasks they excelled at (translation, summarization, structured extraction) are now handled by large instruction-tuned decoder-only models, small ones included, which outperform them without needing per-task fine-tuning. The value of this page is therefore historical and methodological first: this is the moment when "everything is text-to-text" was formulated and proven, and when systematic ablation became the norm. Both have survived far better than the model.
1. How does T5 tell the model which task to perform?
2. What sets T5's span corruption apart from BERT's masking?
3. What data choice did the T5 authors make with the C4 corpus?
4. What is the most durable contribution of the T5 paper, beyond the model itself?