A Study on the Calibration of In-context Learning

Hanlin Zhang, Yi-Fan Zhang, Yaodong Yu, Dhruv Madeka, Dean Foster, Eric Xing, Himabindu Lakkaraju, Sham KakadearXiv 2023

TL;DR

Adapting Large Language Models (LLMs) via in-context learning (ICL) creates a complex trade-off between accuracy and calibration. This study finds that while more examples generally improve performance, they often cause models to become "confidently wrong," particularly in low-shot settings and when using Chain-of-Thought (CoT) prompting or instruction fine-tuning.

What Problem Does This Paper Address?

Calibration measures the alignment between a model’s confidence in its predictions and its actual accuracy. For a perfectly calibrated model, a prediction made with 90% confidence should be correct 90% of the time. In safety-critical domains, knowing when a model is likely to be wrong is as important as the prediction itself.

While prior work has looked at the calibration of fine-tuned models, this paper focuses on In-Context Learning (ICL)—the paradigm where a frozen LLM is adapted to a task simply by providing a few examples in the prompt. The authors investigate whether the impressive performance gains of ICL come at the cost of reliability and how common "usability" enhancements (like fine-tuning or reasoning chains) impact this balance.

Methods

The authors conducted an extensive empirical study using the LLaMA family of models (7B to 30B parameters) and their fine-tuned variants (Alpaca, Vicuna, LLaMA2-Chat). They evaluated:

  • Token-level calibration: Measuring the discrepancy between perceived and actual performance through a Bayesian uncertainty lens.
  • Expected Calibration Error (ECE): A standard metric that bins predictions by confidence and calculates the average gap between confidence and accuracy within those bins.
  • Recalibration Strategies: They tested three post-hoc methods to fix miscalibration: standard Temperature Scaling and a more robust Scaling-Binning approach.
  • Prompt Variations: They explored how repeating contexts vs. providing diverse examples affects the model's internal uncertainty.

Datasets

The study spans two main categories of tasks:

  • Natural Language Understanding (NLU): AGNews (news classification), RTE (entailment), CB (commitment bank), SST-2 (sentiment analysis), and DBPedia.
  • Reasoning Tasks: Strategy QA, Commonsense QA, OpenBook QA, and World Tree. These tasks were often tested with "scratchpads" or Chain-of-Thought prompting.

Key Insights and Ideas

  • The Low-Shot Calibration "Hump": In low-shot settings ($k < 4$), increasing the number of examples initially worsens calibration before it starts to improve. As accuracy climbs, the model's confidence often climbs even faster, leading to a peak in miscalibration.
  • The Usability Trap: Techniques designed to make models more helpful—such as instruction fine-tuning (RLHF) and Chain-of-Thought (CoT) prompting—actually degrade calibration. While CoT improves reasoning accuracy, it frequently leads the model to generate highly confident but entirely hallucinated explanations.
  • Base Models are More "Honest": Base LLaMA models are generally better calibrated than their instruction-tuned counterparts (like Vicuna or Alpaca), which tend to be overconfident.
  • Diverse Examples Matter: Simply repeating the same example in a prompt does not help calibration. True task learning and better uncertainty quantification require a diversity of in-context examples to help the model map the label space.
Figure 1: The accuracy-calibration trade-off of in-context learning. (a) ICL concerns taking task-specific examples as the prompt to adapt a frozen LLM to predict the answer. (b) Classification accuracy and expected calibration error of ICL. As the number of ICL samples increases, the prediction accuracy improves (Left); at the same time, the calibration first worsens (k < 3) and then becomes better (Right).

Key Results

  • Accuracy-Calibration Trade-off: The authors observed a persistent trade-off where models exhibit increased miscalibration in performant settings. For example, on Commonsense QA, a LLaMA-30B model achieves ~64% accuracy but suffers from an ECE of 0.28, indicating significant overconfidence.
  • Scaling-Binning Success: While standard temperature scaling (common in supervised learning) failed to resolve ICL miscalibration, the scaling-binning method successfully reduced ECE to below 0.1 across various tasks.
  • Confidently Wrong Reasoning: Qualitative analysis showed that for reasoning tasks, models often concentrate their confidence scores above 0.8, even for incorrect answers.
Figure 2: Reliability plots for LLaMA models on Commonsense QA. The gap between the blue line and the dashed diagonal represents miscalibration (overconfidence). Larger models (right) show higher accuracy but also higher confidence concentration.

Limitations and Future Work

The authors acknowledge several limitations:

  • Scope of Tasks: The evaluation focused primarily on classification and question-answering. Generative tasks with open-ended outputs were not explored.
  • Label Disagreement: The study assumes a single "ground truth" label, ignoring cases where humans might naturally disagree.
  • Future Directions: The authors suggest exploring "hedging words" (e.g., "I am not sure, but...") as a way for models to express uncertainty linguistically rather than just through probabilities. They also point toward the need for better control of epistemic and aleatoric uncertainty in low-shot settings to improve overall truthfulness.

Summary updated

BibTeX
@misc{zhang2023study,
  author = {Hanlin Zhang and Yi-Fan Zhang and Yaodong Yu and Dhruv Madeka and Dean Foster and Eric Xing and Himabindu Lakkaraju and Sham Kakade},
  title = {{A Study on the Calibration of In-context Learning}},
  year = {2023},
  eprint = {2312.04021},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.04021},
}
Figure