An Overview of Uncertainty Calibration for Text Classification and the Role of Distillation (2021)

Abstract: Recent advances in NLP systems, notably the pretraining-and-finetuning paradigm, have achieved great success in predictive accuracy. However, these systems are usually not well calibrated for uncertainty out-of-the-box. Many recalibration methods have been proposed in the literature for quantifying predictive uncertainty and calibrating model outputs, with varying degrees of complexity. In this work, we present a systematic study of a few of these methods. Focusing on the text classification task and finetuned large pretrained language models, we first show that many of the finetuned models are not well calibrated out-of-the-box, especially when the data come from out-of-domain settings. Next, we compare the effectiveness of a few widely-used recalibration methods (such as ensembles, temperature scaling). Then, we empirically illustrate a connection between distillation and calibration. We view distillation as a regularization term encouraging the student model to output uncertainties that match those of a teacher model. With this insight, we develop simple recalibration methods based on distillation with no additional inference-time cost. We show on the GLUE benchmark that our simple methods can achieve competitive out-of-domain (OOD) calibration performance w.r.t. more expensive approaches. Finally, we include ablations to understand the usefulness of components of our proposed method and examine the transferability of calibration via distillation.

## introduction the recent success of nlp systems, notably the pretraining-and-finetuning paradigm has led to widespread applications @xcite @xcite . however, these systems are not always well-calibrated; in many high-stake decision-making scenarios such as med-ical diagnosis, even small errors would have large damage. suppose an ml system predicts a 20% probability a patient has cancer whereas the reality is 40%, diagnosis relying on inaccurate estimates could lead to devastating consequences @xcite . further, interpreting and communicating these uncertainties facilitates better trust between humans and ml systems @xcite @xcite . hence, it is increasingly important for users to understand not only when the systems would succeed, but also when they could fail. one seemingly straightforward approach is to have the systems output predictions and some measure of their confidence/uncertainty. users could then use both the predictions and associated uncertainties to decide how much they would trust the prediction. for example, one might decide to take an umbrella to work only if the confidence of the rain prediction is more than 50%. for many statistical methods, confidence/uncertainty is either part of the system by design (e.g., bayesian methods) or could be efficiently estimated (e.g., linear regressions). unfortunately, for large-scale dnns, estimating uncertainty becomes a challenge @xcite : e.g., nominal probabilities from the softmax function are shown to be uncalibrated estimates of model uncertainty @xcite @xcite . in this work, we present a systematic study on recalibrating current nlp systems, particularly those that fall in the recent popular pretraining-andfinetuning paradigm @xcite , as they are widely deployed in recent state-of-the-art systems and hence it is important that they are well calibrated for safety and transparency. however, the methods discussed in this work could generalize to a broader range of systems. we focus on the calibration not only of the task itself, but also under dataset distributional shift @xcite . we start by introducing uncertainty and calibration, and cover related advances in the deep learning literature. in addition to widely-used maximum calibration error and expected calibration error, we follow previous works @xcite and include additional calibration evaluation metrics for better comparisons (e.g., brier scores and ℓ p calibration error). we conduct experiments on glue classification tasks @xcite and show that finetuned language models are usually not calibrated out-of-the-box, especially when the data comes from a distribution different from the training data. we use the term "out-of-domain" (or "out-ofdistribution", ood) to refer to the setting where the train and evaluation data come from different "distributions". related works in nlp have considered data from similar tasks but from different datasets as ood @xcite . next, in order to make models more calibrated, we study some of the widelyused recalibration methods, with various degrees of effectiveness and computational cost. for example, ensembling models has been shown to be very effective in out-of-domain settings @xcite , but the cost of computation scales with the size of ensembles. on the other hand, distillation @xcite is a widely-known method for improving the system's performance by learning from a stronger teacher model. in this work, we empirically examine the connection between distillation and calibration. notably, we view the objective function of distillation as a regularization term that encourages the student model to match the predictive uncertainty of a stronger, more calibrated teacher model. we conduct analysis experiments to show that the teacher's calibration performance could be distilled into the student model, even when the teacher model's accuracy remains similar. with this insight, we show that simple methods based on distillation could achieve competitive performance in out-ofdomain calibration, without introducing extra computation at inference time. finally, we also conduct ablation experiments to understand the usefulness of components of the method. in summary, our contributions are listed as follows: it has been widely observed that modern neural networks are usually not calibrated out of the box @xcite @xcite . recalibration methods improve calibration by transforming un-calibrated outputs into calibrated outputs/probabilities, and they include scaling-based methods @xcite , histogrambinning-based methods @xcite , and ensembles @xcite . @xcite proposed the scaling-binning calibrator and a more sample-efficient estimator of calibration error. in our work, we describe simple approaches that combine the strength of ensembles and temperature scaling without introducing computation at inference time; we further apply the scaling-binning calibrator to ensure calibration. ensemble-based methods work by aggregating multiple networks trained independently on the entire dataset, and has been shown to achieve strong performance in out-of-domain calibration @xcite . more generally, there are randomization-based ensembles and boosting-based ensembles. within the randomization-based ensembles, we use the entire training dataset to train each model instead of different bootstrap samples of the original training set @xcite . temperature scaling is an extension of platt scaling @xcite . it uses a single scalar parameter @xmath0. given output z i , the confidence prediction is: an extension, called heteroscedastic regression, is used in our work, which replaces the constant scalar with learned values @xcite . knowledge distillation @xcite is a compression technique in which a compact model (usually referred to as the student model) is trained to mimic the behavior of a more powerful teacher model. in the context of classification, knowledge distillation works by augmenting the loss function with an additional term d kl (p i p j ) where p @xmath1, and t controls the smoothness of the output distribution. in this work, we show that distillation can also be used to distill calibration performance, and use it to build simple yet competitive recalibration methods. concurrently, desai and durrett (2020) studied the calibration of pretrained transformers when finetuned to downstream tasks, and @xcite studied the out-of-distribution robustness of pretrained transformers. we are different from them in that first we present a systematic study on the out-of-distribution calibration; second we draw insights from the connection between distillation and temperature scaling to design simple yet competitive recalibration methods; third, we conduct experiments to understand the connection between them empirically; finally, we also include a more comprehensive set of calibration evaluations following @xcite and @xcite . ## setup we include additional details in the supplementary materials. also included are expanded experiment results, such as figures evaluated on more tasks using more evaluation metrics (sec. 6.1), and detailed/expanded results tables as well as accuracy and eces with multiple bin-sizes (sec. 6.2). model. our codebase is largely based on hug-gingface transformers (wolf et al., 2019). when applicable, we use an ensemble size 2, and choose t (eq. 9) based on the brier scores on the validation dataset. the baseline model has 125.2m parameters, the temperature-scaling model (heteroscedastic variant) has 125.8m, and our method has 125.2m (same as the baseline model). data. we perform experiments on the classification tasks from the glue benchmark (wang et al., 2019), and we refer readers to wang et al. (2019) regarding dataset statistics. because the calculation of calibration errors requires access to the ground truth data, which is not available for glue data, we split the validation dataset into two halves, one for validation and the other for test, following desai and durrett (2020). for multinli, we merge the results for both multinli matched and mismatched sections. when computing the out-of-domain performance between the 3-label multinli and other 2-label nli tasks, we follow jiant (pruksachatkun et al., 2020) and merge the predictions/labels that correspond to "neutral" and "contradiction" into a single category. evaluation. our evaluation follows guo et al. (2017), ovadia et al. (2019), and kumar et al. (2019). the train and evaluation data come from the same task for in-domain evaluations, but they come from different tasks of the same type for out-of-domain evaluations. we group mrpc and qqp (paraphrase tasks), and group mnli (2-label version), qnli, rte, and wnli (nli tasks). we leave sst-2 (sentiment), cola (acceptability), and mnli (3-label version, nli) as separate groups. we use the in-domain validation data to train the scaling-binning calibrator. foot_4 analysis experiments details. we conduct experiments on rte, in which we distill teacher models with different ensemble-sizes (from 1 to 6) and the temperature scaling constant (from 0.50 to 2.00 with a step size of 0.02) to student models. each model is then evaluated on both in-domain task (rte) and out-of-domain tasks (mnli-2, qnli, wnli) using confidence, ece, mce, brier scores, sce (debiased) and sce (biased). the numbers represent performances on the validation dataset. ## conclusion and discussion we presented a study of calibration of finetuned language models in the context of text classification, where models are evaluated on in-domain and out-of-domain data. we showed the effectiveness of a few widely-used calibration methods. we illustrated the intuitive connection between distillation and calibration, and described simple yet competitive calibration methods. we conducted experiments to empirically understand whether distillation can be used to distill calibration performance, and showed that the simple methods we described achieved competitive out-of-domain calibration performances. we further presented ablation studies on the usefulness of components of the proposed method and examined the transferability of calibration via distillation. however, our method is limited in that it requires an overhead cost involved in training the student model, which could be expensive in some settings. we leave it to future works to investigate more efficient inferencetime recalibration techniques. thomas wolf, lysandre debut, victor sanh, julien chaumond, clement delangue, anthony moi, pierric cistac, tim rault, r'emi louf, morgan funtowicz, and jamie brew. 2019. huggingface's transformers: state-of-the-art natural language processing. arxiv, abs/1910.03771. li yuan, francis eh tay, guilin li, tao wang, and jiashi feng. 2020. revisit knowledge distillation: a teacher-free framework. in cvpr. sukmin yun, jongjin park, kimin lee, and jinwoo shin. 2020. regularizing class-wise predictions via self-knowledge distillation. in cvpr. bianca zadrozny and charles elkan. 2001. obtaining calibrated probability estimates from decision trees and naive bayesian classifiers. in icml. xinchuan zeng and tony r. martinez. 2000. using a neural network to approximate an ensemble of classifiers. neural processing letters.