T5
14 memberslucid.models.text.t5T5 family — Raffel et al., 2020 (text-to-text encoder-decoder).
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.
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 from query to key:
with no scaling — the Mesh TensorFlow
initialisation folds it into the query projection. The bucket map
is exact for the nearest distances and
logarithmic beyond, saturating at relative_attention_max_distance
. For buckets per direction and ,
The encoder splits its 32 buckets between the two signs of (); the causal decoder uses all 32 for . One table per stack, computed once and shared by every layer.
Simplified layer norm. Every sub-layer reads — 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
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
T5Config1 methodsConfiguration for every T5 variant (Raffel et al., 2020, §3.7).
T5ForSeq2SeqLM5 methodsT5 with its language-modelling head — the model every T5 task trains.
T5Model6 methodsBare T5 encoder-decoder trunk.
T5ModelOutputOutput of the bare T5 trunk (no language-modelling head).
Functions
t5_3b→ T5Model2.9BT5-3B trunk — Large's depth and width, a wider inside.
t5_3b_seq2seq→ T5ForSeq2SeqLM2.9Bt5_3b with the tied text-to-text head.
t5_11b→ T5Model11.3BT5-11B trunk — the paper's largest model.
t5_11b_seq2seq→ T5ForSeq2SeqLM11.3Bt5_11b with the tied text-to-text head.
t5_base→ T5Model223MT5-Base trunk — the size every ablation of §3.1–§3.6 runs at.
t5_base_seq2seq→ T5ForSeq2SeqLM223Mt5_base with the tied text-to-text head.
t5_large→ T5Model738MT5-Large trunk — BERT-Large on each side.
t5_large_seq2seq→ T5ForSeq2SeqLM738Mt5_large with the tied text-to-text head.
t5_small→ T5Model60.5MT5-Small trunk — the 60M model of the paper's scaling study.
t5_small_seq2seq→ T5ForSeq2SeqLM60.5Mt5_small with the tied text-to-text head.