AI & Machine Learning · Paper 04 / 05

Language Models are Few-Shot Learners

Tom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, et al.

2020 · NeurIPS · ~12 min read

Read the original paper

Every new task used to need a new training run. GPT-3 showed that a large enough model learns a task from a few examples typed into its prompt, which is the interface you use today.

The problem: a new training run for every task

By 2019 the recipe for language tasks was settled: pretrain a Transformer on a large corpus, then fine-tune a copy of it on thousands of labelled examples for each task you cared about. It worked well and it did not scale as a way of working. Every task needed a dataset, a training run and its own copy of the weights; the labelled data was often the bottleneck; and a model tuned for one task forgot how to do the others. People, by contrast, pick up a new task from a sentence of instruction and a couple of examples. GPT-2 had hinted that a big enough language model might too.

2018–2019 · fine-tuningpretrained modelfine-tune: translatethousands of labelled examples, a new copy of the weightsfine-tune: sentimentthousands of labelled examples, a new copy of the weightsfine-tune: Q&Athousands of labelled examples, a new copy of the weightsGPT-3 · promptingone frozen model · 175Bprompt: translateprompt: sentimentprompt: Q&A
Two workflows. Fine-tuning produces a specialised copy of the model per task from labelled data. Prompting keeps one frozen model and describes the task in its input.

The idea: make the model large enough that the prompt is the program

The authors trained a decoder-only Transformer with 175 billion parameters, ten times larger than anything before it, on about 300 billion tokens of filtered web text, books and Wikipedia, and then never updated its weights again. Instead they evaluated it by in-context learning: writing the task into the prompt, either as an instruction alone (zero-shot), one worked example (one-shot), or a handful (few-shot, up to what fits in the 2,048-token context). The model continues the text, and continuing it correctly is the task.

How it works

The paper is mostly measurement. Eight models from 125 million to 175 billion parameters were trained the same way and tested on more than two dozen benchmarks in each of the three prompting modes, and the headline chart shows two things at once: accuracy rises steadily with size, and the benefit of adding examples to the prompt rises with size too. The small models barely use the examples; the large one reads them like instructions.

0.1B1B10B175Baccuracyfew-shotone-shotzero-shotschematic of the paper’s aggregate result, not a plot of its numbers
The paper’s central result, schematically. All three prompting modes improve with scale, and the gap between zero-shot and few-shot widens: larger models are better at reading the examples.
Try itTeach a task without training

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.

Classify the sentiment of each review as positive or negative. Review: The pasta was cold and the service slow. Sentiment: negative Review: Lovely room, kind staff, would stay again. Sentiment: positive Review: The headphones sound great and arrived early. Sentiment: ▌
modefew-shotthe examples set the format and the task; nothing is fine-tuned
prompt tokens, roughly68GPT-3’s context held 2,048
the eight models the paper trained · parameters on a log scale
GPT-3 Small125M · 12 layers · d=768Medium350M · 24 layers · d=1024Large760M · 24 layers · d=1536XL1.3B · 24 layers · d=20482.7B2.7B · 32 layers · d=25606.7B6.7B · 32 layers · d=409613B13B · 40 layers · d=5140GPT-3 175B175B · 96 layers · d=12288

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.

Some of the results surprised the authors. The largest model did two-digit addition nearly perfectly from a few examples, unscrambled words, translated between languages it had seen mostly incidentally, and wrote news articles that human readers identified as machine-written only slightly better than chance. Others were honest failures: common-sense reasoning benchmarks and some reading-comprehension tasks stayed well behind fine-tuned systems, and the paper devotes a section to the bias the model absorbed from the web and the energy its training consumed.

modewhat the prompt containswhat changes in the model
fine-tuningnothing special; the task is in the weightsall of them, per task
zero-shotan instructionnothing
one-shotan instruction and one examplenothing
few-shotan instruction and several examplesnothing

What it changed

GPT-3 turned a model into an interface. OpenAI exposed it through an API weeks after the paper, and “prompt engineering” became a job description; the instruction-following training that produced ChatGPT two years later was built on exactly this model and exactly this observation. The scaling thesis, that capability keeps arriving with size, set the research agenda and the capital expenditure of the field for the years that followed, and the next paper on this list is the measurement that justified it.

Where you meet it today

  • Every chat and copilot product. A system prompt plus examples is few-shot prompting with a nicer interface.
  • Prompt templates in code. The f-string with three examples in it is this paper, in production.
  • Evaluation by prompting. Benchmarks now report zero- and few-shot numbers by default because this paper did.
  • The debate about what in-context learning is, which is still open and still shapes how models are trained.