# Making Pre-trained Language Models Better Few-shot Learners

Automatic prompts let small language models learn from few examples

Tianyu Gao, Adam Fisch, Danqi Chen · arXiv · 2020-12-31

- **Problem** Standard fine-tuning of masked language models fails with only a few labelled examples per class, because it adds a new classification head to learn. Hand-written prompts avoid this but take domain knowledge and trial and error to design.
- **Method** LM-BFF fine-tunes the model with prompts instead of a new head. It searches label words and generates templates with T5, then adds sampled demonstrations to each input.
- **Results** On SST-2 with 16 examples per class, it reached 93.0 (0.6) against 81.4 (3.8) for standard fine-tuning.

## Why few-shot fine-tuning is hard for masked language models

GPT-3 makes accurate predictions from a natural-language prompt and a few demonstrations without updating its weights, but its 175B parameters make it hard to run in most settings. This study works with models of the BERT and RoBERTa kind, which can be fine-tuned on typical research hardware, and asks how far a small number of labelled examples can carry them.

The training set holds K examples per class, and the main experiments set K = 16 with RoBERTa-large.

Standard fine-tuning puts a randomly initialised classification head on the \[CLS\] representation. On RoBERTa-large a simple binary task adds 2,048 new parameters, which is a lot to learn from around 32 examples. Prompt-based prediction avoids the new head by recasting the task as masked-word prediction, where the model fills a label word into a template.

Good templates take domain knowledge and trial and error, and the authors expect manually written prompts to be suboptimal even when much effort goes into them.

## Prompt-based fine-tuning as masked-word prediction

An input is wrapped by a template T into a sequence that contains one \[MASK\] token. A mapping M assigns each class y to a label word in the vocabulary, so a class is scored by the pre-softmax vector of its label word at the mask position. The probability of class y is a softmax over the label-word scores at the mask hidden state: \\\[ p(y \\mid x\_{in}) = \\frac{\\exp(w\_{M(y)} \\cdot h\_{\[MASK\]})}{\\sum\_{y' \\in Y} \\exp(w\_{M(y')} \\cdot h\_{\[MASK\]})} \\\] Fine-tuning then minimises the cross-entropy loss on the few labelled examples.

The scores reuse the pretrained output vectors, so the approach adds no new parameters. The authors argue that this also narrows the gap between the pre-training objective and fine-tuning, which they expect to help in the few-shot setting. Regression uses the same output machinery. The label range is treated as an interval between two poles, with a prediction written as a mixture of the two poles: \\\[ y = v\_l \\, p(y\_l \\mid x\_{in}) + v\_u \\, p(y\_u \\mid x\_{in}) \\\] Training pushes the predicted weight p(y\_u \| x\_in) toward the normalised target (y - v\_l)/(v\_u - v\_l), using a KL divergence.

## How much the prompt changes accuracy

A pilot on SST-2 and SNLI varies label words and templates with a fixed backbone and few-shot data. With the template fixed on SST-2, great/terrible reached 92.7 (0.9) and terrible/great reached 83.2 (6.9), so label words that match the intended classes do best. The template matters as well: on SNLI, moving \[MASK\] to the end of the input, or swapping the two sentences, produced a drop of more than 10%.

Searching by hand is difficult, because the space is large and a few examples are easy to overfit.

## Searching label words and generating templates

For each class, the label-word search keeps the top k vocabulary words ranked by summed log-probability at the mask over that class's training examples: \\\[ \\text{Top-}k\_{v \\in V} \\Big( \\sum\_{x\_{in} \\in D^{c}\_{train}} \\log P\_L(\[MASK\] = v \\mid T(x\_{in})) \\Big) \\\] Among the pruned assignments, the top n that maximise zero-shot accuracy on Dtrain are fine-tuned, and the best one is picked by re-ranking on Ddev.

The authors note this is simpler than the verbalizer search in earlier PET work, which does not re-rank.

Template generation uses T5, which is pretrained to fill missing spans. Each training example is converted into a T5 input that places a T5 placeholder and the label word around the sentence, so T5 writes the template between those placeholders. Decoding seeks the template that maximises the summed log-likelihood over all converted training examples: \\\[ \\sum\_{(x\_{in},y) \\in D\_{train}} \\log P\_{T5}(T \\mid T\_g(x\_{in}, y)) \\\] Beam search with a wide beam, for example 100, produces many candidates.

Each candidate is fine-tuned on Dtrain and evaluated on Ddev, and either the single best template or the top templates are kept as an ensemble. Training many candidates is fast here because Dtrain is small, and the procedure needs no manual tuning for each dataset.

## Demonstrations as selected context

Here, at each training step one example is sampled per class, converted into a filled template with the mask replaced by its label word, and concatenated after the input: \\\[ T(x\_{in}) \\oplus \\tilde{T}(x^{(1)}\_{in}, y^{(1)}) \\oplus \\cdots \\oplus \\tilde{T}(x^{(\|Y\|)}\_{in}, y^{(\|Y\|)}) \\\] Training and inference both draw several demonstration sets per input, and predictions are ensembled over the sets.

Random demonstrations may be unlike the query, and then the model can ignore them. The similarity variant embeds the raw input sentences with a pretrained SBERT model, without templates. For each query and each class, training instances of that class are ranked by cosine similarity to the query, and only the top r = 50% are sampled as demonstrations.

## Main results with a single prompt

Experiments cover 8 single-sentence and 7 sentence-pair tasks, with RoBERTa-large and K = 16 for the few-shot rows. On SST-2, standard fine-tuning reached 81.4 (3.8), while prompt-based fine-tuning with a manual prompt reached 92.7 (0.9). On SNLI the same two methods reached 48.4 (4.8) and 77.2 (3.7). CoLA is an exception: prompt-based fine-tuning with a manual prompt reached 9.3 (7.3) and standard fine-tuning 33.9 (14.3).

The authors suggest the inputs of this task are out of the distribution the model was trained on. On STS-B, the only regression task, prompt-based fine-tuning with the manual prompt reached 71.0 (7.0) Pearson, against 53.5 (8.5) for standard fine-tuning.

Adding demonstrations helped on most tasks. On MNLI with manual prompts the score rose from 68.3 to 70.7, while on SST-2 with manual prompts it stayed close, at 92.6 (0.5). Combining automatic templates with demonstrations reached 93.0 (0.6) on SST-2 and 77.5 (3.5) on SNLI. The authors report gains of up to 30% absolute and 11% on average across tasks compared with standard fine-tuning.

For in-context learning with RoBERTa-large, the baseline is not a parameter-updating method. On SST-2 it scored 84.8 (1.3) against 83.6 for prompt-based zero-shot prediction, and it did not always beat zero-shot prediction. The authors attribute this to smaller models not being expressive enough to use in-context examples the way GPT-3 does.

## Automatic prompts against manual ones

Some generated pieces look odd: one SNLI template includes the fragment "no" in a biased way, and one generated label word for entailment on SNLI is Hi.

## Ensembles and similarity-based demonstrations

Automatic search can produce as many templates as needed, so individual models can be trained and ensembled. Table 4 compares this with PET's manual prompts on MNLI and RTE. The single manual prompt reached 68.3 (2.3) on MNLI, while PET's four-prompt ensemble reached 71.9 (1.5). An ensemble of 20 automatic templates with demonstrations reached 75.4 (1.6) on MNLI.

The authors note that an ensemble of the same number of automatic templates is comparable to or better than PET's manual ensemble, and that PET's distillation with unlabelled data lies outside their scope.

Table 7 compares uniform sampling of demonstrations with selective sampling by RoBERTa-large or SBERT on four tasks. SBERT-based selection reached 92.6 on SST-2, 79.7 on SNLI, 87.5 on TREC and 77.8 on MRPC, above uniform sampling on all four. RoBERTa-based selection beat uniform sampling on SST-2, SNLI and MRPC but scored 83.4 on TREC against 85.6 for uniform sampling.

Because SBERT was trained on SNLI and MNLI, the authors also tried mean-pooled RoBERTa-large representations, and selective sampling beat uniform sampling in either case.

## Accuracy as K grows

The sweep covers K from 16 up to 256 examples per class. On SST-2, LM-BFF with 32 total examples is close to saturated and comparable to standard fine-tuning on the full dataset. On SNLI, LM-BFF keeps improving as K grows and keeps a gap over standard fine-tuning until the two converge around K = 256. For lower K, the authors say the method consistently outperforms standard fine-tuning.

## Limitations

Results still lag fine-tuning with thousands of examples, especially on harder tasks, and they show high variance across splits as standard fine-tuning does. The authors also find it hard to widen the search space or to generalise the search from about 32 examples.

The method still relies on manual design, either manual templates for the label-word search or manual label words for the template search. The approach suits tasks that can be posed as fill-in-the-blank problems with short inputs and few output classes, and the authors suggest longer-context models may help with input length. Structured prediction is harder to pose this way.

Model development used mainly SST-2 and SNLI, so those two tasks informed design choices.

## Paper info

- **Authors**: Tianyu Gao, Adam Fisch, Danqi Chen
- **Venue**: arXiv · Preprint
- **First published**: 2020-12-31
- **Added**: 2026-11-12
- **Updated**: 2021-6-2
- **Version**: v2
- **arXiv**: 2012.15723
- **Category**: cs.CL · cs.LG
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2012.15723v2) · [PDF ↗](https://arxiv.org/pdf/2012.15723v2)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Tianyu Gao, Adam Fisch, Danqi Chen (2020). Making Pre-trained Language Models Better Few-shot Learners. arXiv:2012.15723v2. https://arxiv.org/abs/2012.15723v2

**BibTeX**

```
@misc{gao2020making,
  title = {{Making Pre-trained Language Models Better Few-shot Learners}},
  author = {Tianyu Gao and Adam Fisch and Danqi Chen},
  year = {2020},
  eprint = {2012.15723},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2012.15723v2}
}
```

## Other paper commentary

- [Evaluating Object Hallucination in Large Vision-Language Models](https://refivu.com/en/papers/994f787c-7b50-4945-8065-0d6a2ea146e6-evaluating-object-hallucination-in-large-vision-language.md)
- [Instruction-Following Evaluation for Large Language Models](https://refivu.com/en/papers/87d7b3e4-5def-4a0c-ac6d-4f0204c38402-instruction-following-evaluation-for-large-language-models.md)
- [Large Language Models: A Survey](https://refivu.com/en/papers/d8a3f692-1bfe-4a26-b530-c20397434b3c-large-language-models-a-survey.md)
- [What Does BERT Look At? An Analysis of BERT's Attention](https://refivu.com/en/papers/8f682775-2bc4-4c36-a7e8-6afc56d2aeae-what-does-bert-look-at-an-analysis-of.md)
- [AutoPrompt: Eliciting Knowledge from Language Models with Automatically Generated Prompts](https://refivu.com/en/papers/e3fa3b73-5b1d-4ff0-8f81-98fad2340fa5-autoprompt-eliciting-knowledge-from-language-models-with.md)
- [DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligence](https://refivu.com/en/papers/a9b5666a-9125-4553-968a-b6f76e0d19db-deepseek-coder-when-the-large-language-model-meets.md)
- [Libra R-CNN: Towards Balanced Learning for Object Detection](https://refivu.com/en/papers/c37a17a8-6ca9-466b-8cf2-8b63070f36bc-libra-r-cnn-towards-balanced-learning-for-object.md)
- [Continual Learning Through Synaptic Intelligence](https://refivu.com/en/papers/443ed68e-4775-416a-b80f-35ef15c63f40-continual-learning-through-synaptic-intelligence.md)
- [BiSeNet V2: Bilateral Network with Guided Aggregation for Real-time Semantic Segmentation](https://refivu.com/en/papers/fe62be3d-2187-471e-93af-db527c65a4a6-bisenet-v2-bilateral-network-with-guided-aggregation-for.md)
- [Evolution Strategies as a Scalable Alternative to Reinforcement Learning](https://refivu.com/en/papers/202e6e5a-1d5b-4899-8cd5-50e1d714f643-evolution-strategies-as-a-scalable-alternative-to.md)
- [Relational Knowledge Distillation](https://refivu.com/en/papers/bc94c76c-131e-4c9c-80c8-1c9bc90a7da4-relational-knowledge-distillation.md)
- [On the Variance of the Adaptive Learning Rate and Beyond](https://refivu.com/en/papers/5e5689e8-3163-4d7b-a0ef-51d1cc8ca1fe-on-the-variance-of-the-adaptive-learning-rate.md)

## Terms in this paper

- [Accuracy](https://refivu.com/en/terms/1995c0cd6282-accuracy)
- [BERT](https://refivu.com/en/terms/45b639a1d317-bert)
- [F1](https://refivu.com/en/terms/a443de87a37a-f1)
- [GPT-3](https://refivu.com/en/terms/d95e818ac9ce-gpt-3)
- [in-context learning](https://refivu.com/en/terms/d53d2af6b551-in-context-learning)
- [SST-2](https://refivu.com/en/terms/8904146eae2e-sst-2)
- [T5](https://refivu.com/en/terms/ae2113eb6c55-t5)
- [regression](https://refivu.com/en/terms/239d667a7188-regression)
- [MPQA](https://refivu.com/en/terms/ddd62f0b54b9-mpqa)
- [MRPC](https://refivu.com/en/terms/54148d717308-mrpc)
- [sBERT](https://refivu.com/en/terms/d551156f28b2-sbert)
- [Uniform Sampling](https://refivu.com/en/terms/573e11f3d903-uniform-sampling)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/58cbc07a-35f5-4401-ada0-4d09082241d1-making-pre-trained-language-models-better-few-shot)
