VerifiedarXiv:1910.1068332 min
LLMs · Transfer learning

T5: Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer

Every NLP task becomes the same task: text in, text out.

A Google team wrote translation, classification, question answering and summarization in one string-to-string format, used it to compare pre-training objectives, architectures and data sets one factor at a time, and then trained the winning recipe at up to 11 billion parameters.

Explaining the paperExploring the Limits of Transfer Learning with a Unified Text-to-Text TransformerRaffel, Shazeer, Roberts, Lee, Narang, Matena, Zhou, Li, Liu · Google · JMLR 2020 · arXiv:1910.10683 ↗

The authors propose no new method. They contribute a controlled comparison of training choices, a 750 GB cleaned web corpus called C4, and five models, the largest of which set the state of the art on 18 of the 24 tasks they measured.

By 2019 the standard recipe for language tasks was transfer learning: pre-train a large network on unlabeled text, then fine-tune it on a small labeled data set for the task you care about. BERT pre-trained an encoder by filling in masked words and attached a small classifier for each task. GPT-2 trained a decoder to predict the next word. XLNet, RoBERTa, UniLM, MASS and SpanBERT each changed the architecture, the pre-training objective, the corpus and the amount of training, usually several at once. When one of them beat the last, nobody could say which change had produced the gain.

The T5 paper sets out to answer that question by experiment. It fixes one baseline model and one training procedure, changes a single factor at a time (the architecture, the objective, the corpus, the multi-task mixture, the use of extra compute), and scores every variant on the same benchmarks. That only works if every task shares the same model, loss and decoding, so the paper first rewrites every task as text-to-text. At the end the best choices are combined and trained at five sizes, and those models are T5, the Text-to-Text Transfer Transformer.

The page follows the paper's order: the text-to-text format; the baseline Transformer and its three small changes; the comparison of attention masks; the pre-training objectives and the span-corruption objective T5 adopted; the C4 corpus; multi-task training; how to spend four times the compute; and the final models and where they fell short.

Every task is text in, text out

A sentiment classifier, a translator and a question-answering system normally have different output layers, different losses and different decoding procedures. T5 gives every task the same interface. The input is a string, the target is a string, and the model is trained to produce the target given the input.

A task prefix at the start of the input says which task is meant. The prefix is ordinary text, tokenized like the rest of the input, with no special machinery behind it. In training, every input that begins "translate English to German:" is paired with a German target, so the model learns that those words predict German output, the same way any context shapes what a language model writes next. The two examples at the top of the listing are verbatim from the paper; the rest follow the same format:

# every task is one (input string -> target string) pair
"translate English to German: That is good."   ->  "Das ist gut."
"mnli premise: I hate pigeons. hypothesis: My feelings towards pigeons
    are filled with animosity."                ->  "entailment"
# illustrative, same format:
"cola sentence: The professor talked us."       ->  "unacceptable"
"stsb sentence1: ... sentence2: ..."            ->  "3.8"
"summarize: <a news article>"                   ->  "<a short summary>"

For a classification task the target is the label written as a word. MNLI gives a premise and a hypothesis and asks whether the premise entails the hypothesis, contradicts it, or neither, so the target is one of entailment, contradiction or neutral. Regression needs one more step. STS-B scores the similarity of two sentences from 1 to 5; T5 rounds each score to the nearest 0.2, so a human rating of 3.84 becomes the four-character target 3.8. That leaves 21 possible strings (1.0, 1.2, and so on up to 5.0), which turns the regression into a 21-class problem. An output that is not a valid label or number is scored as wrong; the authors report they never saw one. The Winograd pronoun tasks are recast so the model writes out the noun that a starred pronoun refers to: for "The city councilmen refused the demonstrators a permit because *they* feared violence", the target is "The city councilmen".

Figure 1 · one model, every task
Pick a task. The teal prefix names the job and the input follows it; the same model emits the answer as plain text: a German sentence, a class label, a similarity number, or a summary. The translate and mnli examples are verbatim from the paper; the others are illustrative in the same format.

Because every target is a token sequence, one loss covers every task, in pre-training and in fine-tuning. For an input xx and a target y=(y1,…,yT)y = (y_1, \dots, y_T), the model is trained by maximum likelihood with teacher forcing: at step tt the decoder is fed the true previous target tokens, not its own guesses, and the loss adds up the cross-entropy of each true next token:

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

At test time the baseline decodes greedily, taking the most likely token at each step. For MNLI the target is one or two tokens, so "classification" is a single step of the same decoder that translates.

The obvious alternative is BERT's: share a pre-trained body and give each task its own output head and loss. Then a comparison of two pre-training objectives also compares whatever heads and losses were tuned for each. With one format, one loss and one decoder, the pre-training objective, architecture or corpus can change while everything around it stays fixed, and the rest of the paper uses that to run controlled comparisons.

The baseline Transformer

The model under the format is the encoder-decoder Transformer from Attention Is All You Need, kept close to its original form. The encoder reads the input tokens, and each position may look at every other position. The decoder writes the target one token at a time; it looks back at the target tokens produced so far and, through cross-attention, at the encoder's output. Both stacks are built from blocks of self-attention followed by a small feed-forward network. Self-attention replaces each position with a weighted average of the positions it may attend to:

yi=∑jwij xj,wij=softmaxj(qi⋅kj)y_i = \sum_j w_{ij}\, x_j, \qquad w_{ij} = \mathrm{softmax}_j\big(q_i \cdot k_j\big)
(2)

In (2), xjx_j is the vector for position jj (after a learned value projection), qiq_i and kjk_j are learned query and key projections, and wijw_{ij} is how much position ii takes from position jj. The softmax makes the weights non-negative and sum to one over jj. Each layer runs several of these heads in parallel on smaller projections and concatenates their outputs. Cross-attention is the same operation with the queries from the decoder and the keys and values from the encoder output. The original Transformer divides the logit by dkv\sqrt{d_{kv}} to keep its size independent of the head width; the T5 code applies no such factor and instead initializes the query projection with a standard deviation of (dmodeldkv)−1/2(d_{\text{model}} d_{kv})^{-1/2}, which has the same effect at the start of training.

The baseline makes each stack the size of BERT-Base: 12 blocks, a model width of dmodel=768d_{\text{model}} = 768 (the length of every token vector), 12 heads of width dkv=64d_{kv} = 64, and feed-forward layers of width dff=3072d_{\text{ff}} = 3072. With two stacks the model has about 220 million parameters, roughly twice BERT-Base. In shapes: a 512-token input becomes a 512×768512 \times 768 matrix; each head projects it to 512×64512 \times 64 queries and keys and forms a 512×512512 \times 512 matrix of logits, the scores that go into the softmax; the 12 heads' 512×64512 \times 64 outputs concatenate back to 512×768512 \times 768. The vocabulary is one SentencePiece model of 32,000 wordpieces (subword units, so a rare word splits into several pieces), trained on English C4 mixed 10 to 1 with each of German, French and Romanian so the same tokens cover the translation tasks.

T5 changes the original design in three places. The paper calls the changes orthogonal to its study and leaves ablating them to future work, so the comparisons below say nothing about whether they help.

The first change simplifies layer normalization. Standard layer norm subtracts each vector's mean, divides by its standard deviation, then multiplies by a learned gain γ\gamma and adds a learned bias. T5 keeps only the rescaling:

LN(x)=γ⊙x1d∑k=1dxk2+ϵ\mathrm{LN}(x) = \gamma \odot \frac{x}{\sqrt{\tfrac{1}{d}\sum_{k=1}^{d} x_k^2 + \epsilon}}
(3)

For x=(2,4,4,6)x = (2, 4, 4, 6), the mean of the squares is (4+16+16+36)/4=18(4 + 16 + 16 + 36)/4 = 18, so (3) divides by 18≈4.24\sqrt{18} \approx 4.24 and returns (0.47,0.94,0.94,1.41)(0.47, 0.94, 0.94, 1.41) before the gain. Standard layer norm would first subtract the mean 4 and return (−1.41,0,0,1.41)(-1.41, 0, 0, 1.41). Both outputs have a root-mean-square of 1, which bounds the scale of what enters the next layer; only standard layer norm also removes the offset. The paper describes the change as rescaling only, with no additive bias; the missing mean subtraction is visible in the code. The same operation appeared a week earlier, in October 2019, under the name RMSNorm, in an independent paper that T5 does not cite, and LLaMA and many later models use it.

The second change moves the normalization to the input of each sublayer. Each attention or feed-forward sublayer FF computes

x  ←  x+F(LN(x))x \;\leftarrow\; x + F\big(\mathrm{LN}(x)\big)
(4)

so the residual path from block to block carries xx without passing through any normalization. The original Transformer normalized after the addition, LN(x+F(x))\mathrm{LN}(x + F(x)). This "pre-norm" placement became common in later models; T5 itself gives no reason for it and does not test it.

The third change replaces absolute position embeddings with a relative position bias. Self-attention on its own treats its input as an unordered set, so the model needs some position signal. T5 adds one learned scalar to each attention logit, chosen by the offset between query and key:

wij=softmaxj(qi⋅kj+bh[ bucket(i−j) ])w_{ij} = \mathrm{softmax}_j\big(q_i \cdot k_j + b_h[\,\mathrm{bucket}(i - j)\,]\big)
(5)

Offsets are sorted into 32 buckets, 16 for each sign of i−ji - j. Within a sign, offsets 0 through 7 get a bucket each; after that the bands widen logarithmically (8–11, 12–15, 16–22, 23–31, 32–45, 46–63, 64–90), and a final bucket takes every offset of 91 or more. The paper describes the log ranges as reaching 128; rounding down in the code starts the last bucket at 91, and offsets from 91 to 128 and beyond all share its scalar. Each head hh has its own 32 scalars, and the same table is used by every layer, so the baseline encoder's position scheme has 32×12=38432 \times 12 = 384 numbers in total. A single layer cannot tell an offset of 100 from one of 400, but stacked layers can combine nearby offsets into longer ones. This is a reduced form of the learned relative embeddings of Shaw et al., which added a learned vector per offset instead of a scalar.

Drag the offset below and read off its bucket. An offset of 5 gets a bucket to itself, 90 shares a band 27 offsets wide, and everything from 91 up lands in the last one.

Figure 2 · 32 buckets for every offset
5 → b5
Band boundaries come from T5's bucketing function (relative_position_bucket, num_buckets=32, max_distance=128). Offsets 0 through 7 each own a bucket, the bands then widen, and one terminal bucket catches every offset from 91 out. The positive half of i−ji-j is shown; the negative half mirrors it with its own 16 buckets. The bias values are illustrative, not trained.

The baseline is pre-trained for 219=524,2882^{19} = 524{,}288 steps on batches of 128 sequences of 512 tokens, about 216=65,5362^{16} = 65{,}536 tokens per batch, which comes to 235≈342^{35} \approx 34 billion tokens. That is about a quarter of BERT's pre-training, and small enough that the baseline never sees any C4 text twice. The optimizer is AdaFactor, a memory-saving relative of Adam, with a learning rate of 0.01 for the first 10410^4 steps that then falls as 1/n1/\sqrt{n} in the step number nn. Fine-tuning runs 2182^{18} more steps at a constant 0.001.

Every experiment reports the same benchmarks. GLUE averages nine English understanding tasks (grammaticality, sentiment, paraphrase, entailment and others) into one score; SuperGLUE is a harder eight-task successor built to stay difficult for pre-trained models; SQuAD is reading comprehension scored by exact match with a reference answer; CNN/Daily Mail is news summarization scored by ROUGE-2 (word-pair overlap with a reference summary); and three WMT translation tasks, English to German, French and Romanian, are scored by BLEU (n-gram overlap with reference translations). The baseline scores 83.28 on GLUE and 71.36 on SuperGLUE, and those two numbers recur below as the reference point. The same network fine-tuned with no pre-training scores 66.22 and 53.04.

Three attention masks

The text-to-text format does not require an encoder and a decoder. A single decoder-only stack, the shape of GPT-2, can do it too: glue the input and target into one sequence and train on next-token prediction. The paper gives the translation example as the single sequence "translate English to German: That is good. target: Das ist gut." To predict, the model is fed everything up to "target:" and generates the rest. The architectures differ mainly in their attention mask, the rule for which positions may attend to which.

A mask sets some weights wijw_{ij} in (2) to zero. A fully visible mask zeroes none, so every position sees every other; the encoder uses it. A causal mask zeroes wijw_{ij} for every j>ij > i, so position ii sees only itself and earlier positions; the decoder uses it so that training cannot peek at the tokens it must predict. A causal mask with a prefix is fully visible over the first part of the sequence and causal after it.

The three masks give three architectures. The encoder-decoder has a fully visible encoder and a causal decoder joined by cross-attention. The language model is one causal stack over input plus target. The prefix LM is one stack whose mask is fully visible over the input and causal over the target. In the figure, look at the input block in the upper left. The language model's is a triangle, so the vector for the third input word is built without the fourth and fifth, even though all of the input is known before any output is written; the other two fill the block.

Figure 3 · the mask makes the model
Who can attend to whom, over five input tokens followed by four target tokens. Switch architectures to compare the input block: a triangle for the plain language model, a full square for the other two. All three cost the same compute MM; only the encoder-decoder has 2P2P parameters. GLUE scores are from the paper's Table 2, denoising objective.

Comparing the architectures fairly needs a common budget, and the paper notes that an encoder-decoder and a single stack cannot be matched on parameters and compute at the same time. Let PP be the parameters of one BERT-Base-sized stack of L=12L = 12 layers, about 110 million. An encoder-decoder with LL layers in each stack has about 2P2P, the same as a 24-layer language model. Its compute per example, though, matches a 12-layer language model, because each token passes through only one of its stacks: input tokens through the encoder, target tokens through the decoder.

A forward pass costs roughly 2 FLOPs per parameter per token it passes through (a common rule of thumb that ignores the attention terms that grow with sequence length). Take an example with 400 input tokens and 100 target tokens. The encoder-decoder costs about 400×2×P+100×2×P=1000P400 \times 2 \times P + 100 \times 2 \times P = 1000P, about 1.1×10111.1 \times 10^{11} FLOPs. A 12-layer language model runs all 500 tokens through its PP parameters: also 1000P1000P. A 24-layer language model with 2P2P parameters runs all 500 tokens through all of them: 2000P2000P. The paper calls this common cost MM and confirms it empirically: the step times of LL-layer language models and L+LL+L encoder-decoders were nearly identical. Cross-attention adds about 10% to the encoder-decoder's parameters, which the paper's 2P2P ignores.

With the denoising objective (Table 2), the encoder-decoder (2P2P, MM) scored 83.28 on GLUE and was the best configuration on every benchmark. Sharing weights between its encoder and decoder (PP, MM) cost little, 82.81. Halving each stack to 6 layers (PP, M/2M/2) cost more, 80.88. The prefix LM (PP, MM) scored 81.82 and the plain language model 74.70. The shared encoder-decoder and the prefix LM have the same parameters and compute, so the paper reads the 1-point gap between them as a benefit of explicit cross-attention. The prefix LM's 7-point lead over the language model comes from the one difference in their masks, the visibility of the input.

The same table repeats every architecture with a plain language-modeling objective. On GLUE, denoising beat it in every architecture: 83.28 against 79.56 for the encoder-decoder, 81.82 against 79.68 for the prefix LM, 74.70 against 73.78 for the language model. Per benchmark there are exceptions, such as the language model scoring 56.51 on SuperGLUE with its own objective and 55.02 with denoising.

Seven pre-training objectives

A pre-training objective turns unlabeled text into (input, target) pairs, so the model can train with loss (1) on text nobody labeled. The older choice was language modeling: split the text and predict the continuation. By 2019 most strong models used a denoising objective instead: corrupt the input and train the model to repair it, as in BERT's masked language modeling.

The paper's Table 3 shows each objective it tested on one sentence, "Thank you for inviting me to your party last week." The figure reproduces the table. For each objective, compare two things: what the encoder still sees, and how many tokens the decoder has to write. Decoder tokens cost training time, because every target token is one more step of the decoder and one more term in (1).

Figure 4 · one sentence, seven objectives
Pick an objective to see its encoder input and decoder target on the paper's sentence, the number of tokens each side holds, and its scores from Tables 4, 5 and 7. Teal chips are mask and sentinel tokens; the violet chip is BERT-style's random replacement. Inputs and targets are verbatim from Table 3, except that the deshuffled input drops a stray "fun" the paper's version contains.

The objectives fall into three groups. The prefix LM objective splits the text at a random point, gives the first part to the encoder and trains the decoder to write the second. Deshuffling shuffles the tokens and asks for the original order. The BERT-style objective corrupts 15% of the tokens, replacing 90% of those with a mask token and 10% with a random token (the sentence shows "last" turned into "apple"), and the decoder writes out the entire original sentence.

T5's BERT-style objective differs from BERT in two ways. BERT chooses 15% of positions and turns 80% of them into [MASK], 10% into a random token, and leaves 10% unchanged. BERT is an encoder only, so it predicts just the chosen positions, each from the encoder's output vector at that position. T5 has a decoder, so its version asks the decoder for the entire uncorrupted sequence. The remaining rows vary the corruption. MASS-style drops the random swaps and keeps only mask tokens. Replace spans collapses each run of corrupted tokens into one sentinel token and has the decoder write only the corrupted tokens, each run after its sentinel. Drop tokens deletes the corrupted tokens with no marker and asks for them in order. Random spans is replace spans with the corruption chosen as contiguous spans rather than as independent tokens. The last three write 3 to 9 tokens for this sentence where the full-reconstruction objectives write 11.

Span corruption

The objective T5 ends up with is span corruption. Pick 15% of the tokens to corrupt, grouped into contiguous spans with a mean length of 3. Replace each span in the input with a sentinel, a special token that appears once in the example (the paper writes them <X>, <Y>, <Z>; the released vocabulary calls them <extra_id_0>, <extra_id_1> and so on). The target lists each span after its sentinel and ends with one more sentinel; the tokens left alone get no prediction.

The paper's own worked example uses a 500-token sequence. Corrupting 15% gives 500×0.15=75500 \times 0.15 = 75 tokens; asking for 25 spans makes their mean length 75/25=375 / 25 = 3. Counting sentinels, the encoder input has 500−75+25=450500 - 75 + 25 = 450 tokens and the target has 75+25+1=10175 + 25 + 1 = 101. An objective that rebuilds the whole text would need a 500-token target, five times as long. The released code sets the counts from the rate and the mean span length and then places the spans at random:

# span corruption on one training sequence (rate 0.15, mean span 3)
n        = len(tokens)                       # 512 in pre-training
n_noise  = round(n * 0.15)                   # 77 tokens to corrupt
n_spans  = max(1, round(n_noise / 3))        # 26 spans
mask     = random_spans(n, n_noise, n_spans) # spans at random positions
src, tgt, k = [], [], 0
for run in runs(tokens, mask):               # alternating kept / corrupted runs
    if run.corrupted:
        src += [sentinel(k)]                 # the whole span becomes one token
        tgt += [sentinel(k)] + run.tokens    # the target spells the span out
        k += 1
    else:
        src += run.tokens                    # kept tokens stay in place
tgt += [sentinel(k)]                         # a final sentinel ends the target
# len(src) = 512 - 77 + 26 = 461, len(tgt) = 77 + 26 + 1 = 104
# loss: cross-entropy on tgt only, teacher-forced through the decoder

In the figure, the sliders set the same two numbers the code takes. The passage shows one sampled mask; the bars underneath apply the same counting to a real 512-token sequence. Raise the mean span and the number of sentinels falls, so both the input and the target get shorter. Raise the rate and the target grows: at 50% with spans of 3, a 512-token example has a 342-token target and a 341-token input, and the target is no longer the short side. At 0% nothing is corrupted and the target is a lone sentinel with nothing to predict.

Figure 5 · span corruption, both knobs
15%
3
Set the corruption rate and mean span length; reroll to resample where the spans fall. The encoder input keeps every uncorrupted token in place and holds one sentinel per span; the decoder target spells each span out after its sentinel. The bars give lengths for a 512-token sequence, next to the 512-token target of an objective that rebuilds the whole text. The mask counts follow T5's random_spans_noise_mask; words stand in for wordpieces.

The baseline used for the paper's comparisons corrupts independent tokens ("i.i.d." in the tables), which is the replace-spans row of Figure 4: 15% of tokens chosen one at a time, with any that happen to be adjacent merged under one sentinel. At a 15% rate, independent choices produce mostly one-token runs, so the baseline needs more sentinels than a mean span of 3 does. The final models switch to span corruption with mean length 3, for a small score gain and slightly shorter targets.

The paper chose the objective in four stages, fixing each decision before moving to the next (its Figure 5): the high-level approach, then how to corrupt, then the corruption rate, then the span length. Each variant is pre-trained and fine-tuned like the baseline, so the scores differ only through the objective. To tell a real difference from run-to-run noise, the authors trained the baseline 10 times from scratch: its GLUE score has a standard deviation of 0.235 and its SuperGLUE score 0.416, and the tables bold every score within two standard deviations of the best. In the figure, each stage has a fixed axis for its metric so the spreads can be compared across stages; switch to SuperGLUE to see where it disagrees with GLUE.

Figure 6 · the objective search
1 / 4
Four stages of the search, on GLUE or SuperGLUE. The teal bar is the variant the paper carried forward. Each metric keeps one axis across all four stages. Numbers are verbatim from Tables 4 through 7.

Stage one compares the three families. BERT-style denoising scored 82.96 on GLUE, the prefix LM 80.69, and deshuffling 73.17. The stage spans almost ten points, but most of that is deshuffling's deficit; denoising led prefix language modeling by 2.27 GLUE points and 4.58 SuperGLUE points (69.85 against 65.27).

Stage two varies the corruption scheme. On GLUE the four variants span 2.1 points: MASS-style 82.32, BERT-style 82.96, replace spans 83.28 and drop tokens 84.44. Dropping tokens owes its GLUE lead to CoLA, the grammaticality task (60.04 against the baseline's 53.84), which the authors suggest is related to noticing that words are missing; on SuperGLUE it falls to 68.67 against replace spans' 71.36. The paper calls the variants similar and continues with replace spans: it and drop tokens both avoid predicting the full sequence, so they train faster, and replace spans held up better on SuperGLUE.

Stage three tries corruption rates of 10%, 15%, 25% and 50%. GLUE reads 82.82, 83.28, 83.00 and 81.27: little change until 50%, which also lowers SQuAD from 80.88 to 79.80 and lengthens the targets. T5 keeps 15%, which is also BERT's rate. Stage four replaces independent corruption with spans of mean length 2, 3, 5 and 10. The GLUE scores all sit within 0.7 of each other, about three baseline standard deviations, but span length 3 is best on SuperGLUE (72.53 against the i.i.d. 71.36) and on CNN/Daily Mail, and the paper calls its gain over i.i.d. small but significant.

Among denoising variants, then, no choice moved GLUE by more than about two points, and the paper picks among them partly on cost. The earlier decision, denoising instead of predicting a continuation, was worth 2 to 4 GLUE points: 2.27 in stage one, and 3.72 for the encoder-decoder in the architecture comparison (83.28 against 79.56).

C4, the cleaned web crawl

The corpus is its own variable, and the paper built one it could vary. C4, the Colossal Clean Crawled Corpus, starts from Common Crawl, a public archive that scrapes the web and publishes about 20 TB of extracted text each month. Most of that text is menus, error messages, boilerplate and duplicates. The authors took the April 2019 crawl and filtered it with a list of simple rules. At the line level: keep only lines that end in a period, exclamation mark, question mark or closing quotation mark; keep only lines with at least 5 words; drop any line containing the word "Javascript", since many pages carried warnings that it should be enabled; drop lines with cookie and policy notices ("terms of use", "privacy policy", "uses cookies" and similar); and delete Wikipedia-style citation markers such as [1]. At the page level: discard any page with fewer than 3 sentences, any page containing a curly bracket (a sign of source code), any page containing "lorem ipsum", and any page with a word from a public list of obscene and offensive words. Then deduplicate across the corpus, keeping one copy of any three-sentence span that occurs more than once, and keep only pages that the langdetect tool classifies as English with probability at least 0.99.

Figure 7 · C4's filters on one page
A made-up news page as Common Crawl extracts it. Each line is kept or dropped by the first line rule it fails. Turn a line rule off to see which lines it was catching, or inject a line of code or placeholder text to trip a page rule that discards everything. The copyright line survives every rule, as some boilerplate does in C4. Cross-page deduplication is not simulated.

What survives is about 750 GB of English text, orders of magnitude more than most pre-training corpora then in use, and the authors released it through TensorFlow Datasets. The filters change results. Pre-training the baseline on the same crawl without them (6.1 TB) lowered GLUE from 83.28 to 81.46 and SuperGLUE from 71.36 to 68.04, and the unfiltered version scored worst of the corpora on every task.

Smaller corpora from one domain sometimes did better (Table 8). A 20 GB mix of Wikipedia and the Toronto Books Corpus raised SuperGLUE to 73.24, and almost all of that came from one task: MultiRC, a reading-comprehension set whose largest source is fiction, rose from 25.78 to 50.93 exact match. A 35 GB news-only corpus raised the news reading task ReCoRD from 68.16 to 73.72.

A single domain usually means a small corpus, and small corpora have a cost in long training runs. Table 9 truncates C4 and pre-trains for the same 2352^{35} tokens, so the data repeats. With 2292^{29} tokens, each token is seen 64 times and GLUE barely moves (82.87). With 2252^{25} tokens, about 34 million, each is seen 1,024 times and GLUE falls to 79.55; at 2232^{23}, 4,096 repeats, it falls to 76.34 and SuperGLUE to 59.29. The training loss drops lower as the corpus shrinks, which the paper reads as the model starting to memorize its data. The final T5 runs see about a trillion tokens, which would repeat the 20 GB Wikipedia-and-books corpus hundreds of times, so they stay on C4.

Training on many tasks

In the text-to-text format, training on several tasks at once means mixing their (input, target) pairs into one stream, with the unsupervised objective as one more task. The open question is the mixing rate. Sampling in proportion to data set size would give almost every batch to the unlabeled corpus, which is orders of magnitude larger than any labeled set. The paper's examples-proportional mixing caps every data set at an artificial size KK before computing the proportions. With ene_n examples in task nn, task mm is sampled with probability

rm=min⁡(em,K)∑nmin⁡(en,K)r_m = \frac{\min(e_m, K)}{\sum_n \min(e_n, K)}
(6)

With K=219K = 2^{19}, a task with a million examples and a task with two million get equal shares, and a task with 100,000 examples gets about a fifth of their share each. Trained on such a mixture for the same total number of steps as the baseline's pre-training plus fine-tuning, a multi-task model scored 81.42 on GLUE and 67.30 on SuperGLUE, below the baseline's 83.28 and 71.36 (Table 12). Pre-training on the multi-task mixture and then fine-tuning on each task recovered the difference: 83.11 and 71.03. Leaving the target task out of the mixture and fine-tuning on it afterwards scored 81.98 and 71.68. Pre-training on the supervised tasks alone, with no unsupervised objective, scored 79.93 and 65.36 and was worse everywhere except translation.

The final models use multi-task pre-training followed by fine-tuning. It matched unsupervised pre-training in Table 12, and it lets the authors watch downstream scores throughout pre-training.

Spending 4× compute

Everything above holds the compute fixed. The paper then asks a direct question: you were just given 4× more compute; how should you use it? The premise is Rich Sutton's "bitter lesson", that general methods which use more computation have tended to win over hand-built ones, and the experiment compares ways of using it. The bigger models follow BERT-Large's shape (dmodel=1024d_{\text{model}} = 1024, 16 heads) with 16 or 32 layers per stack, for about 2× and 4× the baseline's parameters and compute.

Figure 8 · spending 4× compute
Six ways to spend four times the baseline compute, scored on SuperGLUE or GLUE. Bigger model options (teal) score above more steps or a bigger batch (amber), and a 2× model trained 2× as long lands next to a 4× model. The ensemble of four separately trained models barely moves SuperGLUE. Numbers verbatim from Table 13.

The options are: train 4× as many steps, train with a 4× batch, train a 2× model for 2× the steps, train a 4× model for the baseline number of steps, ensemble four separately trained baselines, or, as a cheaper variant that does not spend the full 4×, pre-train once and ensemble four models fine-tuned from that single checkpoint. On SuperGLUE the baseline scores 71.36; 4× steps gives 74.72 and 4× batch 74.64, with no clear winner between them; the 2× model for 2× steps gives 77.18 and the 4× model 78.04. On GLUE the order of the last two flips (86.18 against 85.91). The paper found no large difference between them on any task and concludes that training longer and training bigger are complementary, and that a bigger model gives an extra gain beyond more steps or a bigger batch.

Ensembling is a separate axis. Four independently trained models, averaged, were the best of all the options on CNN/Daily Mail, English-to-German and English-to-Romanian, but neither ensembling variant significantly improved SuperGLUE (71.74 against 71.36). The section is a table of measured tradeoffs, not a fitted law: the power-law fits of Kaplan et al. (January 2020) and Chinchilla (2022) came after it.

The final models

The final recipe combines what the study found:

ModelLayers (each stack)d_modeld_ffHeadsParameters
Small65122,0488≈60M
Base127683,07212≈220M
Large241,0244,09616≈770M
3B241,02416,38432≈2.8B
11B241,02465,536128≈11B

From Large up, the width dmodeld_{\text{model}} stays at 1,024. The 3B and 11B models grow mainly by widening the feed-forward layers, to 16,384 and 65,536, with 128-wide heads (dkv=128d_{kv} = 128). The paper chose dffd_{\text{ff}} because TPUs are most efficient on large dense matrix multiplications, and those are what the feed-forward layers compute.

Figure 9 · the five sizes on five benchmarks
The same recipe at five sizes, on the benchmark you pick. Dashed lines mark the previous best and, where the paper gives one, the human score. SuperGLUE climbs past the old record toward the human line; WMT English-to-German never reaches the old record. Scores are test-set numbers from Table 14.

On SuperGLUE, T5-11B scored 88.9, up from the previous best of 84.6 and 0.9 below the human baseline of 89.8, and it was best on the SuperGLUE average and on each of its eight tasks. On GLUE it averaged 90.3 against a previous best of 89.4, though it trailed earlier systems on three GLUE tasks: MRPC (paraphrase detection), QNLI (question answering posed as entailment; 96.9 against 99.2) and QQP (duplicate Quora questions) accuracy. On SQuAD it reached 91.26 exact match and 96.22 F1. Human exact match on SQuAD is estimated at 82.30, so the paper doubts further gains there mean much. It also set the record on CNN/Daily Mail. Counting those misses and the three translation tasks, T5 was state of the art on 18 of the 24 tasks. The paper names the move to 11 billion parameters as the most important ingredient, and a separate check (Table 15) found T5-Base beat the baseline trained on the same trillion tokens on every task, so the other recipe changes also counted.

T5 did not reach the state of the art on any WMT translation task. In the figure, English-to-German goes from 26.7 (Small) to 32.0 (Large) and then stops, 31.8 at 3B and 32.1 at 11B, against a previous best of 33.8. The paper offers hedged reasons: the English-only pre-training corpus "may be in part" responsible; most of the best systems used backtranslation, which creates extra training pairs by translating target-language text back into the source language; the best English-to-Romanian result used cross-lingual pre-training; and the best English-to-German result trained on the much larger WMT 2018 data. The paper does not isolate which of these matters, and does not blame the text-to-text format itself.

Much of what came after reused the paper's pieces directly. Switch Transformers built its mixture-of-experts models on the T5 architecture and trained them on C4, the text-to-text format became a common way to train one model on many instructions, and C4 became a standard pre-training corpus.

Provenance Verified against primary literatureHow we verify
Vaswani et al. (2017)The encoder-decoder Transformer T5 keeps, apart from three changes to normalization and positions.
BERT / MLM (2018)The denoising objective T5 adapts. T5’s "BERT-style" baseline is a modified version, not BERT’s recipe.
RMSNorm (Zhang & Sennrich, 2019)T5’s rescale-only LayerNorm is this operation. The RMSNorm preprint appeared a week before T5’s; T5 does not cite or name it.
Shaw et al. (2018)Learned relative positions; T5 reduces each learned vector to one scalar per head, shared across layers.
HF transformers, modeling_t5.pyT5LayerNorm has no mean subtraction and no bias. T5Attention applies no 1/√d_kv to the logits; _init_weights scales W_q by (d_model·d_kv)^−1/2 instead. _relative_position_bucket gives the bucket bands in Figure 2.
t5/data/preprocessors.pyrandom_spans_noise_mask: round(n·rate) noise tokens in round(noise/mean_span) spans, the counting rule Figure 5 uses.
Sutton, "The Bitter Lesson" (2019)The premise the 4× compute experiment puts to the test.
correctionT5’s "BERT-style" objective is not BERT’s. BERT picks 15% of positions, turns 80% of them into [MASK], 10% into a random token and leaves 10% unchanged, and predicts only those positions at the encoder output. T5’s version corrupts 15% as 90% mask and 10% random and has the decoder rebuild the entire original sequence; T5’s final span objective predicts only the dropped spans. Two smaller slips in the paper: Table 3’s deshuffled example contains a word ("fun") that is not in the original sentence, so it is not a permutation (Figure 4 drops it); and Section 3.7 says the 11B model was best among the five sizes on every task, but Table 14 has T5-3B ahead on WMT English-to-Romanian (28.2 vs 28.1 BLEU).

Questions you might still have

?

How does one set of weights know which task it is doing?
Only from the input text. Every training input for MNLI starts with "mnli premise:" and every target is one of three label words, so the words at the front of the input predict the kind of output the way any context predicts the next token in a language model. There is no task id, no routing, and no separate output layer.

?

What if the model writes something that is not a valid label?
It is scored as wrong. For a classification task, an output string that is none of the label words counts as an error, and the same holds for an STS-B output that is not one of the 21 numbers. The authors report that none of their trained models ever produced an invalid output.

?

Why an encoder-decoder, when decoder-only models later took over?
In the paper’s controlled comparison (Table 2), the encoder-decoder with a denoising objective scored highest on every benchmark, with twice the parameters of a decoder-only model at the same compute per example. Later decoder-only models won for reasons this study did not measure, such as generating open-ended text with no separate input, in-context prompting, and a simpler single stack at very large scale. The GPT-3 and LLaMA explainers on this site cover that line.

?

If the choice of denoising objective barely matters, why run the search?
A measured null result lets you choose on cost. Among the denoising variants, GLUE moved by about two points at most, so T5 kept the variant with the shortest targets, which trains fastest. The larger gaps were between families: BERT-style denoising beat prefix language modeling by 2.27 GLUE points and deshuffling by 9.79.

?

Why did T5 miss state of the art on translation?
The paper does not know for sure. It says the English-only pre-training corpus may be part of the reason, notes that the best WMT systems used backtranslation (extra training pairs made by translating target-language text back into the source language) and cross-lingual pre-training, and that the best English-to-German result used the much larger WMT 2018 training set. The model sizes above Large barely moved En-De BLEU (32.0, 31.8, 32.1).

?

Is T5 the model or the paper?
Both. The paper is a comparison of transfer-learning choices on one baseline; T5 is the name of the five final models (Small to 11B) trained with the choices that won, plus the text-to-text framework itself. The C4 corpus and the released checkpoints were used by many later models.

Footnotes & further reading

  1. The paper: Raffel, Shazeer, Roberts, Lee, Narang, Matena, Zhou, Li, Liu, Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer (Google, JMLR 21, 2020). Code (span masking: t5/data/preprocessors.py, random_spans_noise_mask) and the C4 data set.
  2. The PyTorch port used for the normalization, attention scaling and bucketing details: modeling_t5.py in Hugging Face Transformers (T5LayerNorm, T5Attention).
  3. The backbone: Vaswani et al., Attention Is All You Need (2017); explained on this site at Attention Is All You Need.
  4. The denoising objective T5 adapts: Devlin et al., BERT (2018); the span-masking idea, Joshi et al., SpanBERT (2019); and the masked sequence-to-sequence objective, Song et al., MASS (2019).
  5. The rescale-only normalization, posted a week before T5: Zhang and Sennrich, Root Mean Square Layer Normalization (2019). Standard layer norm is explained at Layer Normalization; its later use in LLaMA (2023).
  6. Relative position representations: Shaw et al., Self-Attention with Relative Position Representations (2018). A later rotation-based alternative is explained at RoPE.
  7. The prefix-LM architecture: Dong et al., Unified Language Model Pre-training (UniLM) (2019).
  8. The scaling premise: Rich Sutton, The Bitter Lesson (2019); the optimizer, Shazeer and Stern, Adafactor (2018); the later fitted laws, Kaplan et al., Scaling Laws for Neural Language Models (2020), and Hoffmann et al., Chinchilla (2022).