Study guide · Language models & AI · 2020

Language Models are Few-Shot Learners

Tom Brown et al. · NeurIPS 2020

Does a language model need to be retrained for every new task, or can you just show it a few examples? This paper scaled GPT-2's recipe up more than a hundredfold, to 175 billion parameters, and found that the model could pick up many tasks from a handful of examples written into its prompt, with no retraining at all. It named this "in-context learning", and it changed how people use language models.

The paper in four sentences

The standard way to get a language model to do a task was to fine-tune it: train it further on thousands of labelled examples of that task.

GPT-3 is a 175-billion-parameter language model trained only to predict the next word, on about 300 billion tokens (word pieces) of text from the web, books and Wikipedia.

Instead of fine-tuning, the authors simply wrote a task description and a few solved examples into the prompt, then asked for one more; the model's weights never change.

This "few-shot" prompting worked surprisingly well, sometimes matching fine-tuned systems, and it got much better with model size, though GPT-3 still failed on some kinds of reasoning and comparison tasks.

Idea · §1 · Fig. 2.1

Zero, one or a few examples in the prompt

A language model continues text: it reads a prompt and predicts what comes next, one small piece (a token, roughly a word fragment) at a time.

The paper tests three ways of asking it to do a task, with no further training in any of them:

  • Zero-shot: just a description, such as "Translate English to French: cheese =>".
  • One-shot: the description plus one solved example, such as "sea otter => loutre de mer", before the question.
  • Few-shot: the description plus several solved examples, usually 10 to 100, as many as fit in the model's 2,048-token window.

The model has to work out from the examples what you want, and then do it. The authors call this in-context learning: "learning" that happens inside a single prompt and is forgotten the moment the prompt ends.

The toy below acts out what this asks of the model. It knows eight possible "rules" for turning a word into something else, and keeps a score of how believable each rule is given the examples so far. Add examples and watch it narrow down.

An illustrative toy. Left: the prompt the model sees. Right: how much the toy believes in each candidate rule after reading the examples (each rule starts equal; a rule that contradicts an example loses almost all of its weight). The first examples of each rule are deliberately ambiguous ("pop" reversed is still "pop"), so one example is not always enough. GPT-3 has no list of rules; this only shows the kind of inference a prompt demands. Later work did describe in-context learning as a form of implicit inference about which task the prompt comes from.
Everyday pictureA new colleague is handed a stack of forms with three already filled in and asked to "do the rest like these". Nobody retrains them; they spot the pattern from the examples and carry on.

TakeawayFew-shot prompting replaces "retrain the model on the task" with "show it a few examples of the task", and the model's weights never change.

Check yourself
What is the difference between few-shot prompting and fine-tuning?
Fine-tuning changes the model's weights by training on many labelled examples. Few-shot prompting puts a few examples in the input text; the weights are untouched and nothing is remembered after the prompt.
Why are there at most about 10 to 100 examples in the few-shot setting?
They have to fit, along with the question, inside the model's context window of 2,048 tokens.

Idea · §2.1–2.3 · Tables 2.1–2.2

Same recipe, much bigger

GPT-3 is not a new design. It is the GPT-2 transformer with one change to how attention is computed, made much larger. The authors trained eight sizes, from 125 million to 175 billion parameters (the adjustable numbers that training tunes). The largest is more than 100 times GPT-2.

All eight read the same 300 billion tokens. The text came mostly from a filtered crawl of the web (Common Crawl), shrunk from 45 TB of compressed text to 570 GB by keeping pages that resembled known good sources and removing near-duplicates. Smaller, higher-quality sources such as Wikipedia and books were shown to the model more often than their size alone would suggest, so it read Wikipedia more than three times over but most of the web crawl less than once.

Training the largest model took roughly 3 × 1023 arithmetic operations, on a cluster of graphics processors provided by Microsoft. That cost is why the authors could not simply retrain when they later found a mistake in their data cleaning (Idea 5).

TakeawayGPT-3's novelty is scale and the way it is used, not a new architecture.

Idea · §3 · Fig. 1.2 · Tables 3.2–3.10

What it could and could not do

The authors tested GPT-3 on more than two dozen benchmarks, plus some new tasks they invented to make sure it could not have seen the answers. Three patterns stand out. Examples help, more examples usually help more, and the benefit of examples grows with model size: big models are much better at learning from the prompt (Fig. 1.2 shows this on a word-unscrambling task).

Choose a view below. All numbers are from the paper, for the 175-billion-parameter model.

LAMBADA (predict the last word of a paragraph) and TriviaQA (answer trivia questions with no documents to look at): accuracy with zero, one and few examples, Tables 3.2–3.3. Arithmetic: few-shot accuracy on two- to five-digit sums and differences, two-digit multiplication and one-digit chains, Table 3.9. Word puzzles: few-shot accuracy on letter-scrambling tasks, Table 3.10.

The arithmetic results were striking in 2020: 100% on two-digit addition, from examples alone. But accuracy falls sharply with more digits. On word puzzles it can undo some scrambling but almost never reverse the letters of a word (0.44%), probably because it sees text as chunks rather than individual letters. In-context learning is real, but it inherits the model's blind spots.

Weak spots the authors report include tasks that compare two sentences (such as deciding whether one follows from the other, where GPT-3 was barely above chance on the hardest test, ANLI) and some reading-comprehension benchmarks.

TakeawayFew-shot GPT-3 was competitive on some benchmarks and poor on others; the consistent pattern was that larger models learn more from examples in the prompt.

Check yourself
On LAMBADA, one-shot was worse than zero-shot (72.5% vs 76.2%), yet few-shot was best (86.4%). What might explain this?
The paper suggests the models need several examples to recognise the unusual fill-in-the-blank format; with only one, the format seems to confuse more than help.
Why might reversing a word's letters be so hard for GPT-3?
Its input is split into multi-letter tokens, so it does not directly see individual letters.

Idea · §3.9.4 · §6

Fake news that people can't spot

The authors asked GPT-3 to write short news articles from a title and subtitle, then asked people to judge whether each article was written by a human or a machine. For the largest model, people were right only about 52% of the time, barely better than tossing a coin. For a deliberately weak control model they were right 86% of the time.

The paper spends a whole section on what this could mean: misinformation, spam, fraudulent academic essays. It also measured biases the model absorbed from the web, for example in how it associates genders, races and religions with particular words, and the energy cost of training.

TakeawayGPT-3's text was fluent enough that people could not reliably tell it from human writing, which the authors flagged as a risk alongside learned social biases.

Idea · §4–5

Caveats: leaked tests and an unclear kind of learning

Leaked test questions. With so much web text, some benchmark questions were bound to be in the training data. The authors tried to remove them, but a bug meant some overlaps were missed, and the model was too expensive to retrain. They checked each benchmark afterwards on "clean" questions only; for most, scores barely changed, but they flagged a few results (such as PIQA and the Winograd test) as possibly inflated.

Learning, or recognising? The authors admit they cannot tell whether few-shot prompting teaches GPT-3 a genuinely new task, or just helps it recognise a task it already met during training. That question shaped years of later research.

Later refinementSeveral of GPT-3's lessons were revised. Chinchilla (2022) showed GPT-3 was trained on far too little data for its size; a smaller model trained on more text does better for the same cost, the bet that LLaMA made. InstructGPT showed that fine-tuning with human feedback, not cleverer prompts, made the model reliably follow requests. And chain-of-thought prompting showed that examples which spell out their reasoning fix many of the arithmetic and reasoning failures seen here.

TakeawayGPT-3 proved prompting works at scale, but left open how much it truly learns from the prompt, and some of its scores carry contamination caveats.

Follow the idea

Built on: Transformer (2017), GPT-2 (2019)

Led to: InstructGPT (RLHF) (2022), Chain of thought (2022), LLaMA (2023)