In-context Example Selection with Influences

Tai Nguyen, Eric WongarXiv 2023 · DOI

Abstract

Large Language Models (LLMs) are highly sensitive to the specific examples provided in their prompts. This paper introduces in-context influences, a method to quantify the causal impact of individual examples on model performance. By ranking examples based on their influence, the authors demonstrate a significant performance gap—up to 16.3%—between the "best" and "worst" prompts. The results show that influence-based selection consistently outperforms standard heuristics like semantic similarity and perplexity.

Introduction

In-context learning (ICL) allows LLMs to perform tasks by observing a few labeled examples in a prompt. However, ICL is notoriously "brittle"; performance can fluctuate wildly based on which examples are chosen, their order, and the formatting template used. While researchers have attempted to stabilize ICL using semantic similarity or perplexity, there is no consensus on what makes an example "good." This paper moves beyond these heuristics to directly measure the causal impact of an example on a model's success.

Methodology: Quantifying Influence

The authors adapt "retraining-based influence" techniques to the training-free world of ICL. Their approach, Algorithm 1, operates in three main steps:

  1. Subset Collection: A small "training" set of labeled examples is used to generate random subsets (e.g., 8 examples from a pool of 400). The model's accuracy is recorded on a validation set for each random prompt.
  2. Influence Calculation: The influence of a specific example $x$ is calculated by comparing the average performance of prompts that included $x$ versus those that omitted it.
  3. Selection: At inference time, the $k$ examples with the highest positive influence scores are selected to build the final prompt.

Because ICL does not require gradient updates, this process is significantly cheaper than traditional influence methods, requiring only forward passes (inference).

Experimental Setup

The method was evaluated across 72 combinations of models and tasks:

  • Models: GPT-J (6B), GPT-NeoX (20B), the OPT family (6.7B to 30B), and the LLaMA family (7B and 13B).
  • Tasks: 9 diverse benchmarks including binary classification (e.g., RTE, WIC) and multi-choice tasks (e.g., ARC, Hellaswag, OpenBookQA).
  • Setup: Subsampled sets of 400 training, 200 validation, and 500 test examples were used for each task.

Results and Analysis

The Performance Gap

The most striking finding is the extreme variance in example quality. As shown in Figure 1, using examples from higher influence percentiles leads to marked improvements in test accuracy across various tasks and models. For instance, on the OpenBookQA task using LLaMA-13B, the "most positive" influence examples resulted in a 16.3% higher accuracy than the "most negative" ones.

Test accuracy across percentile bins of influence scores for various models and tasks.

Characteristics of Influence

Influence scores appear to capture a unique signal about model behavior. Surprisingly, an example's influence has zero correlation with its length, perplexity, or semantic similarity to the test query. Furthermore, while models within the same family (e.g., LLaMA-7B and LLaMA-13B) tend to agree on influential examples, there is very little agreement across different families (e.g., OPT vs. LLaMA), suggesting that "good" examples are highly model-dependent.

Comparative Performance

Influence-based selection consistently outperformed all baselines, including random selection, semantic similarity, and perplexity-based selection. Across all tasks, the influence-based method achieved the lowest (best) average rank aggregation.

Performance comparison of influence-based selection against baselines on the OPT-30B model.

Discussion and Limitations

The framework also provides a mathematical way to quantify "recency bias"—the tendency of models to be more influenced by examples placed at the end of a prompt. Absolute influence scores were found to be significantly higher for examples in the final position of a 4-shot prompt.

Despite its effectiveness, the method has limitations:

  • Offline Requirement: It requires a labeled development set to run experiments before identifying the best examples.
  • Computational Overhead: It still requires thousands of forward passes to obtain accurate influence estimates.
  • Task Scope: The study focused on classification and multiple-choice tasks; future work should extend this to generative tasks like summarization.

Summary updated

BibTeX
@misc{nguyen2023context,
  author = {Tai Nguyen and Eric Wong},
  title = {{In-context Example Selection with Influences}},
  year = {2023},
  eprint = {2302.11042},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2302.11042},
}
Figure