Uncertainty Decomposition and Quantification for In-Context Learning of Large Language Models

Chen Ling, Xujiang Zhao, Wei Cheng, Yanchi Liu, Yiyou Sun, Xuchao Zhang, Mika Oishi, Takao Osaki, Katsushi Matsuda, Jie Ji, Guangji Bai, Liang Zhao, Haifeng Chen

TL;DR

This paper introduces a novel framework to decompose the uncertainty of Large Language Models (LLMs) during in-context learning into two distinct sources: aleatoric uncertainty (stemming from the provided examples) and epistemic uncertainty (stemming from the model's own internal knowledge and configuration). By separating these "why" factors, the authors provide a more robust way to detect model failures and out-of-distribution data compared to traditional, single-score uncertainty methods.

What Problem Does This Paper Address?

In-context learning (ICL)—where an LLM learns a task simply by seeing a few examples in a prompt—is a cornerstone of modern AI. However, LLMs are prone to hallucinations and overconfidence. While researchers have developed ways to measure how much a model is uncertain, they often ignore why it is uncertain.

In ICL, uncertainty can come from two places:

  1. The Prompt (Aleatoric): The few-shot examples might be noisy, ambiguous, or insufficient to define the task.
  2. The Model (Epistemic): The model itself might lack the parameters or the right decoding configuration to handle the specific query.

Existing methods treat these as a single "black box" of uncertainty. This paper argues that decomposing them is crucial for building trustworthy systems—allowing us to distinguish between a "bad prompt" problem and a "weak model" problem.

Figure 1: Uncertainty in LLM’s prediction can stem from two aspects: a) Demonstration Quality: LLMs are likely to make wrong predictions if the demonstrations are inappropriate; b) Model Configuration: different decoding strategies (e.g., beam_search and top_k sampling) and their parameter settings may return different predictions.

Methods

The authors frame ICL through a Bayesian lens, treating the "task" as a latent concept the model must infer from the prompt. They propose two ways to estimate these decomposed uncertainties:

  • Entropy-based (White-box): For models where we can access token probabilities, they use Mutual Information. Epistemic uncertainty is calculated as the average entropy across different sets of demonstrations, while Aleatoric uncertainty is the "leftover" uncertainty once the model's internal noise is accounted for. They use Beam Search as a clever proxy for sampling from the model's posterior distribution.
  • Variance-based (Black-box): For models like GPT-4 where probabilities aren't available, they propose using the variance of outputs across different hyperparameter settings (like temperature) and demonstration sets.

The framework is "plug-and-play," meaning it doesn't require retraining the LLM; it simply analyzes the outputs and probabilities generated during a standard inference run.

Figure 2: Uncertainty Quantification of In-context Learning Pipeline: we want to quantify the uncertainty that comes from 1) different in-context demonstrations x1:T ; and 2) different model configurations Θl.

Datasets

The researchers evaluated their method across several Natural Language Understanding (NLU) benchmarks:

  • Sentiment Analysis: EMOTION, Financial Phrasebank, and SST2.
  • Linguistic Acceptability: CoLA (judging if a sentence is grammatically correct).
  • Topic Classification: AG_News.

They tested these on a range of open-source models, specifically LLaMA-2 (7B, 13B, and 70B versions) and OPT-13B.

Key Insights and Ideas

  • Epistemic Uncertainty (EU) is the best "Red Flag": The most striking finding is that EU is a much more reliable indicator of a wrong answer than Aleatoric Uncertainty (AU) or even total uncertainty. If the model's internal "knowledge" is shaky, it’s far more likely to misclassify.
  • Spotting "Bad" Prompts: AU is highly sensitive to the quality of demonstrations. If you give a model examples from a completely different domain (e.g., giving grammar examples for a sentiment task), the AU spikes, providing a clear signal that the prompt is irrelevant.
  • The Scaling Effect: As models get larger (moving from 7B to 70B parameters), both types of uncertainty generally decrease. Larger models aren't just more accurate; they are more "stable" in how they process ICL prompts.
  • Token Equality is a Myth: The authors note that treating all tokens as equally important for uncertainty (as standard entropy does) is a mistake. Their method focuses on the "answer tokens," which filters out the "linguistic redundancy" of the rest of the generated sentence.
Figure 3: Framework of entropy-based uncertainty estimation, which consists of 1) generating M sequences based on a set of x1:T −1; 2) selecting token(s) that is relevant to the answer and extract the probabilities; 3) aggregating the token probabilities of M sequences into a distribution of predicted labels; 4) iterating the process L times corresponding to L different demonstration sets and form a probability matrix M, where the column denotes different demonstration sets and the row denotes labels of the dataset.

Key Results

The proposed decomposition consistently outperformed state-of-the-art baselines like Semantic Uncertainty and Likelihood-based methods in two key areas:

  1. Misclassification Detection: Using EU to predict when a model made a mistake yielded significantly higher AUROC (Area Under the Receiver Operating Characteristic) scores. For example, on the EMOTION dataset with LLaMA-7B, EU reached an AUROC of 0.696, while standard entropy only managed 0.538.
  2. Out-of-Domain (OOD) Detection: The method was exceptionally good at identifying when a test sample or a demonstration set didn't belong to the task at hand. In some OOD detection tests, EU achieved AUROC scores as high as 0.941, effectively acting as a high-fidelity filter for irrelevant data.

Limitations and Future Work

The primary limitation is that this framework is currently optimized for classification and NLU tasks where there are discrete, predefined labels (like "Positive/Negative" or "World/Sports").

Applying this to free-form generation (like writing an essay or code) is much harder because it's difficult to determine which specific tokens are "semantically important" for the overall meaning. The authors suggest that future work will focus on extending these decomposition techniques to more complex, open-ended generative tasks and different modalities of data.

Summary updated

BibTeX
@inproceedings{ling2024uncertainty,
  author = {Chen Ling and Xujiang Zhao and Wei Cheng and Yanchi Liu and Yiyou Sun and Xuchao Zhang and Mika Oishi and Takao Osaki and Katsushi Matsuda and Jie Ji and Guangji Bai and Liang Zhao and Haifeng Chen},
  title = {{Uncertainty Decomposition and Quantification for In-Context Learning of Large Language Models}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.naacl-long.184},
}
Figure