Learn the language once — then re-dress every task as text.
In 2018, the way to win an NLP benchmark was to design a new model for it: one wiring for entailment, another for question answering, another for similarity. Each needed its own labeled dataset, and labels were the scarcest resource in the field — while billions of words of plain, unlabeled text sat unused.
This paper bets that a single Transformer, trained only to predict the next word in ordinary books, already absorbs most of what those specialized models were each learning from scratch. So it flips the workflow: keep one generic network, flatten every task's input into a plain token sequence the network can read, add one small output layer, and fine-tune briefly. That bet won on 9 of the 12 benchmarks it was tested on.
The GPT recipe, version one: pre-train on raw text, then bend the task to fit the model — never the model to fit the task.
The problem and the bet
Why NLP was stuck, and what shape the fix takes
Step 1 · One task, one machine
Every task had its own custom-built model — and its own label famine.
Let's make the problem concrete with one example, and keep it on stage for the whole lesson. Here is a real pair from SNLI, the largest dataset this paper is tested on. The task is textual entailment: read two sentences and decide whether the first guarantees the second.
Premise — the sentence we take as true
Hypothesis — does the premise guarantee this?
Deciding this pair takes real language understanding — you used the fact that soccer is a sport without noticing. In 2018, the models that could do it were discriminatively trained: built and trained end-to-end on that one dataset, with architectures crafted for the task (compare-and-align networks for entailment, multi-range attention for reading comprehension, and so on). Each benchmark had its own leaderboard of bespoke machines.
The bottleneck was labels. Someone has to write and annotate every premise–hypothesis pair, so labeled sets stayed small — from about 5.7k examples (STS-B) up to 550k (SNLI) — while unlabeled text was effectively infinite. The field already had one trick for tapping raw text: pre-trained word embeddings (word2vec, GloVe), which give a model a head start on what individual words mean. But an embedding table is just the first layer. Everything above it — how words combine into claims, negations, consequences — still had to be learned from those small labeled sets, once per task.
The paper's introduction names the two open questions that had kept it that way. Nobody agreed on what objective teaches the most transferable representations from raw text — language modeling? machine translation? discourse coherence? And nobody agreed on how to transfer them — every existing method changed the model architecture per task. The next two steps answer both.
| Task family | Datasets | Count |
|---|---|---|
| Natural language inference | SNLI · MNLI · QNLI · RTE · SciTail | 5 |
| Question answering / commonsense | RACE · Story Cloze | 2 |
| Semantic similarity | MRPC · QQP · STS-B | 3 |
| Classification | CoLA · SST-2 | 2 |
Step 2 · The recipe from orbit
Two stages: read 7,000 books once, then lend the same network to every task.
Twelve tasks, twelve bespoke models, and a label famine. The paper's answer is a division of labor: let unlabeled text do the heavy lifting, and ask the labels to do only the last mile.
The whole method is the two lanes below. In stage 1, a Transformer plays a single game across the BooksCorpus — over 7,000 unpublished books — with no labels anywhere: given the words so far, guess the next one. In stage 2, those learned weights are carried over unchanged; our premise and hypothesis are flattened into one token sequence, a small output layer is bolted on top, and the whole thing is fine-tuned briefly on the labeled pairs.
One choice in this drawing matters more than it looks: which raw text. The team picked BooksCorpus over the better-known 1B Word Benchmark, which is a similar size but shuffled at the sentence level. Books keep long stretches of contiguous story, so guessing the next word sometimes requires remembering something from paragraphs ago — and that pressure is exactly what stage 2 will cash in on. Notice also the asymmetry between the lanes: 100 epochs of reading, then just 3 epochs of fine-tuning. Stage 1 does almost all of the work.
After pre-training, the model reaches a token-level perplexity of 18.4 on BooksCorpus — perplexity ≈ how surprised the model is by held-out text; lower is better. Our soccer pair carries a label, so it can only ever enter the bottom lane.
Step 3 · The machine itself
The model is the 2017 Transformer's writing half — twelve decoder blocks.
The recipe calls for one network in both lanes. Before we watch it train, let's look inside those ink-colored boxes.
If you've met the original Transformer, this is its decoder — the
tower that writes — kept, and the encoder discarded. GPT-1 stacks
12 decoder blocks, each holding a masked multi-head
self-attention layer and a feed-forward layer, with 768-dimensional
states and 12 attention heads. Text is first chopped into sub-word
pieces by byte-pair encoding (BPE) — a
40,000-entry vocabulary of fragments, so no word is ever
out-of-vocabulary — and each piece gets an embedding plus a learned
position vector. In the paper's notation the input matrix is built
as h₀ = U·W_e + W_p, then flows up through the twelve
blocks.
The word doing the real work here is masked. In the figure,
look at the arcs under the token row: when the model computes the
representation of a, attention may reach any word to
its left, but the arc toward sport is cut.
Every position is blind to its own future. That one constraint is
what makes the model a generator — if a position could peek
ahead, "guess the next word" would be a solved game with nothing to
learn — and it's the design choice that separates this paper from
BERT, which arrived months later reading in both directions but
unable to generate.
We won't re-derive attention itself on this page — how those arcs get their strengths is a six-step calculation that deserves its own lesson, and the 2017 paper's explainer walks it in full. For today's story one sentence covers it: each position blends information from the positions it is allowed to see. What GPT-1 contributes is not the machinery but what the machinery is trained on, and what happens to it afterward.
A tidy detail from Eq. 2: the output softmax reuses the token embedding matrix (P(u) = softmax(h_n·W_eᵀ)) — one table translates words into vectors on the way in and vectors back into words on the way out. Training used Adam with a max learning rate of 2.5e-4, batches of 64 sequences × 512 tokens, and GELU activations.
The engine, by hand
Compute the pre-training loss · see why it transfers · bolt on a task
Step 4 · The pre-training objective
Pre-training is one game: put probability on the actual next word.
The stack ends in a softmax over 40,000 pieces — a full probability distribution over what comes next. Stage 1 turns that distribution into a score, and the score into learning.
Our labeled pair sits out stage 1, but its hypothesis is still just an English sentence — and the objective works on any sentence; that indifference is the whole point of unsupervised learning. So let's borrow it as practice text. Cover the sentence with your hand and reveal it word by word. At each position the model has already published its distribution over what comes next; then the true word is revealed, and the model is graded on one number only: the probability it gave that word.
The grade is −ln p — natural-log units, called nats.
Give the true word probability 1 and you score a perfect 0; hedge
at 0.5 and you pay 0.69; at p = 0.01 the bill is 4.61. Let's grade
three positions of our hypothesis with made-up but realistic
probabilities (each row is one calculator keystroke — try one):
“Some ___” — model says P(men) = 0.20
Almost anything can follow “Some”, so the guess is diffuse and the bill is hefty.
“Some men are ___” — model says P(playing) = 0.35
Context accumulates; the distribution sharpens and the bill shrinks.
“Some men are playing a ___” — model says P(sport) = 0.42
Five words of context make “sport” a strong favorite. Cheapest row of the three.
Keep that 3.53 — it returns in Step 8. Training is nothing more than nudging all the weights so this bill, summed over every position in 7,000 books, goes down. Feel how the penalty moves first:
Drag to change the probability on the true word
What to notice: every halving of p costs the same +0.69 nats — dropping from 0.42 to 0.21 hurts exactly as much as from 0.10 to 0.05. The log makes confident wrongness expensive and confident rightness barely rewarded, so the model can never stop sharpening.
You have now run the entire objective by hand. Sum your per-position scores (as log-probabilities, sign flipped back) over a context window of k tokens, and you get Equation 1 of the paper — maximize:
L₁(U) = Σᵢ log P(uᵢ | uᵢ₋ₖ, …, uᵢ₋₁; Θ)
uᵢ = the i-th token · k = context window (512 tokens) · Θ = all the network's weights
Two simplifications to be honest about: the probabilities in the table are invented so the arithmetic stays visible — the real model spreads them over 40,000 BPE pieces, not whole words — and a real context window is 512 tokens, not five. The −ln p bookkeeping is exact.
Step 5 · Why this transfers
To keep winning the guessing game, the model is forced to learn what the tasks will ask.
You just paid 0.87 nats on “sport” — the cheapest row in the table. A fair question before going further: why would shrinking that bill teach a model to judge entailment?
This is the strangest claim in the paper, and it deserves a slow step — the authors themselves present the explanation as a hypothesis, not a theorem. Here's the way in: ask what the model must know for row 3 to be cheap. To rank “sport” above “game”, “piano” or “sandwich” after Some men are playing a…, the network needs, somewhere in its weights, the fact that the things men play together are sports. Now look back at our gold label from Step 1: that is the same fact the entailment task grades. Producing the label was never the hard part — knowing that soccer is a sport was. And that knowledge sat in raw text all along, no annotator required.
Scale the pressure up. Across 7,000 books, the cheapest way to predict next words is not memorizing text — it's tracking who did what to whom, what got negated, what a pronoun refers to, how a scene tends to end. A model that keeps a mystery novel's suspects straight pays a smaller bill on the reveal page than one that doesn't. None of these skills were the goal. Every one of them lowers L₁, so gradient descent buys them anyway.
“A hypothesis is that the underlying generative model learns to perform many of the tasks we evaluate on in order to improve its language modeling capability.” — Section 5, Radford et al., 2018
A hypothesis needs evidence, and the paper offers two pieces we'll weigh properly in Part C: peel pre-trained layers off one at a time and task performance degrades layer by layer (Step 10); and with zero fine-tuning, the raw language model can already play the tasks — and keeps getting better at them the longer it pre-trains (Step 11).
Labels were never the scarce ingredient. The facts behind the labels are written across billions of words of ordinary text, and next-word prediction is a machine for extracting them without asking anyone to annotate anything.
Step 6 · The fine-tuning bridge
Flatten the pair into one sequence; one new matrix reads the answer off the last token.
Stage 1 left us weights holding facts like soccer ⊂ sport. But the network still only knows how to emit next-word probabilities — nothing in it can say “entailment”. Stage 2 has to build that exit, with as little new machinery as possible.
First problem: entailment hands us two sentences, and the
machine eats one sequence. The paper's move — borrowed from
what it calls traversal-style approaches — is disarmingly direct:
concatenate them. Wrap the whole thing in randomly-initialized
start and end tokens, put a delimiter $ between
premise and hypothesis, and feed the result through the pre-trained
stack exactly as if it were a stretch of book text:
Now the exit. The paper takes h_l^m — read the
sub- and superscripts slowly, they stalled us too on a first pass:
the activation of the last block at the m-th (final)
input token, the dashed column above ⟨e⟩ in the
figure. By the top of the stack, that one 768-number vector has had
the chance to attend across the entire pair — it is the network's
summary of everything it read. Multiply it by one new matrix
W_y (768 × 3, one column per class), softmax the three
resulting scores, and you have an entailment classifier. Say the
scores for our pair come out as 2.1, 0.3 and −0.8 (invented for the
arithmetic, like Step 4's table):
Exponentiate each score
Softmax's first move — everything positive, gaps amplified.
Divide by the sum (8.17 + 1.35 + 0.45 = 9.97)
Three scores become three probabilities — the bars in the figure.
Grade it like Step 4: −ln of the true class
The gold label is entailment, so the bill is small. This number is the supervised loss for our pair.
Same scoring rule as pre-training, different question: stage 1 asked which token comes next, stage 2 asks which of three labels is right. Summed over all labeled pairs, that gives the paper's Equations 3 and 4:
P(y | x¹…x^m) = softmax(h_l^m · W_y) → maximize L₂(C) = Σ log P(y | x¹…x^m)
h_l^m = final block's vector at the last token · W_y = the only new matrix · C = the labeled dataset
The additions for an entire task: W_y (768 × 3 numbers) and the embeddings of the delimiter tokens. Everything else — all twelve blocks, every attention head — arrives from stage 1 and is merely nudged. The bespoke architectures of Step 1 needed millions of task-specific weights; this needs a few thousand.
Fine-tuning specifics (§4.1): learning rate 6.25e-5, batch size 32, dropout 0.1 on the classifier. The real 768-dim h and W_y stay folded here — the arithmetic above is the full mechanism at toy scale.
Step 7 · One trick, four task shapes
Every task shape flattens into token sequences — the network never changes.
Flattening premise-$-hypothesis handled entailment. The other eleven datasets arrive in different shapes — single sentences, unordered pairs, a passage with candidate answers — and each gets its own flattening, never its own network.
The four recipes are below (the paper's Figure 1, redrawn in our
colors). Two deserve a closer look. Similarity: “are these
two sentences paraphrases?” has no natural first-vs-second order,
but a left-to-right model reads order as meaning — so the input is
flattened both ways, each order runs through the Transformer
independently, and the two output vectors are added element-wise
before the head. Multiple choice: each candidate answer gets
its own sequence — context, question, $, that answer —
each runs through the same network for a score, and one softmax
across the candidates picks the winner.
Tap a task family to spotlight its flattening
Entailment — the flattening you already know from Step 6: premise, delimiter, hypothesis, one forward pass, three-way head.
The buttons only spotlight rows in a chart that is complete as-is — all four flattenings are above, in the page's fixed colors: teal first segment, amber second, coral for every token added at fine-tuning.
Contrast this with the era's main alternative: keep the pre-trained network as a frozen feature extractor and build a task-specific architecture on top of it — which reintroduces exactly the per-task engineering the paper wants to delete. Here the adaptation lives in the data format, and the format is text: the one thing the model is already fluent in.
Step 8 · The auxiliary objective
Fine-tuning keeps the next-word game running — λ sets its volume.
Step 6 ended with L₂ ≈ 0.20 nats of supervised loss on our pair. The obvious plan for stage 2 is to minimize L₂ and call it done. The paper doesn't stop there.
While fine-tuning on the labeled pairs, the model also keeps playing the guessing game on those same sequences — predicting each next token of the flattened premise-$-hypothesis text, exactly the L₁ arithmetic from Step 4, just run on stage-2 data. The two bills are added with a mixing weight λ, and we've already computed both ingredients for our pair: L₂ ≈ 0.20 from Step 6's softmax, and (using our three graded positions as a stand-in for the whole sequence's next-word bill) L₁ ≈ 3.53 from Step 4. Mix them yourself:
Drag λ — the paper trains at λ = 0.5
Total loss, split into its two ingredients
L₃ = L₂ + λ·L₁ = 0.20 + 0.50 × 3.53 = 1.97 nats
What to notice: at the paper's λ = 0.5, the gray segment dwarfs the cinnabar one — most of the training signal is still reading practice, not the label. (These magnitudes are our toy numbers; in real training the balance shifts with sequence length and batch size, but λ is the same dial.)
L₃(C) = L₂(C) + λ · L₁(C)
Equation 5 · C = the labeled dataset, used both as labeled pairs and as raw text · λ = 0.5
Why bother? The paper reports that the auxiliary term improves generalization and speeds up convergence, and the intuition fits everything we've built: L₁ is what put the knowledge in, and keeping it alive during fine-tuning stops the network from trampling that knowledge while chasing a few hundred thousand labels. The ablation in Table 5 adds a caveat the abstract doesn't advertise: the auxiliary loss helps on the large datasets — QNLI drops from 88.1 to 86.9 without it, MNLI and QQP dip too — but on small ones it gets in the way: CoLA actually rises from 45.4 to 47.9 when it's removed, and the naive average across the eight GLUE tasks is a wash (75.0 vs 74.7). A useful tool, not a magic one.
The full stage-2 budget, for contrast with stage 1's 100 epochs: about 3 epochs at learning rate 6.25e-5, batch size 32, warmup over 0.2% of training. The expensive general education happens once; each task is a weekend course.
The evidence
Nine records, two defeats, and a curve pointing at GPT-2
Step 9 · The scoreboard
One generic model took nine of twelve records from the bespoke machines.
The recipe is complete: pre-train (Steps 2–4), see why it stores skills (Step 5), flatten and fine-tune (Steps 6–8). Time to face the twelve datasets from Step 1's table.
The same pre-trained weights, fine-tuned per task with nothing but Step 7's flattenings, set a new state of the art on 9 of the 12 — often beating ensembles of specialized models with one network. A sample, against the best previously published results:
Report card · GPT-1 vs previous best (each task's own metric)
Story Cloze · pick the story ending
previous best
RACE · exam reading comprehension
previous best (9-model ensemble)
CoLA · grammatical acceptability
previous best
GLUE · overall benchmark score
previous best
0task metric →100
And the three losses, because a scoreboard you can trust must show them: on RTE, the smallest entailment set (2,490 examples), GPT-1 scored 56.0 against 61.7 for a multi-task biLSTM — too few examples to fine-tune on, a gap the authors suggest multi-task training might close. On MRPC it trailed a specialized paraphrase system (82.3 vs 86.0), and on SST-2 its 91.3 fell short of 93.2. Worth saying plainly: the bespoke-model era did not lose every battle. It lost the war — one generic recipe now matched or beat nearly all of them at once.
Metrics differ per task — accuracy for Story Cloze and RACE, Matthews correlation for CoLA, F1 for MRPC and QQP — so compare each bar with its neighbor, not tasks against tasks. Full tables: §4.2, Tables 2–4 of the paper.
Step 10 · Which ingredient mattered?
Delete pre-training and the average collapses by 14.8 points.
Nine records still admit three explanations — the pre-training, the Transformer, or the auxiliary loss. Table 5 removes them one at a time and reruns everything.
Remove stage 1 entirely — train the same architecture directly on each task — and the average score falls from 74.7 to 59.9, a 14.8-point collapse, with every single task hurt. Swap the Transformer for a 2048-unit LSTM and the average drops 5.6 points (the LSTM wins on exactly one dataset, MRPC). The auxiliary loss you already weighed in Step 8: real help on big datasets, mild drag on small ones. So the ranking of ingredients is unambiguous — pre-training first, architecture second, λ third.
The second experiment speaks directly to Step 5's hypothesis. If pre-training stored task skills throughout the network, handing over more of the pre-trained stack should help monotonically — and it does. Transfer only the embedding layer and MultiNLI sits around 73; hand over all twelve blocks and it climbs to about 82. In the figure, each dot to the right adds one more pre-trained block; there is no plateau where the extra layers stop paying.
The gain is not concentrated in the bottom layers — that would just be better embeddings, the trick NLP already had. It accrues through all twelve, which is exactly what you'd expect if next-word prediction had packed useful functionality into every floor of the building.
Step 11 · Zero-shot — the loose thread
With no fine-tuning at all, the language model can already play the tasks.
The layer ablation says the skills are spread through the stack. One question remains from Step 5: can we catch the raw language model doing a task with zero labels — no W_y, no stage 2 at all?
You can, if you phrase the task in the only language the model
speaks: probabilities over text. Take sentiment on movie reviews.
Append the word very to a review, ask the model for
its next-word distribution, but compare only two entries:
positive and negative. Whichever gets
more probability is the verdict — the review's tone was already
steering the model's expectations. The paper builds one such
heuristic per task: for grammaticality, threshold the average
per-token log-probability (broken sentences read as improbable
text); for RACE, pick the answer the model finds most probable
given the passage; for Winograd pronouns, substitute each candidate
referent and keep the one that makes the rest of the sentence read
more naturally.
The result is the figure below. Tracked over the course of pre-training, these zero-shot scores climb steadily — no labels, no fine-tuning, just more next-word practice — and the Transformer's curves sit above an LSTM's jittery ones. This is the paper's quietest figure and, in hindsight, its loudest: it says task ability grows inside the language model itself.
Hold this figure and Step 8's slider side by side and you can see a fork in the road. If pre-training alone keeps climbing, why keep stage 2 at all? Turning that loose thread into the whole program — delete fine-tuning, scale up the reading — is, almost verbatim, the pitch of GPT-2. Before the closing bookend, four questions to close the loop. Sketch an answer from memory, then check — Steps 4, 6 and 8 hold the receipts.
What are the only new parameters a task needs?
W_y — one linear layer, 768 numbers per class — plus embeddings for the delimiter tokens ⟨s⟩, $, ⟨e⟩. Everything else transfers from stage 1 and is only nudged (Step 6).
Why books, and not the bigger-name 1B Word Benchmark?
The 1B Word corpus is shuffled at the sentence level, which destroys long-range structure. Books force the model to carry context across paragraphs to win the guessing game — the ability the downstream tasks then borrow (Step 2).
λ = 0.5 — what is being mixed, and when does it help?
L₃ = L₂ + λ·L₁: the supervised loss plus the next-word loss on the same flattened sequences. It helps the large datasets (QNLI, MNLI, QQP) but slightly hurts small ones — CoLA improves when it's removed (Step 8).
Stage 1 never sees a label. Where does the entailment skill come from?
From the facts behind the labels: ranking “sport” highly after “Some men are playing a…” requires knowing what counts as a sport — the very fact the entailment label tests. Cheap next-word bills demand real knowledge (Steps 4–5).
The recipe outlived the scoreboard.
Every number in Part C has since been surpassed. What survived is the workflow this paper demonstrated — pre-train on raw text, then adapt one generic model — which within two years became the default shape of NLP, and then of AI at large.
BERT
Took the same pre-train-then-fine-tune recipe but dropped the mask constraint, reading both directions with an encoder — and overtook GPT-1 across the benchmarks. Either way, the recipe won.
GPT-2
Grew Step 11 into an entire thesis: scale the model and the corpus, skip fine-tuning entirely, and prompt the raw language model — zero-shot, on everything.
GPT-3 and the assistants
In-context learning replaced W_y; instruction tuning and RLHF replaced task fine-tuning. The two-stage skeleton — costly generic reading, cheap adaptation — is still every chat model's biography.
Stage 1 never went away: every assistant you've talked to began exactly here — guessing the next word, one token at a time.