Auto-regressive In-context Demonstration Selection

Yunzhe Qi, Sirui Chen, Jiaru Zou, Jingrui He

Introduction

In-Context Learning (ICL) empowers Large Language Models (LLMs) to tackle novel tasks simply by observing a few "demonstrations" (input-output pairs) in their prompt. However, LLMs are notoriously sensitive to both the content and the order of these examples. Because of phenomena like recency bias—where the final example in a prompt exerts disproportionate influence—selecting the optimal $k$ demonstrations from a pool of $N$ candidates is a complex combinatorial challenge.

Most existing methods rely on simple semantic similarity or treat the set of examples as order-independent, ignoring the compositional effects of how the query and examples interact. To address this, researchers introduce AutoSelect, a novel framework that formulates demonstration selection as an auto-regressive sequential decision process, identifying both the best content and the optimal ordering to maximize LLM performance.

The AutoSelect Framework

AutoSelect mirrors the step-by-step generation process of LLMs themselves. Instead of retrieving a batch of examples simultaneously, it selects them sequentially. At each step, the model evaluates the query alongside previously chosen demonstrations to pick the next best exemplar.

Key components of the methodology include:

  • Matrix Embeddings & ViT Policy: Rather than flattening text into a single vector (which strips structural information), AutoSelect represents each example as a 2D matrix (tokens $\times$ embedding dimensions). A Vision Transformer (ViT) acts as the policy model, processing these matrices to capture complex inter-token and inter-exemplar relationships.
  • Adaptive Stopping: The model incorporates an "End-of-Sequence" (EOS) signal. This allows it to dynamically determine the optimal prompt length and halt selection when adding more examples would degrade performance.
  • Plackett-Luce Alignment & Tractable Training: To navigate the factorial space of permutations, the framework formulates a Kullback-Leibler (KL)-regularized optimization problem. The authors prove that minimizing a specific policy-level cross-entropy (CE) loss bounds the worst-case discrepancy between the learned policy and the theoretical optimal Plackett-Luce (PL) ranking. This ensures stable and effective training based on sequence-level rewards (i.e., how well the LLM actually performed).

Experimental Setup

The researchers evaluated AutoSelect across nine diverse datasets spanning multiple capabilities:

  • Classification: AGNews, Amazon (reviews), SST-2 (sentiment), and Trec (question types).
  • Reasoning (BigBench): Winowhy, Epistemic_reasoning, Timedial, and Hyperbaton.
  • Mathematics: AQuA (algebraic word problems).
  • Generative Tasks: XSum (summarization) and E2E-NLG (data-to-text).

Key Findings and Results

AutoSelect consistently outperformed seven major baselines, achieving an average rank of 1.1 across all tasks (compared to 2.7 for the next best, computationally expensive "greedy-oracle" method).

  • Significant Performance Gains: On challenging reasoning tasks like Winowhy and AQuA, AutoSelect improved performance by 11.2% and 5.6%, respectively, over the strongest non-oracle baselines.
  • Order as a First-Class Citizen: By framing selection auto-regressively, the model crafts a coherent "story" for the LLM. Results confirm that re-ordering the exact same set of examples can significantly swing accuracy.
  • Quality Over Quantity: AutoSelect using a maximum of just 4 examples frequently outperformed a random selection of 16 examples. This underscores that a lean, highly optimized prompt is vastly superior to a cluttered prompt with mediocre examples.
  • Transferability: A policy trained on one reasoning task demonstrated strong zero-shot performance on other reasoning tasks, indicating the model learns generalizable principles of effective demonstration.
  • Inference Efficiency: Despite a one-time offline training cost, inference-time overhead is minimal (adding only ~20-30ms compared to standard retrieval), which is negligible relative to the time the LLM takes to generate a response.

Limitations and Future Directions

While highly effective, AutoSelect requires an initial offline training phase using a labeled validation set to query the task-solving LLM for rewards. Furthermore, the current framework operates in the efficiency sweet spot of 4–16 examples. Extending this to the "many-shot" regime (hundreds of examples) will require more efficient attention mechanisms, such as sparse or block-local attention, to manage extended contexts.

Looking forward, the authors suggest that future research could explore training a single, multi-task "universal selector" policy capable of operating across all domains without the need for task-specific adaptation.

Summary updated

BibTeX
@inproceedings{qi2026auto,
  author = {Yunzhe Qi and Sirui Chen and Jiaru Zou and Jingrui He},
  title = {{Auto-regressive In-context Demonstration Selection}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=8uZlNyR5R3},
}
Figure