What Makes Good In-Context Examples for GPT-$3$?
Authors: Jiachang Liu, Dinghan Shen, Yizhe Zhang, Bill Dolan, Lawrence Carin, Weizhu Chen
Abstract
GPT-$3$ has attracted lots of attention due to its superior performance across a wide range of NLP tasks, especially with its powerful and versatile in-context few-shot learning ability. Despite its success, we found that the empirical results of GPT-$3$ depend heavily on the choice of in-context examples. In this work, we investigate whether there are more effective strategies for judiciously selecting in-context examples (relative to random sampling) that better leverage GPT-$3$'s few-shot capabilities. Inspired by the recent success of leveraging a retrieval module to augment large-scale neural network models, we propose to retrieve examples that are semantically-similar to a test sample to formulate its corresponding prompt. Intuitively, the in-context examples selected with such a strategy may serve as more informative inputs to unleash GPT-$3$'s extensive knowledge. We evaluate the proposed approach on several natural language understanding and generation benchmarks, where the retrieval-based prompt selection approach consistently outperforms the random baseline. Moreover, it is observed that the sentence encoders fine-tuned on task-related datasets yield even more helpful retrieval results. Notably, significant gains are observed on tasks such as table-to-text generation (41.9% on the ToTTo dataset) and open-domain question answering (45.5% on the NQ dataset). We hope our investigation could help understand the behaviors of GPT-$3$ and large-scale pre-trained LMs in general and enhance their few-shot capabilities.
The papers around it, by date and closeness
Higher is closer to this paper; left is older. Lines join papers close to each other: groups of lines are sub-topics. Select a point to see why it is there. Back to the summary of this paper
Papers around this one
Ranked by how close their title and abstract are to this paper’s. Select some to read them together.
Closest papers
-
Calibrate Before Use: Improving Few-Shot Performance of Language ModelsTony Z. Zhao, Eric Wallace, Shi Feng et al. · 2021 · Computation and Language · cited 2,193 times · Not summarized yet
Calibrate Before Use reduces few-shot instability by correcting answer biases, while this paper selects semantically similar examples for GPT-3 prompts.
Abstract
GPT-3 can perform numerous tasks when provided a natural language prompt that contains a few training examples. We show that this type of few-shot learning can be unstable: the choice of prompt format, training examples, and even the order of the training examples can cause accuracy to vary from near chance to near state-of-the-art. We demonstrate that this instability arises from the bias of language models towards predicting certain answers, e.g., those that are placed near the end of the prompt or are common in the pre-training data. To mitigate this, we first estimate the model's bias towards each answer by asking for its prediction when given the training prompt and a content-free test …
-
Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder et al. · 2020 · Computation and Language · cited 65,949 times · AI summary available
Language Models are Few-Shot Learners establishes GPT-3's few-shot prompting capabilities that this paper seeks to improve through example retrieval.
Abstract
Recent work has demonstrated substantial gains on many NLP tasks and benchmarks by pre-training on a large corpus of text followed by fine-tuning on a specific task. While typically task-agnostic in architecture, this method still requires task-specific fine-tuning datasets of thousands or tens of thousands of examples. By contrast, humans can generally perform a new language task from only a few examples or from simple instructions - something which current NLP systems still largely struggle to do. Here we show that scaling up language models greatly improves task-agnostic, few-shot performance, sometimes even reaching competitiveness with prior state-of-the-art fine-tuning approaches. Spec…
-
GPT-4 In-Context Learning Ability with Semantico-Syntactically Similar Examples in RussianTimofei Plotnikov · 2025 · Mundo Eslavo · Not summarized yet
GPT-4 In-Context Learning Ability with Semantico-Syntactically Similar Examples in Russian uses similar-example prompting to improve GPT-4 performance on Russian phrases and sentences.
Abstract
In zero-shot performance with a dataset of over 2,200 Russian phrases and sentences, GPT-4 encounters difficulties to correctly identify the meaning of some examples. Therefore, the "problematic" examples are chosen for further investigation. To address these challenges, the in-context learning ability employed in GPTs can be utilized to enhance unsuccessful performance. This approach presumes providing semantico-syntactically similar examples beforehand. The experiment demonstrates that even with just one in-context example, GPT-4’s performance becomes more robust across nearly all problematic examples. However, the examples that remain misinterpreted potentially reveal that the model can u…
-
Making Pre-trained Language Models Better Few-shot LearnersTianyu Gao, Adam Fisch, Danqi Chen · 2021 · Annual Meeting of the Association for Computational Linguistics · cited 2,387 times · Not summarized yet
Making Pre-trained Language Models Better Few-shot Learners improves few-shot performance by fine-tuning smaller models with automated prompts, rather than retrieving GPT-3 demonstrations.
Abstract
The recent GPT-3 model (Brown et al., 2020) achieves remarkable few-shot performance solely by leveraging a natural-language prompt and a few task demonstrations as input context. Inspired by their findings, we study few-shot learning in a more practical scenario, where we use smaller language models for which fine-tuning is computationally efficient. We present LM-BFF—better few-shot fine-tuning of language models—a suite of simple and complementary techniques for fine-tuning language models on a small number of annotated examples. Our approach includes (1) prompt-based fine-tuning together with a novel pipeline for automating prompt generation; and (2) a refined strategy for dynamically an…
-
Prompt Programming for Large Language Models: Beyond the Few-Shot ParadigmLaria Reynolds, Kyle McDonell · 2021 · Computation and Language · cited 1,458 times · AI summary available
Prompt Programming for Large Language Models examines how prompts and few-shot examples affect GPT-3 task performance, including cases where zero-shot prompts do better.
Abstract
Prevailing methods for mapping large generative language models to supervised tasks may fail to sufficiently probe models' novel capabilities. Using GPT-3 as a case study, we show that 0-shot prompts can significantly outperform few-shot prompts. We suggest that the function of few-shot examples in these cases is better described as locating an already learned task rather than meta-learning. This analysis motivates rethinking the role of prompts in controlling and evaluating powerful language models. In this work, we discuss methods of prompt programming, emphasizing the usefulness of considering prompts through the lens of natural language. We explore techniques for exploiting the capacity …
-
Active Example Selection for In-Context LearningYiming Zhang, Feng Shi, Chenhao Tan · 2022 · Conference on Empirical Methods in Natural Language Processing (EMNLP) · cited 100 times · Not summarized yet
Active Example Selection for In-Context Learning learns example-selection policies with reinforcement learning, whereas this paper retrieves semantically similar examples.
Abstract
With a handful of demonstration examples, large-scale language models show strong capability to perform various tasks by in-context learning from these examples, without any finetuning.We demonstrate that in-context learning performance can be highly unstable across samples of examples, indicating the idiosyncrasies of how language models acquire information.We formulate example selection for in-context learning as a sequential decision problem, and propose a reinforcement learning algorithm for identifying generalizable policies to select demonstration examples.For GPT-2, our learned policies demonstrate strong abilities of generalizing to unseen tasks in training, with a 5.8% improvement o…
-
Learning To Retrieve Prompts for In-Context LearningOhad Rubin, Jonathan Herzig, Jonathan Berant · 2022 · Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies ( · cited 375 times · Not summarized yet
Learning To Retrieve Prompts for In-Context Learning trains a retrieval method to select demonstrations, extending retrieval-based prompt selection to labeled examples and an LM.
Abstract
In-context learning is a recent paradigm in natural language understanding, where a large pretrained language model (LM) observes a test instance and a few training examples as its input, and directly decodes the output without any update to its parameters.However, performance has been shown to strongly depend on the selected training examples (termed prompts).In this work, we propose an efficient method for retrieving prompts for in-context learning using annotated data and an LM.Given an inputoutput pair, we estimate the probability of the output given the input and a candidate training example as the prompt, and label training examples as positive or negative based on this probability.We …
-
Structured Prompting: Scaling In-Context Learning to 1,000 ExamplesYaru Hao, Yutao Sun, Li Dong et al. · 2022 · Computation and Language · preprint, not peer reviewed · cited 110 times · AI summary available
Structured Prompting scales in-context learning by encoding and jointly attending to many demonstrations, rather than selecting similar examples for each test input.
Abstract
Large language models have exhibited intriguing in-context learning capability, achieving promising zero- and few-shot performance without updating the parameters. However, conventional in-context learning is usually restricted by length constraints, rendering it ineffective to absorb supervision from a large number of examples. In order to go beyond few shots, we introduce structured prompting that breaks the length limit and scales in-context learning to thousands of examples. Specifically, demonstration examples are separately encoded with well-designed position embeddings, and then they are jointly attended by the test example using a rescaled attention mechanism. So we can scale the num…
Prior work it builds on
-
Retrieval-Augmented Generation for Knowledge-Intensive NLP TasksPatrick Lewis, Ethan Perez, Aleksandra Piktus et al. · 2020 · Neural Information Processing Systems · cited 20,475 times · AI summary available
Retrieval-Augmented Generation adds external memory to pretrained language models for knowledge-intensive tasks, while this paper retrieves demonstrations to construct prompts.
Abstract
Large pre-trained language models have been shown to store factual knowledge in their parameters, and achieve state-of-the-art results when fine-tuned on downstream NLP tasks. However, their ability to access and precisely manipulate knowledge is still limited, and hence on knowledge-intensive tasks, their performance lags behind task-specific architectures. Additionally, providing provenance for their decisions and updating their world knowledge remain open research problems. Pre-trained models with a differentiable access mechanism to explicit non-parametric memory can overcome this issue, but have so far been only investigated for extractive downstream tasks. We explore a general-purpose …
-
Generation-Augmented Retrieval for Open-Domain Question AnsweringYuning Mao, Pengcheng He, Xiao-Dong Liu et al. · 2020 · Annual Meeting of the Association for Computational Linguistics · cited 334 times · Not summarized yet
Generation-Augmented Retrieval improves open-domain question answering by generating query contexts for retrieval, whereas this paper retrieves examples to prompt GPT-3.
Abstract
We propose Generation-Augmented Retrieval (GAR) for answering open-domain questions, which augments a query through text generation of heuristically discovered relevant contexts without external resources as supervision. We demonstrate that the generated contexts substantially enrich the semantics of the queries and GAR with sparse representations (BM25) achieves comparable or better performance than state-of-the-art dense retrieval methods such as DPR. We show that generating diverse contexts for a query is beneficial as fusing their results consistently yields better retrieval accuracy. Moreover, as sparse and dense representations are often complementary, GAR can be easily combined with D…
-
Response Generation by Context-aware Prototype EditingYu Wu, Furu Wei, Shao-Han Huang et al. · 2018 · AAAI Conference on Artificial Intelligence · cited 128 times · Not summarized yet
Response Generation by Context-aware Prototype Editing retrieves and edits prototype responses for dialogue generation, rather than retrieving in-context demonstrations for GPT-3.
Abstract
Open domain response generation has achieved remarkable progress in recent years, but sometimes yields short and uninformative responses. We propose a new paradigm, prototypethen-edit for response generation, that first retrieves a prototype response from a pre-defined index and then edits the prototype response according to the differences between the prototype context and current context. Our motivation is that the retrieved prototype provides a good start-point for generation because it is grammatical and informative, and the post-editing process further improves the relevance and coherence of the prototype. In practice, we design a contextaware editing model that is built upon an encoder…
-
A Retrieve-and-Edit Framework for Predicting Structured OutputsTatsunori B. Hashimoto, Kelvin Guu, Yonatan Oren et al. · 2018 · Neural Information Processing Systems · cited 191 times · Not summarized yet
A Retrieve-and-Edit Framework retrieves training examples and edits their structured outputs, while this paper uses retrieved examples as GPT-3 prompt demonstrations.
Abstract
For the task of generating complex outputs such as source code, editing existing outputs can be easier than generating complex outputs from scratch. With this motivation, we propose an approach that first retrieves a training example based on the input (e.g., natural language description) and then edits it to the desired output (e.g., code). Our contribution is a computationally efficient method for learning a retrieval model that embeds the input in a task-dependent way without relying on a hand-crafted metric or incurring the expense of jointly training the retriever with the editor. Our retrieve-and-edit framework can be applied on top of any base model. We show that on a new autocomplete…
-
GLUE: A Multi-Task Benchmark and Analysis Platform for Natural Language UnderstandingAlex Wang, Amanpreet Singh, Julian Michael et al. · 2018 · BlackboxNLP@EMNLP · cited 9,221 times · AI summary available
GLUE provides a multi-task natural language understanding benchmark, a type of evaluation resource relevant to this paper's NLP benchmark experiments.
Abstract
Human ability to understand language is general, flexible, and robust. In contrast, most NLU models above the word level are designed for a specific task and struggle with out-of-domain data. If we aspire to develop models with understanding beyond the detection of superficial correspondences between inputs and outputs, then it is critical to develop a unified model that can execute a range of linguistic tasks across different domains. To facilitate research in this direction, we present the General Language Understanding Evaluation (GLUE, gluebenchmark.com): a benchmark of nine diverse NLU tasks, an auxiliary dataset for probing models for understanding of specific linguistic phenomena, and…
Papers that cite it
-
Fantastically Ordered Prompts and Where to Find Them: Overcoming Few-Shot Prompt Order SensitivityYao Lu, Max Bartolo, Alastair P. Moore et al. · 2022 · Proceedings of the conference - Association for Computational Linguistics. Meeting · cited 610 times · Not summarized yet
Fantastically Ordered Prompts studies sensitivity to demonstration order in GPT-3, while this paper focuses on which examples to select.
Abstract
When primed with only a handful of training samples, very large, pretrained language models such as GPT-3 have shown competitive results when compared to fully-supervised, finetuned, large, pretrained language models.We demonstrate that the order in which the samples are provided can make the difference between near state-of-the-art and random guess performance: essentially some permutations are "fantastic" and some not.We analyse this phenomenon in detail, establishing that: it is present across model sizes (even for the largest current models), it is not related to a specific subset of samples, and that a given good permutation for one model is not transferable to another.While one could u…
-
Rethinking the Role of Demonstrations: What Makes In-Context Learning Work?Sewon Min, Xinxi Lyu, Ari Holtzman et al. · 2022 · Conference on Empirical Methods in Natural Language Processing (EMNLP) · cited 755 times · Not summarized yet
Rethinking the Role of Demonstrations tests which features of demonstrations drive in-context learning, while this paper evaluates selecting semantically similar examples.
Abstract
Large language models (LMs) are able to incontext learn-perform a new task via inference alone by conditioning on a few input-label pairs (demonstrations) and making predictions for new inputs.However, there has been little understanding of how the model learns and which aspects of the demonstrations contribute to end task performance.In this paper, we show that ground truth demonstrations are in fact not required-randomly replacing labels in the demonstrations barely hurts performance on a range of classification and multi-choce tasks, consistently over 12 different models including GPT-3.Instead, we find that other aspects of the demonstrations are the key drivers of end task performance, …
-
Self-Adaptive In-Context Learning: An Information Compression Perspective for In-Context Example Selection and OrderingZhiyong Wu, Yaoxiang Wang, Jiacheng Ye et al. · 2023 · Proceedings of the conference - Association for Computational Linguistics. Meeting · cited 74 times · Not summarized yet
Self-Adaptive In-Context Learning selects and orders examples through a select-then-rank framework, whereas this paper retrieves semantically similar examples.
Abstract
Despite the impressive few-shot performance of in-context learning (ICL), it remains a common practice to randomly select examples to serve as the context.In this paper, we advocate self-adaptive in-context learning, a new principle for ICL, in which the self-adaption mechanism is introduced to help each input find an in-context example organization (i.e., selection and permutation) that can derive the correct output, thus maximizing performance.To validate the effectiveness of self-adaptive ICL, we propose a general select-then-rank framework and a set of novel selection and ranking algorithms.Upon extensive evaluation on eight different NLP datasets, our self-adaptive ICL method achieves a…
-
Self-Improving In-Context LearningBaturay Saglam, Dionysis Kalogerias · 2026 · arXiv.org · preprint, not peer reviewed · Not summarized yet
Self-Improving In-Context Learning optimizes prompt embeddings at test time, rather than retrieving examples to improve few-shot prompting.
Abstract
We propose to improve in-context learning (ICL) by optimizing the continuous embeddings of a fixed few-shot prompt at test time. The key observation is that the log-probabilities a model assigns to its demonstrated outputs$\unicode{x2013}$available from a single forward pass without generating any tokens$\unicode{x2013}$provide a meaningful signal for how well the model has inferred the task from its demonstrations. We formalize this signal as a bounded, self-supervised confidence proxy and maximize it via zeroth-order optimization over the prompt embeddings, yielding a test-time calibration procedure. The approach requires no finetuning, no token generation, no predefined label set, and no …
-
Improving few-shot stance detection with MINE: meta-prompting and in-context N-shot examplesUwaila Ekhator, Francesca Spezzano · 2026 · International Journal of Data Science and Analysis · Not summarized yet
MINE uses semantically retrieved examples in prompts for stance detection, applying retrieval-augmented in-context learning to a specific task.
Abstract
Stance detection aims to identify an author’s stance toward a target topic. Although recent prompting-based methods enable zero- and few-shot stance detection with large language models (LLMs), they often require extensive prompting or costly use of multiple LLM agents, as well as large labeled training datasets. We present MINE (Meta-prompting and In-context N-shot Examples), a simple, light-weight, training-free framework that first creates a target-specific LLM stance agent through meta-prompting, and then augments it with a small number of semantically retrieved examples. While meta-prompting and retrieval-augmented in-context learning have been studied independently, these components ha…
Go further
How are these papers found?
We compare the title and abstract of this paper with those of every paper summarized on this site, and with the papers Semantic Scholar recommends, those it cites and those citing it (for a much-cited paper, its most recent citations and, from OpenAlex, the most cited ones). Among the prior work and the follow-ups, the papers that use each other in depth, a method it uses and the much-cited follow-ups come a little higher. The levels (very close, close, related) come from the similarity of the texts, not from a judgment of quality; * marks a paper without an abstract, compared by its title. The sentence under a paper is written by an AI from the two abstracts: check it in the papers. A paper marked not relevant by three readers leaves the list.
Updated on 2 November 2026.