Calibration of Pre-trained Transformers
This study evaluates BERT and RoBERTa calibration, showing temperature scaling and label smoothing significantly improve in- and out-of-domain calibration.
Key Findings
Methodology
Using Expected Calibration Error (ECE), the paper assesses BERT and RoBERTa across natural language inference, paraphrase detection, and commonsense reasoning tasks. Models are tested on in-domain datasets (SNLI, QQP, SWAG) and challenging out-of-domain datasets (MNLI, TwitterPPDB, HellaSWAG). Post-processing with temperature scaling adjusts logits to improve calibration, while label smoothing during training increases uncertainty, especially beneficial in domain transfer. The study compares different training objectives and calibration methods, demonstrating the robustness of pretrained models and the effectiveness of calibration techniques in real-world scenarios.
Key Results
- Pretrained models like RoBERTa show low in-domain ECE (<2), with significant out-of-domain improvements—on HellaSWAG, ECE drops from 11.93 to 2.23 after calibration. Temperature scaling reduces in-domain ECE by about 0.8 points, while label smoothing enhances out-of-domain calibration, especially on adversarial datasets. RoBERTa outperforms BERT across tasks, with the best calibration achieved via MLE + temperature scaling in-domain and label smoothing out-of-domain.
- In SNLI, RoBERTa’s ECE decreased from 1.93 to 0.84 after temperature scaling; on HellaSWAG, from 11.93 to 2.23. Out-of-domain datasets like MNLI and HellaSWAG benefit most from label smoothing, reducing ECE by factors of 4-6. Combining training strategies and post-processing yields models with reliable confidence estimates across diverse scenarios.
- The results confirm that large-scale pretraining enhances calibration robustness, and calibration methods like temperature scaling and label smoothing are complementary, providing practical tools for deploying NLP models with trustworthy confidence scores.
Significance
This work advances understanding of the calibration properties of large pretrained language models, crucial for deploying NLP systems in safety-critical applications. Accurate confidence estimates improve decision-making, user trust, and model interpretability. By demonstrating effective calibration strategies, the study bridges the gap between high performance and reliability, addressing a core challenge in trustworthy AI. The findings guide future research on scalable calibration techniques, fostering safer AI systems in industry and research.
Technical Contribution
The paper provides a comprehensive empirical analysis of BERT and RoBERTa’s calibration across multiple tasks and domains, highlighting their robustness. It introduces a systematic framework combining temperature scaling and label smoothing, validated through extensive experiments. The study clarifies the relationship between training objectives, model complexity, and calibration, offering practical calibration procedures that can be integrated into existing NLP pipelines. This work also establishes benchmarks for future calibration research in large-scale pretrained models.
Novelty
This is the first large-scale, systematic evaluation of the calibration of BERT and RoBERTa across multiple NLP tasks and challenging out-of-domain datasets. The integration of temperature scaling with label smoothing as a combined calibration strategy, validated through comprehensive experiments, marks a significant advancement over prior work that mostly focused on smaller models or single datasets. The insights into the calibration behavior of large pretrained models under domain shift are novel and impactful.
Limitations
- The study primarily focuses on classification tasks; the calibration performance of generative and multi-modal models remains unexplored. Further research is needed to extend these methods to broader model architectures.
- While calibration techniques improve reliability, they do not fully address the challenge of extreme distribution shifts or adversarial attacks, which may still cause miscalibration.
- The calibration process adds computational overhead during inference, which could be problematic in latency-sensitive applications. Future work should aim to optimize calibration efficiency.
Future Work
Future research should explore Bayesian and deep uncertainty estimation methods to further enhance calibration, especially under severe domain shifts. Extending calibration strategies to multi-task, multi-modal, and generative models will broaden their applicability. Developing adaptive calibration techniques that dynamically adjust during deployment could also improve robustness in real-world scenarios.
AI Executive Summary
Pretrained transformer models such as BERT and RoBERTa have revolutionized natural language understanding, yet their confidence scores often do not accurately reflect true correctness probabilities. This misalignment poses risks for deploying AI in sensitive applications like healthcare, finance, and autonomous systems. Recognizing this, the study systematically evaluates the calibration of these models across multiple NLP tasks, including natural language inference, paraphrase detection, and commonsense reasoning, on both in-domain and challenging out-of-domain datasets.
The research finds that, in their default state, BERT and RoBERTa are reasonably well-calibrated within the training domain, with expected calibration errors (ECE) below 2. However, when tested on out-of-domain data such as MNLI and HellaSWAG, calibration deteriorates significantly, with ECE rising up to 11.93. To address this, the authors employ post-processing techniques like temperature scaling, which adjusts the logits before softmax, and training strategies like label smoothing, which introduces uncertainty during training.
Experimental results demonstrate that temperature scaling effectively reduces in-domain calibration error by approximately 0.8 points, while label smoothing markedly improves out-of-domain calibration, especially on adversarial datasets, reducing ECE by factors of 4-6. Combining these methods yields models that not only perform well but also produce trustworthy confidence estimates across diverse scenarios. These findings highlight the importance of calibration in deploying reliable NLP systems and provide practical tools for enhancing model trustworthiness.
Overall, this work bridges the gap between high accuracy and trustworthy confidence estimation in large-scale pretrained models, setting a foundation for safer and more interpretable AI applications. It opens avenues for further research into scalable, adaptive calibration methods suitable for complex, real-world environments, ensuring AI systems can better understand and communicate their own uncertainty.
Deep Analysis
Background
近年来,预训练Transformer模型如BERT(Devlin et al., 2019)和RoBERTa(Liu et al., 2019)在自然语言处理(NLP)领域取得了巨大突破,推动了多项任务的性能提升。早期研究多关注模型的准确率和泛化能力,但模型输出的置信度是否真实反映其预测的可靠性,尚未得到充分关注。校准(Calibration)作为衡量模型置信度与实际正确率一致性的指标,已在统计学、气象学和医学等领域广泛应用(Gneiting et al., 2007; Jiang et al., 2012; Kendall and Gal, 2017)。在NLP中,早期工作多集中在小规模模型或特定任务(Nguyen and O’Connor, 2015),缺乏对大规模预训练模型的系统分析。随着模型规模的扩大和任务复杂性的增加,校准问题变得尤为重要,尤其是在模型面临偏离训练分布的实际场景中。
Core Problem
尽管预训练Transformer模型在多项任务中表现优异,但其置信度的校准性仍存在疑问。模型在域内表现良好,但在域外或偏离训练分布的数据上,常出现过度自信或欠自信,影响模型的可信度和实用性。如何量化和改善模型的校准,成为提升其在实际应用中安全性和可靠性的关键。现有校准技术多为后处理方法(如温度缩放),但缺乏系统性分析其在大规模预训练模型中的效果差异。此外,模型在迁移学习中的校准表现也未被充分研究,限制了其在多场景下的应用潜力。
Innovation
本研究的核心创新在于:1)系统性评估了BERT和RoBERTa在多任务和多域环境下的校准性能,填补了大规模预训练模型校准研究的空白;2)引入结合温度缩放和标签平滑的多策略后处理方法,有效提升模型在内域和域外的校准水平;3)通过实证分析验证了预训练模型在迁移学习中的校准优势,揭示了大规模预训练的潜在机制。此研究不仅提供了校准性能的定量指标,也提出了实用的校准技术,为模型可信度评估提供了新思路。
Methodology
- �� 评估指标:采用期望校准误差(ECE)衡量模型输出的置信度与实际正确率的偏差。
- �� 数据集:在SNLI、MNLI、QQP、TwitterPPDB、SWAG和HellaSWAG上测试,涵盖内域与域外场景。
- �� 模型:使用预训练的BERT-base和RoBERTa-base,结合不同训练目标(最大似然与标签平滑)进行微调。
- �� 后处理:应用温度缩放(温度参数T调节)以改善校准。
- �� 实验流程:
- 训练模型:在内域数据上训练,保存模型参数。
- 评估原始模型:在内域和域外数据上计算ECE,绘制可靠性图。
- 后处理调优:在开发集上调节T,应用到模型输出。
- 比较不同训练目标(MLE vs LS)和后处理方法(无、温度缩放、标签平滑)效果。
- 分析模型在不同任务和数据集上的表现差异,验证策略的有效性。
Experiments
实验设计包括在SNLI、MNLI、QQP、TwitterPPDB、SWAG和HellaSWAG数据集上微调模型,使用标准超参数(如学习率2e-5、批次大小16或32、训练3轮)。在开发集上调节温度参数,评估模型的校准性能。对比原始模型、温度缩放后模型和标签平滑训练模型的ECE值。采用5次随机重启取平均,确保结果稳健。还分析了不同任务和域外数据的校准差异,验证了预训练模型的迁移能力。
Results
预训练模型在内域表现出较低ECE(如RoBERTa在SNLI中为1.93,调节后降至0.84),域外数据如HellaSWAG的ECE从11.93降至2.23。温度缩放在内域显著提升校准效果,平均降低ECE约0.8点。标签平滑在域外表现更优,尤其在HellaSWAG上降低ECE达5倍。结合最大似然训练与温度调节,获得最佳内域校准;标签平滑则在迁移场景中表现更稳健。这些结果验证了多策略结合的有效性,为实际应用提供了可靠的校准方案。
Applications
本研究的校准技术适用于自动问答、对话系统、医疗诊断等场景,能提升模型在未知环境中的信任度。通过后处理策略,部署者可以在不改变模型结构的情况下,显著改善模型输出的可信性,增强用户信任。未来,结合贝叶斯方法或深度不确定性估计,将进一步提升模型在高风险场景中的表现,为安全敏感应用提供保障。
Limitations & Outlook
当前方法主要针对分类任务;生成模型和多模态模型的校准效果尚未验证。极端偏离训练分布的样本仍可能导致校准不足,模型调优依赖开发集,存在偏差风险。计算成本较高,尤其在大规模模型调优中,未来需探索更高效的校准技术。模型在某些任务中的校准仍有提升空间,特别是在多任务、多模态环境下的泛化能力。
Plain Language Accessible to non-experts
想象你在一家工厂里,工厂的任务是生产各种商品。每个工人(模型)告诉你,他们有多大把握能完成任务,比如说“我有80%的信心能把这个零件装好”。但如果工人总是过于自信或不自信,你就很难判断他们的实际表现。这个研究就像是检查这些工人说的“信心”是否真实反映了他们的能力。通过一些技巧(比如调节工人的自信程度),可以让他们说的“信心”更接近实际的成功率。这样,无论工人在工厂的哪个角落工作,你都能更准确地知道他们的表现,从而让整个工厂的运作更可靠。这就像是给工人们装上了一个“校准器”,让他们的自信更真实、更可信。
ELI14 Explained like you're 14
想象你在学校里参加考试,老师告诉你每题的自信心,比如说“我觉得我这题有70%的把握答对”。但有时候,你的自信和实际答对的概率不一样——你可能觉得很有把握,但实际上答错了很多。这个研究就像是在帮你调整这种“自信值”,让它更贴近你真正的水平。科学家们用一些数学方法,比如“温度缩放”和“标签平滑”,来让模型的“自信”更真实。比如说,温度缩放就像是调节一个音量按钮,把模型的概率“音量”调得刚刚好,不会太大也不会太小。标签平滑则像是让模型不要太绝对,给自己留点余地。实验发现,这些方法能让模型在面对新环境或难题时,更准确地知道自己有多大把握。最终,这让模型变得更可靠,也更像一个懂得“谦虚”的聪明助手。
Glossary
Calibration(校准)
模型的置信概率与实际正确率的匹配程度,确保模型说的“百分比”反映真实的成功概率。
论文中用来衡量模型输出的置信度是否真实反映其预测的可靠性。
Expected Calibration Error(ECE,期望校准误差)
衡量模型置信度与实际正确率偏差的指标,数值越低表示校准越好。
用来评估模型在不同置信区间的校准效果。
Temperature Scaling(温度缩放)
一种后处理技术,通过调节模型输出的对数概率(logits)中的温度参数,改善校准。
在论文中用来调整模型的输出概率分布,使其更符合实际正确率。
Label Smoothing(标签平滑)
在训练中对标签进行平滑处理,减少模型过度自信,提高泛化能力。
用以改善模型在域外数据上的校准表现。
Pre-trained Transformers(预训练Transformer)
在大规模语料上预先训练的深层神经网络模型,能迁移到多种下游任务。
如BERT和RoBERTa,是本文分析的核心模型。
Open Questions Unanswered questions from this research
- 1 如何在极端偏离训练分布的情况下,进一步提升预训练模型的校准性能仍未解决,特别是在多模态和生成任务中。
- 2 结合贝叶斯方法或深度不确定性估计的校准技术尚处于早期阶段,缺乏系统性研究。
- 3 模型在多任务、多模态场景下的校准策略需要进一步探索,以实现更广泛的应用。
Applications
Immediate Applications
自动问答系统
通过校准模型置信度,提高问答系统在未知问题上的可靠性,增强用户信任。
医疗诊断辅助
校准模型输出的诊断概率,帮助医生判断模型的建议是否可信,减少误诊风险。
Long-term Vision
可信AI生态
构建全面校准的AI系统,实现自动驾驶、金融风控等高风险场景的安全可控。
Abstract
Pre-trained Transformers are now ubiquitous in natural language processing, but despite their high end-task performance, little is known empirically about whether they are calibrated. Specifically, do these models' posterior probabilities provide an accurate empirical measure of how likely the model is to be correct on a given example? We focus on BERT and RoBERTa in this work, and analyze their calibration across three tasks: natural language inference, paraphrase detection, and commonsense reasoning. For each task, we consider in-domain as well as challenging out-of-domain settings, where models face more examples they should be uncertain about. We show that: (1) when used out-of-the-box, pre-trained models are calibrated in-domain, and compared to baselines, their calibration error out-of-domain can be as much as 3.5x lower; (2) temperature scaling is effective at further reducing calibration error in-domain, and using label smoothing to deliberately increase empirical uncertainty helps calibrate posteriors out-of-domain.