Abstract
By allowing models to predict without task-specific training, in-context learning (ICL) with pretrained LLMs has enormous potential in NLP. However, a number of problems persist in ICL. In particular, its performance is sensitive to the choice and order of in-context examples. Given the same set of in-context examples with different orderings, model performance may vary between near random to near state-of-the-art. In this work, we formulate in-context example ordering as an optimization problem. We examine three problem settings that differ in the assumptions they make about what is known about the task. Inspired by the idea of learning from label proportions, we propose two principles for in-context example ordering guided by model's probability predictions. We apply our proposed principles to thirteen text classification datasets and nine different autoregressive LLMs with 700M to 13B parameters. We demonstrate that our approach outperforms the baselines by improving the classification accuracy, reducing model miscalibration, and also by selecting better in-context examples.
Introduction
Large Language Models (LLMs) have revolutionized NLP through In-Context Learning (ICL), where models perform tasks based on a few examples provided in the prompt. Despite its success, ICL is notoriously sensitive to the specific sequence of these examples. A simple reordering of the same four examples can swing a model's performance from state-of-the-art accuracy to near-random guessing.
Existing methods for finding optimal orderings often rely on labeled development sets to validate permutations. However, the primary appeal of ICL is its utility in low-resource settings where labeled data is scarce. This paper introduces Probability Distribution Ordering (PDO), a zero-labeled-data approach to identifying high-performing example orderings by aligning model predictions with expected label distributions.
Methodology
The PDO framework is built upon two core principles designed to minimize model bias without requiring ground-truth labels:
- Principle I (The Null Input Test): A well-ordered prompt should not induce inherent bias in the model. When presented with a "null" input (e.g., an empty string) following the in-context examples, the model's output distribution should ideally be uniform. PDO selects orderings that minimize the KL-divergence between the model’s null prediction and a uniform distribution.
- Principle II (Distribution Matching): When unlabeled data is available, the model's aggregate predicted distribution across the dataset should match the true (or assumed) label proportions. For a balanced sentiment task, a good prompt should result in an approximately 50/50 split of positive and negative predictions.
To implement this, the authors utilize a "sample-then-select" strategy. Rather than brute-forcing all $k!$ permutations, they sample a manageable subset (e.g., $K=24$), calculate the KL-divergence based on the principles above, and select the ordering with the lowest score.
The Bias-Accuracy Correlation
A central finding of this research is the strong inverse correlation between model bias (measured via KL-divergence) and task accuracy. Prompts that exhibit high bias toward specific labels on null or unlabeled inputs consistently underperform on the actual task.
As shown in the figure above, orderings that result in lower KL-divergence (indicating a more balanced, less biased distribution) are significantly more likely to achieve higher accuracy. This relationship allows label distributions to serve as an effective proxy for ground-truth performance.
Experimental Results
The researchers evaluated PDO across 13 text classification datasets (spanning sentiment, topic, and toxicity classification) and 9 LLMs ranging from 770M to 13B parameters.
Key findings include:
- Consistent Accuracy Gains: PDO systematically outperformed random ordering. For example, using OPT-13B on balanced datasets, PDO improved accuracy from 80.9% to 84.2%.
- Variance Reduction: PDO significantly narrowed the performance gap between the best and worst seeds, providing much-needed stability to few-shot prompting.
- Improved Calibration: Beyond accuracy, PDO reduced Expected Calibration Error (ECE), meaning the model's confidence scores became more representative of its actual probability of being correct.
- Competitive Performance: PDO matched or exceeded the performance of supervised baselines like CondAcc, despite requiring no labeled development data.
Conclusion
Probability Distribution Ordering offers a robust, data-efficient solution to the example ordering problem in ICL. By leveraging label proportions as a form of weak supervision, PDO stabilizes LLM performance and improves calibration across a wide range of tasks and model architectures. Future work remains to extend this framework to open-ended generation tasks where discrete label distributions are not readily available.
Summary updated