In-Context Example Ordering Guided by Label Distributions

Zhichao Xu, Daniel Cohen, Bei Wang, Vivek Srikumar

Introduction

In-Context Learning (ICL) has emerged as a powerful paradigm for Large Language Models (LLMs), enabling them to perform complex tasks using only a few demonstrations. However, ICL is notoriously sensitive to the specific ordering of these examples. A simple permutation of the same few-shot examples can cause performance to fluctuate wildly, ranging from state-of-the-art accuracy to near-random guessing. This paper, presented at NAACL 2024, introduces Probability Distribution Ordering (PDO), a method to identify optimal example sequences without requiring additional labeled data.

The Challenge of Example Ordering

Current methods for mitigating ordering sensitivity often rely on a labeled development set to validate different permutations. However, in low-resource or few-shot scenarios, such data is rarely available. If one possesses enough labeled data for a validation set, fine-tuning often becomes a more viable alternative. The authors address this by asking: can we select the best ordering using only the few examples provided in the prompt?

Probability Distribution Ordering (PDO)

PDO operates on the principle of "learning from label proportions." It evaluates candidate permutations based on how well the model's predicted label distributions align with expected priors.

Principle I: FewShot (Null Input Bias)

In the absence of extra data, a robust ordering should minimize intrinsic bias. PDO measures this by providing a "null" input (e.g., an empty string) to the model. A biased prompt might cause the model to predict a specific label even for empty input. PDO selects the ordering that minimizes the KL-divergence between the model’s output for a null input and a uniform distribution.

Principle II: FewShotUP (Unlabeled Data Alignment)

When a small set of unlabeled data is available, PDO ensures that the average predicted label distribution across this set matches the known or assumed task prior. For instance, in a balanced sentiment analysis task, the optimal ordering should yield a roughly 50/50 split in predictions.

Correlation between KL divergence and Accuracy for FewShot and FewShotUP methods.

As shown in the figure above, lower KL divergence (indicating better alignment with priors) strongly correlates with higher classification accuracy, particularly for the FewShotUP variant.

Experimental Results

The researchers evaluated PDO across 13 text classification datasets and 9 autoregressive LLMs (ranging from GPT-2 to LLaMA-13B).

Performance and Consistency

PDO consistently improves average accuracy while significantly reducing performance variance. By "raising the floor," the method prevents the model from falling into the low-performance traps associated with poor example ordering.

Accuracy comparison between PMI and PDO-PMI across various LLMs.

The boxplots demonstrate that PDO-PMI not only achieves higher median accuracy across most models but also tightens the distribution of results, making ICL much more reliable. For LLaMA-13B, PDO (FewShotUP) reached an average accuracy of 75.5%, a notable improvement over the 72.2% achieved by random ordering.

Improved Calibration

Beyond accuracy, PDO enhances model calibration. For OPT-13B, the Expected Calibration Error (ECE) dropped from 20.4% to 16.6%. This ensures that the model's confidence scores are more representative of its actual likelihood of being correct, which is critical for real-world deployment.

Conclusion and Future Work

PDO provides a data-efficient solution to the instability of few-shot learning. By leveraging label distribution priors, it identifies high-performing example sequences without the need for extensive labeled validation sets. While currently limited to classification tasks with fixed label sets, future research may extend these principles to open-ended generation and larger-scale frontier models.

Summary updated

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 from 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.
BibTeX
@inproceedings{xu2024context,
  author = {Zhichao Xu and Daniel Cohen and Bei Wang and Vivek Srikumar},
  title = {{In-Context Example Ordering Guided by Label Distributions}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-naacl.167},
}
Figure