Region-dependent temperature scaling for certainty calibration and application to class-imbalanced token classification (2022)

Abstract: Certainty calibration is an important goal on the path to interpretability and trustworthy AI. Particularly in the context of human-in-the-loop systems, high-quality low to mid-range certainty estimates are essential. In the presence of a dominant high-certainty class, for instance the non-entity class in NER problems, existing calibration error measures are completely insensitive to potentially large errors in this certainty region of interest. We introduce a region-balanced calibration error metric that weights all certainty regions equally. When low and mid certainty estimates are taken into account, calibration error is typically larger than previously reported. We introduce a simple extension of temperature scaling, requiring no additional computation, that can reduce both traditional and region-balanced notions of calibration error over existing baselines.

## introduction calibrating the certainty estimates of neural networks is of the utmost importance for interpretability of results and building trust in ai systems. ideally, if a model outputs some prediction with an associated probability, we would like to interpret that quantity as the probability of a correct prediction (i.e. as a meaningful certainty estimate) @xcite . however, contemporary models are consistently over-confident in their output probabilities @xcite . @xcite demonstrates that overconfident models can arise by overfitting to the negative log-likelihood (nll) loss, without overfitting to the classification accuracy. many calibration methods involve modulating the output logits somehow, according to a prescribed functional form. the parameters of the modulation function are learned on the associated validation set by minimizing the nll loss (thereby correcting the overfit). @xcite , as well as many subsequent studies (e.g. @xcite , showcase the surprising effectiveness of temperature scaling, a single-parameter modulation function. the calibration error is reported as a single quantity computed on the associated test set. typically, the error is composed of a sum of observed errors across the certainty landscape, visualized using a reliability diagram @xcite . however, not all regions contribute equally, especially in the case of class-imbalanced datasets. consider an output with a predicted certainty of 99.9% vs. an expected actual certainty of 99.8%. in terms of human interpretability and intervention, this difference is negligible. now consider 79% predicted certainty vs. 71% expected certainty. clearly the second case is one we should care more about correcting. however, as we will discuss in the following section, the presence of a dominant high-certainty class can cause the first discrepancy to contribute more to the reported calibration error than the second. high quality mid-certainty estimates are most impactful for human-in-the-loop applications, yet current error measures are not sensitive to this region. here we take ner @xcite @xcite as a case study for class-imbalanced token classification. naturally, the "outside" or non-entity class dominates the dataset. in the following section, we introduce a region-balanced calibration error. we then introduce region-dependent temperature scaling, a calibration method that further reduces error over traditional temperature scaling, across various ner scenarios, without additional computation. ## region-balanced expected calibration error the most popular calibration error metric is the expected calibration error (ece) @xcite . a test set is partitioned into certainty bins, each low-quality mid-certainty estimates (b) sample reliability diagram for the case of low-quality certainty estimates in the mid-certainty region. figure 1: reliability diagrams contrasting two cases with equal ece values. both cases have the same support distribution (yellow), where 90% of all samples have an estimated certainty above 0.95. in each bin, the confidence (blue) is defined as the mean certainty of samples in the bin (i.e. the predicted certainty). the accuracy (red) is the proportion of samples with a correct prediction (i.e. the actual certainty). the calibration error per bin is the difference in predicted and actual certainty. in case (a), calibration error is consistently low across all certainty regions. in case (b), calibration error is high across the mid-certainty regions. however, because of the dominant support in the highest certainty bin, this error is undetected by the ece measure. refer to figure 1 for an illustrated example. one extension of ece is to find bin partitions adaptively @xcite , such that each bin contains an equal number of samples, and each bin contributes equally to the overall error. the result is that many more bins exist in the high certainty region, each of which are narrower in width. essentially, adaptive-ece reports the exact same error quantity as ece in theory, but estimates the quantity using a finer-toothed comb. neither metric is informative on lower or mid-certainty regions if support is dominated by a high-certainty class. maximum expected calibration error (mece) @xcite partially tells the story of lowcertainty regions by reporting the maximum bin error. however, mece is overly sensitive to outlier bins. for example, if a single sample happens to fall in the 0-5% certainty bin, and it has the correct predicted class, we have @xmath0.95, which is clearly an unusable characterization of the calibration error as a whole. here we consider region-balanced ece (rb-ece) as a way to characterize calibration error weighted evenly across certainty regions. simply, the error in each bin b i contributes to the error equally, subject to some threshold support requirement n @xmath1. the set of bins that meet this requirement is denoted by θ. alternative threshold requirements such as variance in conf(b i ) vs. bin size could be explored in the future. another possible extension is custom bin-weighting according to a certainty region of interest for your application (e.g. for human-in-theloop systems with an intervention criterion). ## region-dependent temperature scaling the idea underlying all calibration methods is generally to modulate overconfident predictions. in traditional temperature scaling (ts), a higher temperature means stronger modulation. temperature is taken to be a constant, meaning all samples are treated with the same modulation strength. the idea underlying region-dependent temperature scaling (rd-ts) is simply that the most confident predictions likely need greater modulation than less confident predictions, and therefore temperature should depend on the uncalibrated certainty. if we consider the hypothetical limit of a 0% confidence score, it is intuitive that this does not need any modulation. to investigate this idea empirically, we apply ts to subsets of the ontonotes dataset, partitioned according to uncalibrated confidence scores. for each confidence region, the ideal temperature is shown in figure 2 . as expected, temperature increases as a function of confidence. a linear fit sufficiently describes the dependence. within uncertainty, the intercept is equal to the expected value of 1 (t (@xmath2, corresponding to no modulation). to apply rd-ts, uncalibrated logits ⃗ a are scaled as ⃗ @xmath3. temperature is now a function of confidence t (h) = mh + 1, where @xmath4. the slope m is the single parameter controlling modulation strength. to estimate m, one could repeat temperature scaling on multiple data subsets, collect data points, and fit the slope as in figure 2 . however, this method increases computational overhead. instead, let us estimate m from the original ts constant t 0 and some knowledge of the validation dataset which was used to compute t 0 . each sample in the validation set has an ideal temperature, here taken to be in the form t @xmath5. assuming each sample contributed to the found t 0 equally, t 0 = 1 n n i (mh i + 1). given access to the validation set, this sum can be computed exactly to find m. however, we can further approximate the sum by loosely assuming that the data has a high proportion of samples (say ≈ 90%) with very high certainty estimates (say ≈ .99 on average). then the sum is dominated by the first leading term, t 0 ≈ .9(.99m + 1). this quick sketch is sufficient to achieve good error reduction over the baseline ts method. the numerical exactness is figure 2 : the ontonotes 5.0 validation set is split into 14 bins according to uncalibrated confidence scores h. for each subset, regular temperature scaling is applied to find the ideal t 0 as a function of average confidence. blue: linear regression fit of empirical data (@xmath6.402 ± .108, @xmath7.943 ± .073 with a 95% confidence interval). red: region-dependent temperature scaling parameter t (h) as determined by our protocol (see points 1-3). both methods produce equivalent results within the uncertainty. rd-ts is a simple extension of temperature scaling which requires no additional training. like temperature scaling, rd-ts cannot change the predicted class or model accuracy (unlike some other generalizations, vector and matrix scaling). ## discussion and conclusion good quality mid-range certainty estimates are essential for productive human-model interactions. despite this, existing calibration error measures can be insensitive to all but the highest certainty regions. we propose a region-balanced error metric to probe this unreported information. when low and mid-certainty regions are taken into account, greater calibration errors are revealed. further, we explore the idea of a certaintydependent temperature. while previous generalizations of ts, such as vector and matrix scaling, allow certainty dependence by increasing the number of learned parameters, these methods are generally outperformed by ts @xcite . rather than allowing a complicated certainty dependence, we enforce a simple linear dependence (motivated by intuition and an empirical example) without introducing any learnable parameters. unlike vector and matrix scaling, rd-ts cannot change the relative ranking of logits, and therefore model accuracy is retained (in single-label settings). one line of future work could be to apply rd-ts on top of weighted temperature scaling, a method known to decrease variance in calibration error among classes @xcite . another line of work would be to investigate whether improved certainty estimates can increase model accuracy (in multi-label settings where predictions are applied by meeting a certainty threshold), especially in out-of-domain problems. finally, it is important to note that our discussion of a region-balanced error measure, as well as our sketch derivation of the rd-ts method, have been generally applicable to any problem with a dominant proportion of high-certainty predictions. this situation does arise in any token classification problem with a dominant "easy" class, as is the case in ner, however this situation can equally occur in class-balanced situations. therefore, region-dependent temperature scaling can find utility beyond ner, token classification, or classimbalanced situations.