In-Context Example Ordering Guided by Label Distributions (2024)

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.

## introduction an intriguing property of large language models like the gpt @xcite and palm families of models @xcite is their ability to "learn in context". that is, the model can achieve competitive predictive performance with only a task description and a few training examples with no parameter updates @xcite @xcite . model predictions can sometimes even match full fine-tuning performance @xcite . in-context learning (icl)-the idea of prompting llms with only a few examples, also known as few-shot prompting-has shown promise across nlp. yet, many problems persist with this paradigm. prior work has shown that icl is sensitive to different natural language instructions and different orderings of in-context examples @xcite . merely changing the ordering of a fixed set of examples can change the predictive performance from that of nearly fully-tuned models to random guessing. @xcite studied in-context ordering and proposed heuristics to select the performant orderings. however, prior work on example ordering assumes (to different degrees) that an additional dataset is available to help reorder the in-context examples. we ask: can we select the best in-context example orderings with no labeled data beyond the in-context ones? we draw inspiration from the idea of learning from label distributions @xcite , which shows that the prior probability distributions of labels can weakly supervise label predictors. we build upon this insight to improve the quality of in-context predictions, and in particular, to select performant in-context example orderings. we consider two cases: (a) when we only have in-context examples @xcite , and (b) when we also have unlabeled examples (fewshotu) and additionally know the prior label distributions @xcite . in all cases, we only use the model's output probability distributions over candidate outputs. these distributions serve as a direct indicator of the model's confidence as well as the bias carried from pretraining and in-context examples. given a set of in-context examples, we propose to select the best ordering that, on the corpus level, has a probability distribution over candidate labels, such that it is (a) less biased towards certain labels, or, (b) close to a prior label distribution, if known. fig. 1 illustrates the two criteria using opt-1.3b as a backbone language model. each point corresponds to a certain ordering of a fixed set of in-context examples. fig. 1a corresponds to case (a). its x-axis is the kl-divergence between the uniform distribution and the model's probability for the null input given in-context examples. this kl-divergence captures the model's bias towards certain labels; smaller values indicate less bias. fig. 1b corresponds to case (b). its x-axis is kldivergence between model's average probability distribution over unlabeled samples and the prior label distribution. in fig. 1a , accuracy is weakly inversely correlated with kl-divergence, indicating performant orderings tend to be less biased towards certain labels. in fig. 1b , the negative correlation is stronger, indicating the marginal label probabilities of performant orderings tends to be close to informative priors. our approach, probability distribution ordering (pdo), effectively improves in-context predictions on 13 text classification datasets and 9 language models with 700m-13b parameters. it not only improves the classification accuracy and reduces variance across all datasets and models, but also improves models' confidence calibration, making them more suitable for real-world deployment. finally, in analysis experiments, we study how well pdo can select in-context examples for a task. prior work on task-level in-context example selection requires labeled development data @xcite . we show that pdo improves task-level example selection, matching condacc @xcite without the need for a labeled development set. ## background & notation we seek to order in-context examples to improve both predictive accuracy and model calibration. this section reviews in-context learning (icl) and model calibration, and introduce relevant notation. through the paper, we use the word ordering and permutation interchangeably. ## a proposal for ordering selection we seek to find an ordering of the k in-context examples d that has the best predictive performance and leads to calibrated probabilities. to do so, we need to rank the k! permutations and select the highest performing one. however, since we are operating in the few-shot setting, it is important to specify the task information we are allowed to use. prior efforts @xcite @xcite ) on in-context example ordering operate under different resource settings, making it difficult to perform comprehensive comparisons. we study three settings, in the order of increased information: in the fewshotup setting, the prior over labels may be determined from prior information (e.g., previous experiments) or a subjective expert assessment (e.g., the probability of a certain disease in the population assessed by a clinician). the fewshotu setting-where we do not know the prior label distribution-can be seen as a special case of fewshotup that uses an uninformative (or flat) prior, i.e., a uniform prior distribution of q(y) = unif(y) over the development set. we therefore consider two cases separately: (1) when we only have the in-context examples (fewshot); and (2) when we also have an unlabeled set of examples (fewshotu) and additionally know the prior label distribution (fewshotup). ## experiments our experiments evaluate the effectiveness of the proposed principles and answer the following research questions: ## conclusions in this paper, we aim to optimize in-context example ordering to improve icl performance. we rigorously examine three problem settings based on the availability of labeled examples and propose two principles in selecting performant orderings. our approach, referred to as the probability distribution ordering (pdo), leverages the model's output probability distributions. via extensive experiments, we demonstrate that our approach requires a trivial amount of extra computation and outperforms the baselines by improving classification accuracy and reducing model miscalibration.