- Year of appearance
- 2019
- Researchers
- Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, Peter J. Liu
- Organisation
- Architecture type
- Encoder–decoder Transformer
- Learning mechanism
- self-supervised
- Tasks
- Machine translation, Summarisation, Question answering, Text classification
A framework that turns all language tasks into a “text-to-text” format with a single encoder-decoder model, with a systematic study of pre-training choices.
Architecture diagram
Displayed configuration: T5-base: 12 + 12 layers, d = 768, d_ff = 3072, 12 heads — An encoder-decoder with relative position bias and RMS normalisation before every sub-layer.
Layer table (19 nodes)
| Layer | Type | Input | Output | Repetition | Parameters | Formula | MACs |
|---|---|---|---|---|---|---|---|
| Input text with the task prefix | input | 128 | 1 | 0 | — | ||
| Shared embedding 32,128 × 768 | embed | 128 | 128 × 768 | 1 | 24,674,304 | 32,128 · 768 | — |
| Relative position bias (encoder) | posenc | 128 | 128 × 12 | 1 | 384 | From the reference PyTorch implementation | 0 |
| RMSNorm (without bias) | ln | 128 × 768 | 128 × 768 | 12 | 768 | From the reference PyTorch implementation | 0 |
| Self-attention | mha | 128 × 768 | 128 × 768 | 12 | 2,359,296 | From the reference PyTorch implementation | 327,155,712 |
| RMSNorm | ln | 128 × 768 | 128 × 768 | 12 | 768 | From the reference PyTorch implementation | 0 |
| FFN 768←3072←768 (ReLU) | ffn | 128 × 768 | 128 × 768 | 12 | 4,718,592 | From the reference PyTorch implementation | 603,979,776 |
| Final encoder RMSNorm | ln | 128 × 768 | 128 × 768 | 1 | 768 | From the reference PyTorch implementation | 0 |
| Target text (shifted) | input | 128 | 1 | 0 | — | ||
| Relative position bias (decoder) | posenc | 128 | 128 × 12 | 1 | 384 | From the reference PyTorch implementation | 0 |
| RMSNorm | ln | 128 × 768 | 128 × 768 | 12 | 768 | From the reference PyTorch implementation | 0 |
| Masked self-attention | masked_mha | 128 × 768 | 128 × 768 | 12 | 2,359,296 | From the reference PyTorch implementation | 327,155,712 |
| RMSNorm | ln | 128 × 768 | 128 × 768 | 12 | 768 | From the reference PyTorch implementation | 0 |
| Cross-attention | cross_attention | 128 × 768 | 128 × 768 | 12 | 2,359,296 | From the reference PyTorch implementation | 327,155,712 |
| RMSNorm | ln | 128 × 768 | 128 × 768 | 12 | 768 | From the reference PyTorch implementation | 0 |
| FFN 768←3072←768 | ffn | 128 × 768 | 128 × 768 | 12 | 4,718,592 | From the reference PyTorch implementation | 603,979,776 |
| Final decoder RMSNorm | ln | 128 × 768 | 128 × 768 | 1 | 768 | From the reference PyTorch implementation | 0 |
| Projection to the vocabulary (tied) | fc | 128 × 768 | 128 × 32128 | 1 | 0 | Tied to the shared embedding | 3,158,310,912 |
| Output text | output | 128 × 32128 | 128 | 1 | 0 | — |
Configuration figures: T5-base: 12 + 12 layers, d = 768, d_ff = 3072, 12 heads
- Input shape
- n SentencePiece tokens
- Output shape
- n × 32128
- Depth
- 12 encoder layers + 12 decoder layers
- Complexity
- O(L·(n²d + nd²)) for each of the encoder and the decoder.
- Parameters note
- The paper: about 220 million parameters for the Base model.
- MACs note
- For a source and target of length n = 128.
MAC = a multiplication followed by an addition. The figures are for one forward pass of one sample with the stated dimensions; they are an analytical calculation, not a measurement of run time.
Scientific explanation
Historical background
Published on arXiv in October 2019 and then in JMLR in 2020, with the C4 dataset (about 750GB of cleaned web text), and sizes from Small up to 11B.
The problem it addresses
The variety of task formats and architectures makes systematic comparison of transfer learning methods difficult.
Core idea
Every task is text-to-text with a prefix describing the task, and pre-training uses span corruption.
Architecture description
An encoder-decoder close to the original Transformer, with pre-layer normalisation without bias, a shared relative position bias, and a SentencePiece vocabulary of 32 thousand.
Data flow
“summarize: …” → encoder → the decoder generates the target text token by token.
Inputs
Text with a prefix that specifies the task (such as translate English to German: or summarize:).
Outputs
Text generated token by token: the translation, the summary or the answer; even the class name in classification tasks is written as text.
Training procedure
Pre-training on C4 for 2¹⁹ steps with batches of 2¹¹ × 512 tokens and AdaFactor, then multi-task or per-task fine-tuning.
Loss functions
Cross-entropy on the target tokens (the corrupted spans during pre-training).
Computational complexity
O(L·(n²d + nd²)).
Computational requirements
The 11B version was trained on TPU v3 chips.
Advantages
- A unified format for all tasks
- A broad systematic study
- Models available in several sizes
Limitations
- Huge training cost for the large versions
- Sequential generation in the decoder
- Task prefixes are textual and can be fragile
Equations
Span corruption objective Span corruption objective
\mathcal{L} = -\sum_{t} \log p\left(y_t \mid y_{\lt t}, \tilde{\mathbf{x}}\right)The dropped spans are replaced with sentinel tokens and only the dropped parts are generated.
Symbols: x̃: the input with sentinel tokens
Relative position bias Relative position bias
A_{ij} = \frac{\mathbf{q}_i^\top \mathbf{k}_j}{1} + b_{\text{bucket}(j - i)}A learned bias for each head according to the relative-distance bucket (without dividing by √d in T5).
Symbols: 32 logarithmic buckets
RMS normalisation RMS layer norm
\operatorname{RMSNorm}(\mathbf{x}) = \gamma \odot \frac{\mathbf{x}}{\sqrt{\tfrac{1}{d}\sum_i x_i^2 + \epsilon}}Normalisation without subtracting the mean and without bias.
Scaled dot-product attention Scaled dot-product attention
\operatorname{Attention}(Q, K, V) = \operatorname{softmax}\!\left(\frac{QK^\top}{\sqrt{d_k}}\right) VEach query takes a weighted average of the values according to its similarity with the keys.
Symbols: Q, K, V: queries, keys and values, d_k: key dimension
Applications
Related models
- Built on Transformer — A Transformer encoder-decoder. Compare
- BERT (Bidirectional Encoder Representations from Transformers) — Pre-training with corruption similar to MLM. Compare
- Sequence to Sequence (Seq2Seq) — A sequence-to-sequence framework. Compare
References
- Original paper Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, Peter J. Liu. (2020). Exploring the limits of transfer learning with a unified text-to-text transformer. Journal of Machine Learning Research, 21(140), 1–67. arXiv:1910.10683 Verified
Version 1 — last updated 2026-11-15.
