Active Example Selection for In-Context Learning

Yiming Zhang, Shi Feng, Chenhao Tan

Abstract

In-context learning (ICL) has emerged as a powerful paradigm for leveraging Large Language Models (LLMs), yet it remains notoriously sensitive to the specific examples chosen for a prompt. This sensitivity often results in high performance variance, where the difference between a "good" and "bad" set of examples can determine whether a model succeeds or fails. This paper treats example selection as a sequential decision-making problem, utilizing Reinforcement Learning (RL) to train policies that identify the most effective demonstration examples. By employing Conservative Q-Learning (CQL), the authors demonstrate significant accuracy gains and improved stability across both seen and unseen tasks, providing a more robust framework for ICL.

Introduction

Large Language Models can perform a variety of tasks "out of the box" through in-context learning—simply by providing a few examples within the prompt. However, this performance is incredibly fragile. For models like GPT-2, the gap between the best and worst sets of examples can exceed 30%, sometimes resulting in accuracy lower than random guessing.

Existing mitigation strategies, such as calibration (adjusting for model bias) and reordering (changing the sequence of examples), offer some relief but fail to address the underlying issue: some examples are fundamentally more informative for the model than others. This research moves beyond random selection by "actively" picking the best examples from an unlabeled pool, tailored specifically to the unique idiosyncrasies of how LLMs process in-context information.

Methodology

The authors formulate the challenge of example selection as a Markov Decision Process (MDP), structured as follows:

  • State: The sequence of examples already selected for the prompt.
  • Action: Choosing a new example from an unlabeled pool to be labeled and added to the context.
  • Reward: The marginal increase in accuracy on a validation set.

To solve this MDP, the study employs Conservative Q-Learning (CQL), an offline RL algorithm. CQL is specifically chosen to prevent the model from overestimating the value of "out-of-distribution" actions, ensuring the learned policy remains robust when applied to new, unseen tasks.

Crucially, the policy utilizes minimal features, primarily focusing on the model’s own predicted label probabilities and entropy for a candidate example. This lightweight, model-centric approach ensures that the policy can generalize across different tasks and potentially different model architectures without requiring heavy retraining.

Experimental Setup

The study evaluates the RL policy across four diverse text classification benchmarks:

  1. AGNews: Topic classification (4 classes).
  2. Amazon: Sentiment analysis on reviews (2 classes).
  3. SST-2: Sentiment analysis on movie reviews (2 classes).
  4. TREC: Question type classification (6 classes).

The models tested include GPT-2 (345M) and several GPT-3 variants (Ada, Babbage, and Curie).

Key Insights

The Fragility of ICL

The research confirms that ICL is often a "Wild West" of performance. Simply reordering examples is insufficient; if the initial set of examples is poor, no amount of shuffling will salvage the performance. Furthermore, human intuition regarding "balanced" prompts (e.g., an equal number of positive and negative examples) does not always align with model performance. For instance, on the Amazon dataset, GPT-2 performed better when all demonstration examples were positive.

Emergent Robustness and Scale

As models scale from GPT-2 to GPT-3 variants like Babbage and Curie, they become significantly less sensitive to example selection. While calibration effectively reduces variance in these larger models, it often fails to do so for smaller models like GPT-2, which require more precise example selection to function reliably.

Generalizable Selection Policies

A significant finding is that an RL policy trained on a subset of tasks can successfully identify high-quality examples for a completely unseen task. This suggests the existence of systematic, cross-task patterns that define what makes an example "useful" for a language model's in-context reasoning.

Results

  • Performance Gains: On GPT-2, the RL-based selection improved accuracy by 12.1% over a standard max-entropy active learning baseline on seen tasks.
  • Task Generalization: When applied to brand-new tasks, the policy provided a 5.8% improvement over random selection.
  • Cross-Model Transfer: Policies trained on GPT-2 provided a small (~1%) boost for GPT-3 Ada. However, these gains diminished on larger models like Babbage and Curie, which are inherently more stable.
  • Variance Reduction: Beyond increasing average accuracy, the RL policy significantly narrowed the performance spread, making ICL outcomes much more predictable and reliable.

Conclusion and Future Work

While the RL-based approach offers a clear path toward stabilizing ICL, limitations remain. The study was constrained by the context windows of older models (e.g., GPT-2's 1024 tokens), limiting prompts to $k=4$ examples. Future research should explore how these policies scale with the massive context windows of modern models like GPT-4 or Claude. Additionally, while the policy is effective, the computational cost of generating the thousands of trajectories required for RL training is high. As models continue to grow, understanding why larger architectures are inherently more robust to "bad" examples remains a critical question for the field.

Summary updated

BibTeX
@inproceedings{zhang2022active,
  author = {Yiming Zhang and Shi Feng and Chenhao Tan},
  title = {{Active Example Selection for In-Context Learning}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.emnlp-main.622},
}
Figure