How Certain is Your Transformer?

Artem Shelmanov, Evgenii Tsymbalov, Dmitry Puzyrev, Kirill Fedyanin, Alexander Panchenko, Maxim Panov

Introduction

Transformer models like BERT and ELECTRA have revolutionized Natural Language Understanding (NLU), yet they suffer from a critical flaw: they are often "overconfident" even when their predictions are incorrect. In high-stakes fields such as medicine or law, a model must not only be accurate but also trustworthy. This requires reliable uncertainty estimation (UE)—a confidence score that signals when a model might be making a mistake.

While standard softmax outputs are notoriously overconfident, existing solutions like model ensembles are too computationally expensive for many real-world applications. This paper explores more efficient alternatives, specifically focusing on Monte Carlo (MC) dropout and a novel application of Determinantal Point Processes (DPP).

Quantifying Uncertainty in Transformers

The researchers investigated three primary strategies for generating uncertainty scores:

  1. Standard MC Dropout (All Layers): Dropout remains active during inference across all layers. Multiple stochastic passes are performed, and the variance in predictions serves as the uncertainty measure.
  2. Last-Layer MC Dropout: To save time, dropout is applied only to the final linear layer. This allows the heavy Transformer "body" to be computed just once.
  3. DPP-based Dropout: This innovative approach uses Determinantal Point Processes to select a diverse subset of neurons to drop, rather than dropping them at random. This diversity aims to capture more uncertainty information with fewer inference passes.

These methods were paired with acquisition functions like Sampled Max Probability, Probability Variance, and BALD (Bayesian Active Learning by Disagreement) to produce final uncertainty scores.

Experimental Results

The methods were evaluated on the GLUE benchmark using ELECTRA-base and DistilBERT across three tasks: SST-2 (sentiment), CoLA (grammaticality), and MRPC (paraphrase detection).

Performance Gains

A key finding was the "all or nothing" nature of standard MC dropout. Applying it only to the last layer often performed worse than the deterministic baseline. However, applying it to all layers yielded significant improvements in error detection, measured by ROC AUC.

Performance gains (relative to baseline ROC AUC) of various uncertainty estimation methods on ELECTRA-base. Bold values indicate significant improvements.

As shown in the results for ELECTRA-base, the MC-all configuration provided the most substantial boosts, particularly on the MRPC task (+7.5%). Interestingly, the DPP-last approach acted as a powerful middle ground, outperforming standard last-layer dropout and even matching all-layer performance on tasks like SST-2.

The Efficiency Trade-off

While MC-all is the most effective for error detection, it comes with a massive computational penalty. Running 20 stochastic passes through a 30+ layer Transformer increases inference time by approximately 2,000%.

Inference time (seconds) comparison between deterministic baselines and various stochastic dropout methods.

The data highlights the efficiency of the DPP-based approach. While MC-all takes over 65 seconds for the SST-2 task, DPP-last completes the same task in just 3.33 seconds—adding less than 10% overhead to the deterministic baseline while still providing meaningful uncertainty estimates.

Conclusion

For applications where safety is paramount and compute is secondary, applying MC dropout across all layers remains the gold standard for uncertainty estimation. However, for real-time applications, DPP-based dropout on the last layer offers a compelling alternative, providing a significant boost in reliability with negligible impact on latency. Future work will look toward combining these methods with calibration techniques to ensure that confidence scores translate accurately to real-world probabilities.

Summary updated

BibTeX
@inproceedings{shelmanov2021how,
  author = {Artem Shelmanov and Evgenii Tsymbalov and Dmitry Puzyrev and Kirill Fedyanin and Alexander Panchenko and Maxim Panov},
  title = {{How Certain is Your Transformer?}},
  booktitle = {EACL},
  year = {2021},
  doi = {10.18653/v1/2021.eacl-main.157},
}
Figure