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.
Introduction
In the race for higher leaderboard scores, raw accuracy often takes precedence over reliability. However, for a model to be truly useful in high-stakes real-world applications—such as medical diagnosis or legal technology—it must "know what it doesn't know." This property is known as calibration: if a model assigns a 70% probability to a prediction, it should be correct exactly 70% of the time.
While deep neural networks are notorious for being overconfident, this research investigates whether modern Transformer architectures like BERT and RoBERTa inherit these flaws or if their massive pre-training provides a more realistic "uncertainty landscape."
Methodology
The study evaluates calibration using Expected Calibration Error (ECE). This metric bins predictions by their confidence levels and calculates the average difference between that confidence and the actual accuracy within those bins. The authors compare BERT and RoBERTa against two non-pre-trained baselines: the Decomposable Attention (DA) model and the Enhanced Sequential Inference Model (ESIM).
To improve calibration, two primary strategies are tested:
- Temperature Scaling (TS): A post-processing step where a single scalar ($T$) is used to "soften" the model's output probabilities after training.
- Label Smoothing (LS): A training-time regularization technique that prevents the model from becoming too certain by penalizing it for assigning 100% probability to the correct label.
Experimental Setup
The models are tested across three task pairs to evaluate both in-domain (ID) and out-of-domain (OOD) performance:
- Natural Language Inference: Trained on SNLI (ID), tested on MNLI (OOD).
- Paraphrase Detection: Trained on Quora Question Pairs (ID), tested on TwitterPPDB (OOD).
- Commonsense Reasoning: Trained on SWAG (ID), tested on HellaSWAG (OOD), a dataset specifically designed to exploit the biases of pre-trained models.
In-Domain Calibration Results
Contrary to the trend in older neural architectures where increased complexity leads to worse calibration, pre-trained Transformers are naturally well-calibrated in-domain. Even without additional tuning, BERT and RoBERTa show a strong alignment between their predicted confidence and actual accuracy.
As illustrated in Figure 1, the models track the "Zero Error" diagonal closely. RoBERTa consistently outperforms BERT in both accuracy and calibration across almost every metric and task, likely due to its more robust pre-training regime.
Improving Calibration with Temperature Scaling
Temperature scaling acts as a highly effective tool for refining in-domain calibration. By adjusting the logits post-hoc, the models' posterior probabilities become even more representative of their true performance.
Figure 2 shows the impact of TS, where the calibration curves for SNLI, QQP, and SWAG shift closer to the ideal diagonal. For instance, temperature scaling reduced BERT's ECE on the SNLI dataset from 2.54 to 1.14.
Out-of-Domain Robustness and Label Smoothing
Calibration typically degrades under domain shift, as models encounter examples they should be uncertain about but often guess with high confidence. However, pre-trained models remain significantly more robust than simpler baselines. On the difficult HellaSWAG (OOD) task, RoBERTa's calibration error was 3.4x lower than the DA baseline.
While Temperature Scaling is the "silver bullet" for in-domain data, Label Smoothing is far more effective for OOD robustness. On the adversarial HellaSWAG dataset, RoBERTa trained with label smoothing achieved an ECE of 2.14, compared to 11.93 for the standard version. This represents a massive leap in reliability without sacrificing significant accuracy.
Conclusion
Pre-trained Transformers are not just more accurate than their predecessors; they are also significantly more honest about their own uncertainty. While domain shift still poses a challenge, simple techniques like temperature scaling and label smoothing can make these models remarkably reliable. Future work remains to determine if these findings extend to generative tasks or structured prediction, but for classification, Transformers prove to be surprisingly trustworthy.
Summary updated