Abstract
In-context learning (ICL) performance is highly sensitive to the selection and ordering of few-shot exemplars. We present EASE (Efficient ordering-aware Automated Selection of Exemplars), a framework that optimizes both exemplar sets and their sequence for Large Language Models (LLMs). By leveraging neural bandits and Optimal Transport, EASE identifies high-performing, task-specific prompts offline, significantly improving performance on novel and out-of-distribution tasks without requiring expensive test-time retrieval.
Introduction
Large Language Models (LLMs) demonstrate remarkable versatility through in-context learning (ICL), where they solve new tasks based on a few provided examples (exemplars). However, ICL is notoriously "brittle": minor changes in exemplar selection or even the order of presentation can cause accuracy to fluctuate wildly—sometimes by as much as 40%.
Existing approaches typically rely on test-time retrieval, which is computationally expensive and poses data privacy risks, or subset selection methods that ignore the critical impact of sequence ordering and accompanying instructions. EASE addresses these limitations by automatically selecting a fixed, ordered sequence of exemplars and the optimal instruction for an entire task.
Methodology
EASE treats prompt optimization as a black-box problem, utilizing a Neural Bandit algorithm (specifically NeuralUCB) to navigate the vast search space of possible exemplar combinations and sequences.
Ordering-aware Embeddings
To account for the importance of sequence, EASE employs a pre-trained model (e.g., MPNet) to generate a single continuous embedding for the entire sequence of exemplars. Unlike "bag-of-examples" approaches, this method ensures that different permutations of the same examples result in distinct representations, allowing the optimizer to learn the nuances of "flow" that influence LLM performance.
Efficiency via Optimal Transport (OT)
The search space for ordered exemplars is combinatorially explosive. To maintain efficiency, EASE uses Optimal Transport to measure the "distance" between candidate exemplar sets and the task's validation set. By filtering for the most relevant candidates before evaluation, EASE achieves a 14.1x speedup compared to brute-force neural bandit approaches.
Joint Instruction-Exemplar Optimization
EASE treats instructions as a specialized type of exemplar, allowing for the joint optimization of the prompt's directive and its supporting examples. This captures the synergy between instructions and exemplars, leading to more robust performance than optimizing either component in isolation.
Experimental Results
The authors evaluated EASE against established methods like Determinantal Point Processes (DPP) and Maximum Mean Discrepancy (MMD) across the Instruction Induction (II) benchmark and several "Out-of-Distribution" (OOD) tasks designed to test reasoning (e.g., Linear Regression, Language Puzzles, and Remapped Labels).
As shown in Figure 1, EASE achieved the best performance in 17 out of 19 language tasks. Notably, on the Linear Regression task, EASE outperformed the strongest baseline by 8.3% absolute accuracy. The framework also demonstrated significant resilience to noise, maintaining high accuracy even when 70% of the available data was mislabeled.
Discussion: The Knowledge Gap Hypothesis
A key insight from this research is the "Knowledge Gap Hypothesis": prompt optimization provides the most significant gains on tasks that are novel to the LLM. While basic tasks like sentiment analysis are relatively insensitive to prompt variations, complex or OOD tasks—where the model cannot rely solely on pre-training data—benefit immensely from the structured guidance provided by EASE-optimized prompts.
As illustrated in Figure 4, the performance gap between EASE and simpler selection methods like Best-of-N is most pronounced when the model is less familiar with the task (e.g., in early training stages), supporting the idea that precise prompt engineering is critical for bridging the knowledge gap.
Conclusion
EASE provides a practical and efficient framework for optimizing ICL prompts by treating ordering as a primary factor. By combining neural bandits with Optimal Transport, it bridges the gap between expensive retrieval-based methods and static selection. Future work will explore fine-tuning embedding models specifically for prompt optimization to further refine the relevance filtering process.
Summary updated