Calibrating Language Models with Adaptive Temperature Scaling

Johnathan Xie, Annie S. Chen, Yoonho Lee, Eric Mitchell, Chelsea Finn

Introduction

Large Language Models (LLMs) have seen significant improvements in helpfulness through Reinforcement Learning from Human Feedback (RLHF). However, this alignment process often comes at a cost: models become significantly more overconfident. Calibration—the alignment between a model's predicted probability and its actual accuracy—is frequently "broken" by RLHF, leading to near-100% confidence even in incorrect answers.

Standard post-hoc calibration techniques, such as global Temperature Scaling, apply a single multiplier to all outputs. This approach is often too coarse for natural language, where uncertainty varies drastically depending on the token type (e.g., structural grammar vs. factual claims). To address this, we introduce Adaptive Temperature Scaling (ATS), a method that predicts a unique temperature for every token based on the model's internal hidden states.

Methodology: Adaptive Temperature Scaling

ATS treats calibration as a secondary prediction task, leveraging the rich information stored within an LLM's internal representations.

Feature Extraction and Calibration Head

The core of ATS is a small "calibration head" that operates on the last hidden state of the LLM. This vector representation, captured just before the final output layer, contains signals of uncertainty that may not be fully reflected in the final logit distribution. Empirical testing shows that a single Transformer layer is the most effective architecture for this head, outperforming simpler linear or MLP alternatives.

Selective Smoothing Loss

To train the calibration head without degrading the model's performance, a novel Selective Smoothing Loss is employed. This loss function applies standard cross-entropy if the model's original prediction was correct. If the prediction was incorrect, it pushes the model toward a uniform distribution (maximum uncertainty). This prevents the calibration process from inadvertently increasing confidence in erroneous outputs.

Ablation studies showing the impact of different loss functions, smoothing parameters (α), and head architectures on calibration performance (ECE and BS).

Experimental Setup

The ATS calibration head is trained post-hoc, meaning the original LLM weights remain frozen, ensuring computational efficiency.

  • Training Data: The head was trained using the Alpaca GPT-4 dataset (52,000 samples).
  • Evaluation Benchmarks: Performance was validated across MMLU (general knowledge), TriviaQA (fact-based comprehension), and TruthfulQA (hallucination testing).
  • Models: Evaluation was conducted on Llama-2-7b-Chat, Llama-2-13b-Chat, and Qwen-7b-Chat.

Key Results

ATS consistently outperforms standard calibration methods like Temperature Scaling, Vector Scaling, and Scaling Binning across all tested models and benchmarks.

Comparison of ATS against baseline calibration methods. ATS significantly reduces Expected Calibration Error (ECE) and Brier Score (BS) across multiple models and benchmarks without affecting accuracy.
  • Significant Error Reduction: ATS reduces Expected Calibration Error (ECE) by 10–50% across the board.
  • Preserved Accuracy: Because ATS only scales logits without changing their relative rank, the model's top-1 accuracy remains identical. You get better reliability for "free."
  • Efficiency: The additional overhead is minimal, adding approximately 0.08 seconds (~7%) to the forward pass, making it viable for real-time applications.
  • Generalization: Training on a general instruction dataset (Alpaca) successfully improved calibration on specialized tasks like MMLU, suggesting that internal uncertainty signals are task-agnostic features of the model.

Discussion and Future Work

The success of ATS highlights that LLMs' internal hidden states are reliable "tells" for uncertainty. By allowing for token-level granularity, ATS can specifically target factual claims where overconfidence is most problematic while leaving structural language unchanged.

While ATS provides a robust solution for token-level calibration, future work should explore its application to sentence-level or semantic uncertainty. Additionally, integrating ATS with "verbalized confidence"—where models explicitly state their certainty in natural language—remains a promising direction for improving human-AI trust in high-stakes applications.

Summary updated

BibTeX
@inproceedings{xie2024calibrating,
  author = {Johnathan Xie and Annie S. Chen and Yoonho Lee and Eric Mitchell and Chelsea Finn},
  title = {{Calibrating Language Models with Adaptive Temperature Scaling}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-main.1007},
}
Figure