Skip to content
module

T5

14 members
lucid.models.text.t5

T5 family — Raffel et al., 2020 (text-to-text encoder-decoder).

Language Modeling
Paper

Raffel, Colin, et al. "Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer." Journal of Machine Learning Research, vol. 21, no. 140, 2020, pp. 1–67.

Overview

T5 casts every task — translation, summarisation, classification, regression — as text in, text out: a task prefix such as "summarize: " is prepended to the input and the answer is decoded as tokens, so one encoder-decoder, one loss and one decoding procedure serve them all.

Relative position bias. No position is added to the tokens. Each attention head instead adds a learned scalar to its logits, looked up by the bucketed distance j−ij - i from query to key:

Aij=qi⊤kj+bh, β(j−i),A_{ij} = q_i^{\top} k_j + b_{h,\,\beta(j - i)},

with no 1/dkv1/\sqrt{d_{kv}} scaling — the Mesh TensorFlow initialisation folds it into the query projection. The bucket map β\beta is exact for the mm nearest distances and logarithmic beyond, saturating at relative_attention_max_distance DD. For nn buckets per direction and m=n/2m = n/2,

β(r)={∣r∣∣r∣<m,min⁡ ⁣(n−1,  m+⌊log⁡(∣r∣/m)log⁡(D/m) (n−m)⌋)otherwise.\beta(r) = \begin{cases} |r| & |r| < m, \\ \min\!\Bigl(n - 1,\; m + \Bigl\lfloor \dfrac{\log(|r| / m)}{\log(D / m)}\,(n - m) \Bigr\rfloor\Bigr) & \text{otherwise.} \end{cases}

The encoder splits its 32 buckets between the two signs of rr (n=16n = 16); the causal decoder uses all 32 for r≤0r \le 0. One table per stack, computed once and shared by every layer.

Simplified layer norm. Every sub-layer reads x/RMS(x)⊙γx / \mathrm{RMS}(x) \odot \gamma — no mean subtraction, no bias — and adds its output back to the unnormalised stream (pre-norm residual), with a final norm closing each stack.

Objective. Pre-training corrupts 15% of the input tokens in spans of mean length 3, replaces each span with a unique sentinel and asks the decoder for the dropped spans, each after its sentinel. Every task then trains the same per-token cross-entropy

L=−∑tlog⁡pθ(yt∣x, y<t),\mathcal{L} = -\sum_{t} \log p_\theta(y_t \mid x,\, y_{<t}),

the decoder reading the target shifted right behind decoder_start_token_id. The paper's five sizes span 60M to 11B parameters; T5-11B set the state of the art on GLUE, SuperGLUE, SQuAD and CNN/Daily Mail at publication.

Classes

Functions