Transformers Needs review

T5 (Text-to-Text Transfer Transformer)

T5

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
Google
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)
LayerTypeInputOutputRepetitionParametersFormulaMACs
Input text with the task prefixinput12810—
Shared embedding 32,128 × 768embed128128 × 768124,674,30432,128 · 768—
Relative position bias (encoder)posenc128128 × 121384From the reference PyTorch implementation0
RMSNorm (without bias)ln128 × 768128 × 76812768From the reference PyTorch implementation0
Self-attentionmha128 × 768128 × 768122,359,296From the reference PyTorch implementation327,155,712
RMSNormln128 × 768128 × 76812768From the reference PyTorch implementation0
FFN ‏768←3072←768 (ReLU)ffn128 × 768128 × 768124,718,592From the reference PyTorch implementation603,979,776
Final encoder RMSNormln128 × 768128 × 7681768From the reference PyTorch implementation0
Target text (shifted)input12810—
Relative position bias (decoder)posenc128128 × 121384From the reference PyTorch implementation0
RMSNormln128 × 768128 × 76812768From the reference PyTorch implementation0
Masked self-attentionmasked_mha128 × 768128 × 768122,359,296From the reference PyTorch implementation327,155,712
RMSNormln128 × 768128 × 76812768From the reference PyTorch implementation0
Cross-attentioncross_attention128 × 768128 × 768122,359,296From the reference PyTorch implementation327,155,712
RMSNormln128 × 768128 × 76812768From the reference PyTorch implementation0
FFN ‏768←3072←768ffn128 × 768128 × 768124,718,592From the reference PyTorch implementation603,979,776
Final decoder RMSNormln128 × 768128 × 7681768From the reference PyTorch implementation0
Projection to the vocabulary (tied)fc128 × 768128 × 3212810Tied to the shared embedding3,158,310,912
Output textoutput128 × 3212812810—

Configuration figures: T5-base: 12 + 12 layers, d = 768, d_ff = 3072, 12 heads

Parameters (computed from the layers)222,903,552 (≈222.9M)
Parameters (published in the source)220,000,000 (≈220M)
MACs29,431,431,168 (≈29.43B)
FLOPs ≈ 2 × MACs58,862,862,336 (≈58.86B)
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.
Calculation assumptions: T5Model from Hugging Face with the t5-base configuration (version 1.0 with a tied output).

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) V

Each 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

References

  1. 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
Scientific review note: A first scientific draft based on the original paper and reference implementations; it needs review by a specialist before final approval.

Version 1 — last updated 2026-11-15.