Source-linked AI summary

Calibration of Pre-trained Transformers

Shrey Desai, Greg Durrett

arXiv:2003.07892v3cs.CLcs.LG

TL;DR

The paper asks whether BERT and RoBERTa provide posterior probabilities that accurately reflect example-level correctness. It evaluates them across three tasks and in-domain or challenging out-of-domain settings, finding that out-of-the-box models calibrate in-domain, temperature scaling improves in-domain calibration, and label smoothing helps out-of-domain calibration.

  • Problem

    The paper investigates whether pre-trained Transformers’ posterior probabilities accurately measure how likely their predictions are to be correct.

  • Method

    The authors evaluate BERT and RoBERTa on natural language inference, paraphrase detection, and commonsense reasoning across in-domain and challenging out-of-domain datasets.

  • Results

    Pre-trained models are calibrated in-domain out-of-the-box, temperature scaling improves in-domain calibration, and label smoothing improves out-of-domain calibration.

  • Takeaways & Limitations

    BERT and RoBERTa achieve low in-domain ECE with temperature scaling and remain competitive out-of-domain when trained with label smoothing.

Abstract

from arXiv · show

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.

1 Introduction

The paper examines whether pre-trained Transformers’ posterior probabilities reliably reflect correctness, addressing trust and test-time error diagnosis. It evaluates BERT and RoBERTa across in-domain and challenging out-of-domain tasks, finding strong calibration and effective calibration interventions.

  • Calibration tests whether posterior probabilities match the empirical likelihood that predictions are correct.A calibrated model provides a signal that it “knows what it doesn’t know.”
  • BERT and RoBERTa are evaluated on natural language inference, paraphrase detection, and commonsense reasoning.Each task includes challenging out-of-domain datasets with dissimilar input distributions.
  • Pre-trained models are calibrated in-domain even when used out-of-the-box.This result concerns evaluation without post-processing such as temperature scaling.
  • Out-of-domain, pre-trained models are significantly better calibrated than overconfident non-pre-trained models such as ESIM.The comparison targets settings containing more examples that models should be uncertain about.
  • Temperature scaling improves in-domain calibration, while training regularization that reduces certainty improves out-of-domain calibration.The paper uses a single scalar to rescale logits and label smoothing to smooth probabilities.

2 Related Work

Prior calibration research spans statistical machine learning and NLP, but had not analyzed large-scale pre-trained models. The paper also distinguishes calibration from explicit out-of-domain detection because calibration applies when domains are not discretely defined.

  • Calibration has been studied in forecasting, medicine, computer vision, and both nonneural and neural NLP.These prior studies cover multiple applications and tasks.
  • Previous NLP work had not analyzed large-scale pre-trained models.This paper addresses that gap by studying such models directly.
  • Explicit out-of-domain detection assumes a discrete notion of domain, whereas calibration handles less-quantized domain settings.Calibration is presented as a more general paradigm for uncertainty under distribution differences.

3 Posterior Calibration

Posterior calibration means aligning model confidence with empirical correctness. The paper measures this alignment with expected calibration error computed across equally sized confidence bins.

  • A model is calibrated when confidence estimates align with empirical likelihoods.For predictions assigned probability 0.7, calibration implies approximately 70% correctness.
  • Perfect calibration requires P(Y = y|Q = q) = q for confidence Q and label Y.This formalizes agreement between predicted confidence and observed conditional outcomes.
  • Expected calibration error is a weighted average of the differences between accuracy and confidence across confidence bins.The experiments use 10 equally sized bins.

4 Experiments

The experiments evaluate BERT, RoBERTa, and comparison models across three language-understanding tasks under in-domain and challenging out-of-domain shifts. Results show that pre-training improves calibration, temperature scaling helps in-domain, and label smoothing helps out-of-domain.

  • Tasks and Datasets: The study evaluates natural language inference, paraphrase detection, and commonsense reasoning with corresponding in-domain and out-of-domain datasets.The datasets are SNLI/MNLI, QQP/TwitterPPDB, and SWAG/HellaSWAG; out-of-domain training splits are unused.
  • Out-of-the-box Calibration: BERT and RoBERTa consistently achieve higher accuracies and lower ECEs than the non-pre-trained comparison models.On HellaSWAG, RoBERTa reduces ECE by a factor of 3.4 compared to DA.
  • Out-of-the-box Calibration: RoBERTa consistently achieves lower in-domain ECE than BERT and outperforms BERT out-of-domain in all but one setting.The results associate more robust pre-training with more calibrated posteriors, while further pre-training changes remain an open question.
  • Post-hoc Calibration: Label smoothing generally improves out-of-domain calibration, particularly under strong distribution shifts such as HellaSWAG.RoBERTa-LS obtains a factor of 5.8 less ECE than RoBERTa-MLE on HellaSWAG without seeing HellaSWAG during fine-tuning.
  • Post-hoc Calibration: Optimal temperature values are generally 1-1.4 for in-domain tasks, while TwitterPPDB and HellaSWAG require larger values than MNLI.The results suggest that the degree of distribution shift and the magnitude of T may be closely related.

5 Conclusion

The paper examines posterior calibration as a lens on confidence-score trustworthiness, finding that pre-trained Transformers calibrate well in-domain and remain competitive out-of-domain with appropriate techniques.

  • BERT and RoBERTa with temperature scaling achieve low expected calibration errors in-domain.
  • Label smoothing makes BERT and RoBERTa competitive out-of-domain by encouraging greater uncertainty.

B Training and Optimization

The paper uses standard pre-trained BERT and RoBERTa checkpoints alongside non-pre-trained baselines, with specified fine-tuning settings.

  • BERT and RoBERTa use the bert-base-uncased and roberta-base checkpoints from HuggingFace Transformers.

C Reproducibility

The reported development-set results cover accuracy and expected calibration error for pre-trained models, while post-hoc calibration is not reported on those same sets because they are used for tuning.

  • Table 6 reports accuracy and expected calibration error for BERT and RoBERTa on the considered datasets’ development sets.
  • Post-hoc calibration results are omitted on development sets because those sets are used for tuning.
Loading 2003.07892v3…