Search

Search papers and lessons

Language Models are Few-Shot Learners (GPT-3)

Tom B. Brown, Benjamin Mann, Nick Ryder et al. · 2020

GPT-3 is a 175-billion-parameter language model that learns new tasks from a few examples written in its prompt, with no weight updates, and often comes close to fine-tuned models.

On this page

  • Colour = topic mix
  • Calculus
  • Probability
  • Neural network basics
  • Linear algebra
  • Architectures
  • Discrete math
  • Sign in to see your progress

TL;DR

GPT-3 is an autoregressive Transformer with 175 billion parameters, trained only to predict the next token of web text. Show it a few worked examples of a task inside the prompt and it performs the task with no gradient updates. On several benchmarks it comes close to models that were fine-tuned on thousands of labeled examples. The paper's main claim is that this ability, called in-context learning, improves smoothly as the model gets bigger.

Where you'll see it: the prompt-driven way most people use large language models today, where a task is described and demonstrated in text instead of trained into a new model.

The problem

The standard recipe before 2020 was pretrain then fine-tune. Train a large model on unlabeled text, then run Fine-Tuning on a labeled dataset for each new task. Fine-tuning works, but it needs thousands to hundreds of thousands of labeled examples per task. A fine-tuned model can also latch onto narrow patterns in its training data, so its benchmark score may overstate how well it understands the task. A person, by contrast, can learn a new language task from one instruction or two examples.

Zero-shot transfer without fine-tuning had shown promise, but it was far behind. The paper cites one earlier result that scored only 4% on Natural Questions. The open question was whether scale alone could close that gap, so that a single model could do many tasks from a short description and a handful of examples.

Key idea

Keep the model task-agnostic, make it much larger, and give the task at inference time as text. The prompt holds a natural language description, optionally a few input and output pairs, and then the new input. The model continues the text, and the continuation is the answer. No weights change. The paper's example asks for English to French translation:

Translate English to French:
sea otter => loutre de mer
peppermint => menthe poivrée
plush giraffe => girafe peluche
cheese =>

The model is expected to write "fromage". The paper calls the inner loop of this process in-context learning. The outer loop is the pretraining that gave the model its skills. The authors measure how much the model improves as they add demonstrations and as they increase its size.

The method

Architecture and scale

GPT-3 uses the same architecture as GPT-2, with one change: the layers alternate dense attention with locally banded sparse attention, similar to the Sparse Transformer. The authors trained eight sizes, from 125 million to 175 billion parameters, to test how performance depends on scale. The table shows four of the eight (the others are 350M, 760M, 2.7B and 6.7B). All use a context window of 2048 tokens and a feedforward width of four times the model width.

ModelParametersLayersModel widthHeadsBatch (tokens)Learning rate
GPT-3 Small125M12768120.5M6.0e-4
GPT-3 XL1.3B242048241M2.0e-4
GPT-3 13B13.0B405140402M1.0e-4
GPT-3 175B175.0B9612288963.2M0.6e-4

The largest model is 1400 times bigger than the smallest one by parameter count, which is the range the scaling experiments need.

Training data

The corpus is a mix of five sources. Filtered Common Crawl is 410 billion tokens and makes up 60% of the training mix. The rest is WebText2 (19 billion tokens), Books1 (12 billion), Books2 (55 billion), and English Wikipedia (3 billion). Sampling is not proportional to size. Over the 300 billion training tokens, Common Crawl is seen only 0.44 times and Books2 0.43 times, while WebText2 (2.9 times), Books1 (1.9 times) and Wikipedia (3.4 times) are repeated. The authors accept some overfitting on the curated data in exchange for higher quality.

The authors also tried to remove any overlap between their training data and the test and development sets of every benchmark they report. A filtering bug let some overlap through, and retraining was too expensive, so Section 4 measures the effect of the leftover contamination afterward.

Training objective and compute

Training is standard autoregressive language modeling. The model reads a sequence of tokens and is trained to assign high probability to each next token:

L(θ)=−∑t=1Tlog⁡pθ(xt∣x1,…,xt−1)\mathcal{L}(\theta) = -\sum_{t=1}^{T} \log p_\theta(x_t \mid x_1, \dots, x_{t-1})

Here xtx_t is the token at position tt, θ\theta is the set of all weights, and pθp_\theta is the probability the model gives that token. Minimizing this sum is the same as maximizing the likelihood of the training text.

GPT-3 was trained on 300 billion tokens. A common rule of thumb says training takes about six floating-point operations per parameter per token, since each parameter does about two operations in the forward pass and about four in the backward pass. The paper's estimate is 3.14×10233.14 \times 10^{23} FLOPs, which matches 6×1.75×1011×3×1011≈3.15×10236 \times 1.75 \times 10^{11} \times 3 \times 10^{11} \approx 3.15 \times 10^{23}.

Three settings and how they are scored

The paper compares four ways to specify a task.

SettingWhat the model sees at test timeWeight updates
Fine-tuningNothing at test time; the weights were trained on the taskYes, on thousands of examples
Few-shotTask description plus K demonstrations (K typically 10 to 100)None
One-shotTask description plus one demonstrationNone
Zero-shotTask description onlyNone

GPT-3 is evaluated in the last three settings. The demonstrations are drawn at random from the task's training set, and K is chosen on the development set. For multiple-choice tasks the model scores each candidate completion by its likelihood, normalized by length. For free-form answers it uses beam search with width 4 and a length penalty of 0.6, then scores with F1, BLEU, or exact match, whichever is standard for the dataset.

Results

Language modeling

On the Penn Tree Bank, zero-shot, GPT-3 reaches a perplexity of 20.50. The previous state of the art was 35.8, so the improvement is about 15 points. The authors skip most standard language-modeling benchmarks because they are built from Wikipedia, which the model saw during training.

Cloze and completion

On LAMBADA, which tests whether the model can predict the last word of a passage that needs long context, few-shot GPT-3 reaches 86.4% accuracy. The previous best was 68.0%. Zero-shot reaches 76.2%.

Closed-book question answering

Closed-book means the model must answer from what it stored in its weights, with no retrieval step. On TriviaQA few-shot GPT-3 reaches 71.2%, above the 68.0% of a fine-tuned open-domain system that uses retrieval. On Natural Questions it reaches 29.9% few-shot, well behind the fine-tuned open-domain system at 44.5%.

SuperGLUE

On the SuperGLUE suite, GPT-3 was given 32 examples per task in the few-shot setting. Its test-set average (Table 3.8) is 71.8, just above fine-tuned BERT-Large at 69.0 and far below the fine-tuned state of the art at 89.0. It is near state of the art on COPA (92.0 against 94.8) and ReCoRD. It reaches 80.1% on WSC. It is weak on WiC, at 49.4%, which is chance for a two-way task. The authors also find, from a sweep over the number of examples on the dev set (Figure 3.8), that fewer than eight examples per task are enough for GPT-3 to beat a fine-tuned BERT-Large on the overall score. That sweep uses dev scores, so it is not directly comparable to the test-set table.

Arithmetic

The authors wrote ten arithmetic tests and asked the model to answer in plain text, for example "Q: What is 48 plus 76? A:". Accuracy on the 175B model:

Setting2-digit add3-digit add4-digit add5-digit add
Zero-shot76.934.24.00.7
One-shot99.665.514.03.5
Few-shot100.080.425.59.3
22.533.544.55020406080100digits per operandaccuracy (%)
  • few-shot
  • one-shot
  • zero-shot
Addition accuracy for GPT-3 175B. Accuracy falls quickly as numbers get longer, and more demonstrations help most on the harder cases.

Smaller models do much worse. Even the 13B model solves two-digit addition only about half the time.

News articles

The authors generated news articles from titles and asked about 80 people per model to say which article a human wrote. Accuracy at spotting the deliberately bad control model was about 86%. Accuracy on the 175B model's articles was about 52%, barely above chance.

Scaling

Across the eight sizes, cross-entropy loss follows a power law in training compute, and the trend continues for about two more orders of magnitude with little bending. Downstream performance also rises with size in all three settings. The gap between zero-shot and few-shot performance grows with size, which the authors read as evidence that larger models are better at learning from context.

Limitations the authors report

Long samples lose coherence, repeat themselves, and sometimes contradict themselves. Few-shot performance is weak on natural language inference (ANLI, RTE) and on some reading-comprehension sets. The model is autoregressive, so it cannot look ahead, and the paper does not test bidirectional or denoising objectives. Pretraining is also very sample-inefficient compared with a human. Finally, the authors do not know whether few-shot learning acquires a new task at inference time or recognizes a task seen in training, and inference at this scale is expensive.

Why it mattered

GPT-3 showed that a single pretrained model could be steered by its prompt for many tasks, which made the prompt itself a programming interface. It turned scale into a research strategy. The paper's results shaped the next generation of models that were trained or tuned to follow instructions, and they made the case that large models could be used through an API rather than retrained for each task. The authors themselves name distillation as the route to making models of this size practical.

Reading guide

Read the paper with these lessons in hand, in reading order:

Check yourself

QuestionIn the zero-shot setting, what does the model receive at inference time, and what does it do with the weights?Show answer
The model receives only a natural language description of the task and the new input. No demonstrations are included and the weights are not updated. The model produces its answer by continuing the text.
QuestionUsing the rule of six operations per parameter per token, estimate the training compute for a 175 billion parameter model trained on 300 billion tokens.Show answer
Compute is about 6 times 1.75 times 10 to the 11 times 3 times 10 to the 11, which is about 3.15 times 10 to the 23 FLOPs. This matches the paper's estimate of 3.14 times 10 to the 23.
QuestionWhy do the authors avoid fine-tuning GPT-3 in their main experiments? Give two reasons from the paper.Show answer
First, fine-tuning needs a large labeled dataset for each task, which defeats the goal of task-agnostic use. Second, a fine-tuned model can exploit narrow or spurious patterns in its training data, so its benchmark scores may overstate its general ability. The paper also notes fine-tuning as future work.
QuestionYou have 30 labeled examples for a new sentiment task and access only to a 175B model through a prompt interface, with no training budget. Which setting do you use, and what trade-off do you accept?Show answer
Use few-shot prompting, with the 30 examples as demonstrations, which fit in the 2048-token context if they are short. You accept that few-shot results in the paper are usually below fine-tuned state of the art, and that each request carries the demonstrations, so inference is more expensive than with a fine-tuned model.

Sources

Read the full paper

Tom B. Brown, Benjamin Mann, Nick Ryder et al., 2020. arXiv:2005.14165