Language Models are Few-Shot Learners
2020 · NeurIPS · ~11 min read
Read the original paperTrains a 175-billion-parameter language model and tests it on tasks described only in the prompt, with no further training. Read it to see where few-shot prompting works, where it fails, and how benchmark leakage was handled.
In 2019, if a support team wanted to route incoming tickets by topic, the standard recipe was to fine-tune. Take a pretrained model such as BERT, label a few thousand tickets by hand, train a copy of the model on them, evaluate it, and deploy that copy. A second task, say detecting angry customers, meant a second labelled dataset, a second training run and a second copy of the weights to serve. Pretraining had made each task cheaper. It had not removed the per-task cycle of labelling and training.
GPT-3, published by OpenAI in 2020 under the title Language Models are Few-Shot Learners, tested a different workflow. Train one very large language model on general text. Never update its weights again. For each new task, write a short description and a few solved examples into the input, and let the model continue the text. The paper measured how well that works across dozens of benchmarks and eight model sizes, and found that it improves steadily with scale.
This explainer covers what the authors built, how a few-shot prompt is constructed and scored, what in-context learning does and does not mean, and where the paper’s results were strong, weak or compromised. It ends with how to read a 75-page paper without reading all 75 pages.
What the authors built
Architecturally, GPT-3 is GPT-2 made much larger: a decoder-only Transformer, trained to predict the next token. The largest model has 96 layers, a model width of 12,288, 96 attention heads and a context window of 2,048 tokens, for 175 billion parameters. The authors trained eight sizes, from 125 million to 175 billion parameters, on the same data with the same recipe, so that any change in behaviour could be attributed to size.
The training set was about 300 billion tokens, drawn from a mixture of sources that were deliberately not sampled in proportion to their size.
| source | tokens available | share of training mix | times seen in training |
|---|---|---|---|
| Common Crawl (filtered) | 410 billion | 60% | about 0.4 |
| WebText2 | 19 billion | 22% | about 3 |
| Books1 | 12 billion | 8% | about 2 |
| Books2 | 55 billion | 8% | about 0.4 |
| Wikipedia | 3 billion | 3% | about 3.4 |
The last column is the interesting one. Higher-quality sources were repeated several times while most of Common Crawl was never seen even once. The authors were trading quantity for quality, and accepting a little overfitting on the small sources in return.
The compute is easy to check with the rule that training a Transformer costs about 6 floating-point operations per parameter per token: 6 × 175 × 109 × 300 × 109 ≈ 3.15 × 1023. The paper’s appendix gives 3.14 × 1023. Note the ratio, too: 300 billion tokens for 175 billion parameters is under two tokens per parameter. The scaling-laws paper, published four months earlier with an overlapping author list, had recommended exactly this kind of allocation: a very large model, trained on comparatively little data. The final paper in this category explains why that advice was later revised.
Building a few-shot prompt, token by token
The paper defines three settings. Zero-shot gives the model a natural-language description of the task and the input. One-shot adds one solved example. Few-shot adds as many examples as fit in the context window, typically 10 to 100 depending on the task. In all three, the weights are frozen; the only thing that changes is the text.
The context window sets the budget, so it is worth doing the arithmetic. Suppose a sentiment task has an instruction of about 12 tokens, and each worked example (a review and its label) is about 30 tokens. The query takes another 30. That leaves room for (2,048 − 42) / 30 ≈ 66 examples. If the task is summarising news articles of 500 tokens each, the same window holds three examples and the query. Few-shot, in the paper, means “as many as fit”, and for long inputs that is very few.
Change the number of examples and watch what each one does. Give the model only the instruction “Classify the sentiment of each review as positive or negative” followed by “Review: The headphones sound great and arrived early. Sentiment:”. A language model has seen many texts where “Sentiment:” is followed by a label, but also many where it is followed by a sentence, a score out of five, or nothing useful. Zero-shot, the answer may be right in substance and wrong in form. Add one example, ending in “Sentiment: negative”, and the format is pinned down: one lowercase word from a known set. Add more and the model sees both labels, which guards against it simply repeating the one label it has seen. The paper calls zero-shot the most challenging setting for this reason: without an example, even a person can be unsure what format is wanted.
Pick a task and how many worked examples to show. What you see is the entire input: the model's weights do not change, it simply continues the text.
The paper's finding was not that prompting works; it was that it works better the bigger the model, and that the gap between zero-shot and few-shot widens with size. The 175-billion-parameter model is the one that made a prompt a product.
How is the answer read off? For free-form tasks the model generates text, which is compared with the reference. For multiple-choice tasks, which are most of the benchmarks, the paper does not let the model generate at all. It appends each candidate answer to the prompt, computes the likelihood the model assigns to that completion, normalised per token, and picks the most likely. For a few datasets it also divides by the probability of the answer given only a neutral prompt such as “Answer:”, so that answers which are common in general do not win by default. These scoring choices are set out in Section 2.4 and affect the numbers; they are worth knowing before comparing GPT-3’s scores with anyone else’s.
Prompting is not free at inference time. A forward pass costs about 2 floating-point operations per parameter per token, so reading a full 2,048-token prompt with the 175-billion model is about 2 × 175 × 109 × 2,048 ≈ 7 × 1014 operations, every time the task is run. The examples are re-read on every request. A fine-tuned model pays for its examples once, at training time.
Take a few-shot sentiment prompt with eight labelled examples, and replace the labels with random ones (some positive reviews marked negative and vice versa). Does accuracy on the query collapse to chance?
Show the worked answer
For many classification tasks, it barely moves. Min and colleagues tested this in 2022 across a range of models and tasks and found that random labels in the demonstrations cost only a few points in most settings. What mattered more was that the examples showed the right kind of input, the set of possible labels, and the format.
That suggests that, in those settings, the examples mainly tell the model which task it is being asked to do, and the model’s pretrained knowledge does the rest. Later work by Wei and colleagues (2023) found the picture changes with scale: the largest models will follow flipped labels when the examples are consistent, overriding what they already know. So the answer depends on model size, which is the paper’s theme again.
What in-context learning does and does not mean
The paper calls this in-context learning, and the word “learning” causes confusion. Nothing is stored. The weights after the request are the same as before it, and the next request starts with no memory of the examples. What happens is conditioning: the examples change the probabilities the frozen model assigns to its next tokens. The authors frame it as two loops. The outer loop is pretraining, which by exposure to countless patterns of text produces a model that can recognise a task from its description. The inner loop, within a single forward pass, is the model identifying which of those patterns the current prompt is an instance of and continuing it.
That framing predicts the paper’s main figure. If the inner loop depends on how rich the outer loop’s repertoire is, larger models should use examples better. On a simple task of removing random symbols from a word, accuracy for the smallest models hardly rises as examples are added, while for the largest it rises steeply. Across the full benchmark suite, the gap between zero-shot and few-shot widens with model size.
Two practical consequences follow, both found after the paper. First, results depend on details that a learner in the usual sense would ignore. Zhao and colleagues (2021) showed that the order of the examples, and which label appears most often or last, could swing GPT-3’s accuracy on a classification task from near chance to near its best. Second, it is hard to tell whether a few-shot success reflects a skill or a memory. If the benchmark was on the web before the model was trained, the model may have read the answers.
Where scale helped, and where it did not
The results are uneven in instructive ways. On LAMBADA, which asks for the last word of a passage where the whole passage is needed to guess it, few-shot GPT-3 reached 86.4 per cent, against a previous best of 68.0. On closed-book TriviaQA, answering questions with no documents to read, it beat fine-tuned models that were also answering without retrieval. On the other hand, on SuperGLUE as a whole it scored 71.8 few-shot, against 89.0 for the fine-tuned state of the art. On WiC, which asks whether a word means the same thing in two sentences, it was at chance (49.4 per cent). Natural-language inference benchmarks such as ANLI were also near chance for every size but the largest.
The arithmetic tasks show the same pattern when we change one variable at a time. The prompt format stays fixed; only the number of digits changes.
| task, 175B model, few-shot | accuracy |
|---|---|
| 2-digit addition | 100.0% |
| 3-digit addition | 80.4% |
| 4-digit addition | 25.5% |
| 5-digit addition | 9.3% |
| 2-digit multiplication | 29.2% |
The authors checked whether the model was recalling sums from its training data by searching it for the test problems, and found only a small fraction present. The errors were also informative: failed answers often looked like a carry had been dropped, which is what a partial procedure would produce, not a lookup. But a procedure that works for two digits and fails for five is not the procedure a person learns at school. The model had found something that worked on short problems, and it did not extend.
One more result became a headline. People asked to tell 200-word news articles written by the 175-billion model from real ones were right about 52 per cent of the time, barely above guessing. The authors put that finding in their broader-impacts section, next to an analysis of gender, race and religion associations in the model’s outputs, and an estimate of training energy.
The contamination problem, walked through
Benchmark contamination is the clearest example in the paper of something going wrong, and of a fix that cost something. The training data was 300 billion tokens of web text, and many benchmarks’ test sets were on the web. The authors tried to remove overlaps before training. After training, they found a bug in that filtering: some overlaps had stayed in. Retraining a model that cost over 3 × 1023 operations was not an option.
So they measured the damage instead. For each benchmark they built a “clean” subset by dropping every test example that shared a 13-token sequence with the training data, then compared the model’s score on the clean subset with its score on the full set. If the model was reciting memorised answers, it should do much worse on the clean subset. For most benchmarks the difference was small. For a few, the authors flagged the results with an asterisk or dropped them, and they discussed specific cases in Section 4.
The cost of the fix is that it is an argument rather than a proof. A 13-token overlap filter misses paraphrases and translations of test items, and a clean subset may be easier or harder than the full set for reasons unrelated to contamination. The authors say as much. Every large-model paper since has had to make the same argument, usually with less candour.
What it cost, and what later work added
Holding 175 billion parameters in 16-bit precision takes 350 GB, more than any single GPU of 2020 could store, so even inference needed a cluster of cards. The authors were open about the limitations in Section 5: the model repeated itself over long passages, contradicted itself, struggled with some kinds of common-sense physics, and showed the biases of its training text.
The step that turned GPT-3 into a product was training it to follow instructions. OpenAI’s InstructGPT paper (2022) fine-tuned GPT-3 on human demonstrations and then on human preference rankings, and found that people preferred the outputs of a 1.3-billion-parameter instruction-tuned model to those of the raw 175-billion model. Chain-of-thought prompting, also from 2022, found that including worked reasoning in the few-shot examples improved multi-step problems like the arithmetic above. Both build on this paper’s observation that the prompt shapes behaviour; both also show the raw few-shot setting was far from the best a model of this size could do.
When prompting is the wrong tool
Few-shot prompting is the right first move when there are few labelled examples, many tasks, or a need to change the task by editing text. It is the wrong final answer when volume is high and the task is fixed. Every request re-reads the examples, so a prompt with 1,500 tokens of examples pays for those tokens millions of times; a smaller fine-tuned model can be cheaper and faster per request and often more accurate on a narrow task. Prompting is also fragile in ways the user cannot see: reorder the examples, change the label words, or move to a new model version, and accuracy can shift. If a decision depends on the output, measure it on a held-out set, as the paper did, rather than trusting a few good-looking answers.
How to read the original
The paper is about 75 pages including appendices. Read Section 1 and its three figures first; Figure 1.2 is the clearest picture of in-context learning improving with scale. Then read Section 2 in full, especially 2.1 on the three settings and 2.4 on how answers are scored. Table 2.1 lists the eight model sizes, and Table 2.2 the data mix.
Section 3 is long. Pick a few subsections rather than reading it straight through: 3.1 for LAMBADA, 3.2 for closed-book question answering, 3.9 for the arithmetic and word-scrambling tasks, and 3.9.4 for the news-article study. Look at the figures that plot accuracy against model size for each setting; the shape of the curves says more than any single number. Then read Section 4 on contamination and Section 5 on limitations in full. Appendix G contains the exact prompt for every task, and is the most practically useful part of the paper if you write prompts for a living.
GPT-3’s argument rests on the claim that scale keeps paying. The next paper, Scaling Laws for Neural Language Models, is where that claim was measured, written by several of the same authors a few months earlier, and later corrected in a way that changed how models are built.
The original. Read it after this page; the explainer above is a map, not a substitute.
A short animated explanation of what the model does with your prompt.
The bigger picture of what a GPT-style model computes, token by token.