arXiv(opens in a new tab)cs.LGOct 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2610.17096

Towards Universal Calibration for In-Context Classification

Awik Dhar, Sunita Sarawagi, Arpit Agarwal

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

In-Context Learning (ICL) has received a lot of interest recently due to its ability to improve classification accuracy for new tasks without having to fine-tune the model over these tasks. However, the impact of ICL on calibration has been far less studied. Recent work has shown that ICL can have a negative impact on calibration due to biased selection of in-context examples. The existing methods for improving ICL calibration require additional task and model-specific training, detracting from the no-fine-tuning convenience of ICL. In this work, we introduce CALIBFORMER, a universal ICL calibrator for classification tasks, that generalizes to new models and tasks without further fine-tuning on these tasks. Specifically, we design a transformer-based calibrator which uses the model predictions on in-context examples to predict a confidence score for the test input. We show that the calibrator trained on three models and ten tasks, is able to generalize/calibrate ICL predictions on several new tasks and four LLMs unseen during training. Even for frontier models like Gemini, CALIBFORMER is able to obtain over 50% reduction in calibration error 1^{1}.

1 Introduction

In-Context Learning (ICL) allows large language models (LLMs) to adapt to new classification tasks at inference time by conditioning on a small set of labeled demonstrations, without any parameter updates (Brown et al., 2020). This capability has found wide application in settings where labeled data is scarce, including question answering (Wu et al., 2023), low-resource NLP (Alves et al., 2023; Li et al., 2025), tool calling (Zhang et al., 2025; Dang et al., 2025), and risk assessment (Padayachy et al., 2026). However, for ICL to be deployed reliably the model's predicted probabilities must be calibrated: a prediction made with 90% confidence should be correct 90% of the time. A well-calibrated predictor enables trust in downstream decision-making as the predicted probabilities provide a good measure of the confidence in prediction. For instance, in risk assessment or sequential reasoning, if the system identifies that it is not confident in its prediction, then it can delegate control to a human expert or invoke external verification tools. On the other hand, a miscalibrated predictor can be detrimental to reliable and safe decision-making, especially in autonomous or semi-autonomous systems. Overconfidence in “agentic” loops can propagate errors to downstream tasks, leading to compounding failures in autonomous workflows.

Unfortunately, ICL often degrades calibration. The very mechanism that makes ICL effective—conditioning on a small, context-dependent set of demonstrations—introduces variance in the model’s confidence that does not track its actual accuracy. As illustrated in Figure 1, while accuracy generally improves with additional demonstrations, calibration error behaves erratically, sometimes worsening as more examples are added.

Related Work. Existing approaches to improving ICL classification calibration each carry significant limitations. Bias-correction methods (Zhao et al., 2021; Zhou et al., 2024; Jang et al., 2024) subtract an estimated label prior from the logits, but they target accuracy rather than calibration, assume randomly sampled demonstrations, and require task-specific estimation. Temperature scaling can be fitted on the in-context examples themselves, but treats predictions at different context positions as independent whereas predictions on ICL examples are correlated. Methods that train auxiliary calibrators (Ulmer et al., 2024; Shen et al., 2024) require retraining for each target LLM, and approaches based on hidden-state features (Shen et al., 2024) additionally cannot be applied to black-

1^{1}https://github.com/AwikDhar/icl-calibration

Figure

amazon_counterfactual

massive_intent

metatool

wikitoxic

(a) Similarity sampling

when2call

massive_intent

commonsense_qa

wikitoxic

(b) Random sampling

Figure 1: Accuracy and ECE with varying number of shots. While accuracy typically increases with the number of shots, the model does not significantly improve in aligning its confidence with true likelihood of correctness. Sometimes unpredictable trends are observed - wikitoxic ECE in (a) is turbulent at the end; when2call in (b) experiences worsening ECE despite stable accuracy

box models. In all cases, the user must invest effort per model/task, undermining the convenience that makes ICL attractive. See Appendix C for further discussion of related work.

In this work, we ask: can a single calibrator, trained once, improve the calibration of any LLM on any classification task, using only the in-context examples? Towards that goal we develop CALIBFORMER, a lightweight (0.61M parameter) transformer-based meta-model that predicts the probability that an LLM's prediction is correct, serving as a calibrated confidence score.

The key idea is that in-context examples constitute a latent validation set. As the LLM processes the demonstrations autoregressively, its predictions on these examples reveal the extent and pattern of its miscalibration in the current prompt context. CALIBFORMER is a causal transformer that attends over a compact set of task-agnostic features derived from these prediction-label discrepancies (top-class probabilities, running correctness, ground-truth probability at each position) and learns to output a calibrated confidence for the test prediction. Because these features capture only the statistical signature of the LLM's behavior rather than any task-specific or model-specific representation, a single calibrator trained on 3 open-weight LLMs and 10 classification tasks generalizes to unseen models and tasks without further fine-tuning.

We evaluate CALIBFORMER on eight held-out classification tasks spanning tool use, toxicity detection, intent classification, and medical question answering, using four LLMs not seen during training—including the black-box frontier model Gemini-2.5-flash. Our main findings are:

  1. CALIBFORMER reduces average ECE by 41–73% relative to uncalibrated ICL (e.g., from 18.3% to 6.1% on Phi-4-mini-instruct under similarity sampling; from 12.2% to 4.5% on Gemini-2.5-flash under random sampling).

  2. CALIBFORMER consistently outperforms strong baselines including in-context temperature scaling and context permutation averaging, while requiring only a single forward pass through a sub-million-parameter model.

  3. The calibrator transfers to LLMs with substantially different architectures and confidence profiles, including models that are already reasonably well-calibrated (Qwen-3.5-9B) and black-box models where only token-level log-probabilities are available (Gemini-2.5-flash).

References (1)

  • All layers use a causal mask for attention