What Makes Good In-Context Examples for GPT-3?
Jiachang LiuDinghan ShenYizhe ZhangBill DolanLawrence CarinWeizhu Chen
Proposes a retrieval-based method to select semantically similar in-context examples for GPT-3, demonstrating that similarity-driven prompt selection dramatically outperforms random sampling across diverse generation and question-answering benchmarks.
Large language models such as GPT-3 have demonstrated impressive capabilities in learning tasks directly from a few prompt examples without requiring model fine-tuning. However, standard deployments typically select these demonstration examples at random, leading to significant performance instability and unpredictable accuracy across different inputs. Because fine-tuning massive models requires prohibitive computational infrastructure and parameter access is often restricted, finding practical, lightweight methods to stabilize and maximize prompt performance is a critical priority for practical deployment.
The article evaluates whether systematically retrieving demonstration examples that are semantically similar to a given query can significantly enhance GPT-3's task performance and reliability. To achieve this, the authors introduce KATE, a non-parametric method that uses separate sentence-embedding models to identify and rank nearest-neighbor examples from available training pools to form the context prompt for each input query.
The approach was evaluated across diverse natural language processing benchmarks, including sentiment analysis on IMDB, structured table-to-text generation on the ToTTo benchmark, and open-domain question answering on the Natural Questions, Web Questions, and TriviaQA datasets. The authors assessed performance against standard random sampling, direct nearest-neighbor baselines without language models, and fully fine-tuned baseline models such as T5.
The key findings reveal substantial, consistent performance gains from semantic example selection. First, retrieving semantically closest neighbors dramatically outperformed random selection and farthest-neighbor baselines across all tasks, boosting exact-match question-answering accuracy on Natural Questions from 28.6% up to 41.6% and table-to-text generation scores from 28.4 to 41.0 BLEU points. Second, augmenting GPT-3 with this retrieval method enabled it to match or exceed the accuracy of dedicated, fully fine-tuned T5 models on complex generation and question-answering benchmarks. Third, qualitative analysis showed that semantically aligned examples substantially reduced factual hallucinations in text generation by providing relevant structural templates. Finally, performance scaled positively with larger example pools and larger prompt context windows, while showing low sensitivity to example ordering.
These results demonstrate that large language models act far more effectively as universal problem solvers when guided by relevant context, circumventing the high financial and storage costs of maintaining specialized fine-tuned checkpoints for distinct tasks. Organizations deploying prompt-based language models should implement nearest-neighbor retrieval pipelines to assemble dynamic prompt contexts, ensuring the embedding retrieval models are aligned with the target domain. While the method delivers strong gains, leaders should note that the approach relies on having accessible labeled candidate data pools and requires managing API inference costs when utilizing larger prompt windows.
- Paper: Language Models are Few-Shot Learners, T. B. Brown et al. (2020). Introduces the GPT-3 foundation model and formalizes the few-shot in-context learning paradigm that this source analyzes and improves upon.
- Paper: Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, Patrick Lewis et al. (2020). Establishes the retrieval-augmented framework for language models that directly inspires using nearest-neighbor retrieval to select prompt examples.
- Paper: Calibrate Before Use: Improving Few-Shot Performance of Language Models, Tony Z. Zhao et al. (2021). Identifies the severe sensitivity and instability of GPT-3 to in-context prompt example selection and ordering, motivating systematic selection strategies.
- Paper: Exploiting Cloze-Questions for Few-Shot Text Classification and Natural Language Inference, Timo Schick et al. (2020). Demonstrates the efficacy of cloze-style prompting and pattern exploitation to elicit latent task knowledge from language models in low-resource settings.
- Paper: Making Pre-trained Language Models Better Few-shot Learners, Tianyu Gao et al. (2021). Pioneers selective semantic demonstration sampling for prompt-based few-shot learners using sentence embeddings.
- Paper: Rethinking the Role of Demonstrations: What Makes In-Context Learning Work?, Sewon Min et al. (2022). Investigates what specific mechanisms make in-context demonstrations effective, challenging assumptions about ground-truth input-label mappings.
- Paper: REPLUG: Retrieval-Augmented Black-Box Language Models, Weijia Shi et al. (2024). Extends retrieval augmentation to black-box large language models through parallel document prompting and retriever tuning.
- Paper: In-Context Retrieval-Augmented Language Models, Ori Ram et al. (2023). Applies non-parametric retrieval directly into the context window of standard, unmodified language models across varied scales.
- Paper: Retrieval-Augmented Generation for Large Language Models: A Survey, Yunfan Gao et al. (2023). Provides a comprehensive taxonomy and evaluation of retrieval-augmented generation paradigms built upon dynamic context selection.
- Paper: Lost in the Middle: How Language Models Use Long Contexts, Nelson F. Liu et al. (2024). Examines how language models utilize information across long context windows, diagnosing positional biases in retrieved context.
- Paper: Self-RAG: Learning to Retrieve, Generate, and Critique through Self-Reflection, Akari Asai et al. (2024). Develops a framework for models to dynamically retrieve, generate, and self-critique contextual passages during inference.
- Paper: Few-Shot Parameter-Efficient Fine-Tuning is Better and Cheaper than In-Context Learning, Haokun Liu et al. (2022). Critiques the sample and compute efficiency of in-context few-shot learning by comparing it against lightweight parameter-efficient fine-tuning.
