NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

A Study on the Calibration of In-context Learning

Hanlin Zhang, Yi-Fan Zhang, Yaodong Yu, Dhruv Madeka, Dean Foster, Eric P. Xing, Himabindu Lakkaraju, Sham M. Kakade · OpenReview

Abstract

Accurate uncertainty quantification is crucial for the safe deployment of language models (LMs), and prior research has demonstrated improvements in the calibration of modern LMs. Our study focuses on in-context learning (ICL), a prevalent method for adapting static LMs through tailored prompts, and examines the balance between performance and calibration across a broad spectrum of natural language understanding and reasoning tasks. Through comprehensive experiments, we observe that, with an increasing number of ICL examples, models initially exhibit increased miscalibration before achieving better calibration and miscalibration tends to arise in low-shot settings. Moreover, we find that methods aimed at improving usability, such as fine-tuning and chain-of-thought (CoT) prompting, can lead to miscalibration and unreliable natural language explanations, suggesting that new methods may be required for scenarios where models are expected to be reliable.

Introduction

Large Language Models (LLMs) have revolutionized AI interaction through In-Context Learning (ICL)—the ability to adapt to new tasks via few-shot demonstrations in a prompt. However, as these models are integrated into safety-critical domains, the reliability of their confidence scores becomes paramount. Calibration measures the alignment between a model's perceived confidence and its actual accuracy. This study investigates the calibration of LLMs during the ICL process, uncovering a complex relationship between task performance and predictive reliability.

Methodology

The researchers evaluated the LLaMA family (7B to 30B parameters) and its instruction-tuned variants (Alpaca, Vicuna, LLaMA2-Chat) across diverse benchmarks, including text classification (e.g., SST-2, RTE) and reasoning tasks (e.g., Strategy QA).

Demonstration of the In-context Learning (ICL) process where examples are provided in the prompt.

Key metrics included:

  • Accuracy (Acc): Standard performance measure.
  • Expected Calibration Error (ECE): A metric to quantify the gap between confidence and accuracy.

The study varied the number of demonstrations ($k$-shot) from 0 to 8 to observe how context quantity affects calibration. They also compared standard Temperature Scaling against Scaling-Binning for post-hoc recalibration.

Key Insights: The Calibration-Accuracy Trade-off

The Low-Shot Calibration Dip

A significant finding is the "low-shot" phenomenon. While adding the first few examples (1-3 shots) typically improves accuracy, it often leads to a spike in ECE. As shown in the empirical data, the model appears to learn to be confident in its predictions faster than it learns to be correct, resulting in peak miscalibration in these early stages.

Accuracy and ECE trends for LLaMA-7B across different datasets as the number of shots increases.

The "Usability Tax" of Fine-Tuning

While instruction fine-tuning and Reinforcement Learning from Human Feedback (RLHF) make models more helpful, they significantly degrade calibration. For instance, on the CB dataset, LLaMA2-7B's ECE rose from 0.125 to 0.287 after chat-tuning. These models tend to become overconfident "yes-men," providing high-probability answers even when incorrect.

Chain-of-Thought (CoT) and Reliability

CoT prompting improves reasoning accuracy but exacerbates miscalibration. Models can generate plausible-sounding justifications for incorrect answers with high confidence, making the resulting natural language explanations unreliable for uncertainty estimation.

Results and Recalibration

Empirical results show that larger models (e.g., 30B) generally achieve better calibration in high-shot settings compared to smaller variants. On the SST-2 sentiment task, LLaMA-30B accuracy jumped from ~60% (0-shot) to ~96% (8-shot), though ECE peaked at 1-shot (0.163) before finally improving at 8-shot (0.080).

The study found that standard Temperature Scaling is often insufficient for ICL. Instead, Scaling-Binning—which fits a scaling function and averages values within specific confidence bins—proved much more effective, consistently reducing ECE to below 0.1.

Conclusion

The findings suggest that high accuracy in LLMs does not guarantee reliable confidence. The trade-offs observed in low-shot settings and the negative impact of usability-focused fine-tuning highlight the need for robust recalibration techniques. For practitioners, logit-based confidence from ICL or fine-tuned models should be treated with caution; post-processing methods like scaling-binning are essential for safety-critical applications.

Summary updated

BibTeX
@inproceedings{zhang2024study,
  author = {Hanlin Zhang and Yi-Fan Zhang and Yaodong Yu and Dhruv Madeka and Dean Foster and Eric P. Xing and Himabindu Lakkaraju and Sham M. Kakade},
  title = {{A Study on the Calibration of In-context Learning}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.naacl-long.340},
}
Figure