Manuscript Offprint

arXiv:2610.21248

Beyond Confidence: Rethinking Uncertainty Calibration in Deep Code Models

Ravishka Rathnasuriya, Wei Yang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Ravishka Rathnasuriya

Department of Computer Science

University of Texas at Dallas

ravishka.rathnasuriya@utdallas.edu

Wei Yang

Institute of Systems for Advanced Computing

Fudan University

yang_wei@fudan.edu.cn

Abstract—Deep learning models have shown significant promise in code-related tasks. While confidence calibration techniques have been proposed to improve model reliability, their effectiveness in real-world tasks with strict accuracy requirements remains uncertain. In this paper, we investigate two key questions: first, whether existing measurement metrics, including confidence scores and uncertainty metrics, are effective for guiding selective prediction; and second, whether existing calibration techniques can improve these metrics to better identify cases where model predictions are likely to succeed or fail.

We conduct a systematic study on defect prediction and vulnerability detection using seven code models, evaluating thirteen uncertainty signals and three widely used post-hoc calibration methods. Our analysis reveals three major findings: (1) even strong uncertainty signals can remain poorly calibrated and provide limited separation at the high-confidence end, constraining selective prediction in practice; (2) standard post-hoc calibrators often improve calibration scores but do not consistently translate into better selective prediction behavior; and (3) commonly used calibration metrics can disagree with selective prediction performance, underscoring the need to evaluate both jointly. Moreover, our findings motivate a decision-oriented view of reliability in deep code models, where calibrated scores must be evaluated together with selective-prediction quality and retained-region risk before they can support accept-defer deployment.

I. INTRODUCTION

Deep learning code models have demonstrated impressive capabilities in various code-related tasks such as defect prediction and vulnerability detection [1]-[9]. To improve the reliability of these models, recent research has explored confidence calibration techniques that align predicted probabilities with true correctness likelihoods [10]-[14]. However, the practical effectiveness of these techniques in code tasks remains unclear, particularly when models are used in automated systems where inaccurate predictions can lead to costly failures. In such cases, low-confidence predictions are often deferred to human experts. This paper investigates whether existing calibration methods genuinely enhance code model reliability or whether alternative approaches provide more trustworthy guidance.

While recent techniques [13]–[15] have been proposed to improve the confidence calibration on code models, these techniques often treat calibration accuracy as an end in itself rather than as a tool to enhance downstream performance. These techniques primarily aim to align predicted confidence scores with empirical correctness, yet these studies seldom evaluate whether better-calibrated confidence actually improves the utility of code models in practice. In particular, these studies overlook whether calibration improvements lead to gains in accuracy or selective prediction [16], [17], where the model produces an output only when it is sufficiently confident, and otherwise abstains to avoid unreliable predictions. In contrast, our work extends beyond calibration by jointly examining selective prediction and reliability assessment, two concerns that are essential for reliable deployment but often neglected in prior studies. This broader focus helps clarify how calibration can support trustworthy and actionable predictions in real-world settings.

Our investigation is motivated by two key concerns. First, we examine whether existing confidence and uncertainty scores are reliable indicators of prediction quality in code models. Unlike models in other domains, code models face unique challenges that affect their trustworthiness. One such issue is their tendency to rely on superficial patterns rather than truly understanding the semantics of the code, which can lead to misleading predictions. These models may confidently label a vulnerable function as safe simply because it resembles patterns seen in non-vulnerable code. This becomes especially problematic when the vulnerability is hidden within well-structured code that appears correct on the surface. Another challenge is that models often focus on local syntax but fail to capture important relationships across different parts of the codebase, which further reduces their ability to make reliable predictions. In such cases, relying only on confidence or uncertainty scores may not reflect when the model is making a mistake. Even if the score is well-calibrated, it might still assign high confidence to an incorrect prediction. This raises the question of whether existing [18]–[26] or new metrics tailored for code model behavior could offer better signals for deciding when model outputs can be trusted.

Even if confidence or uncertainty scores are accepted as reasonable inputs for calibration, widely used calibration metrics face important limitations. Metrics like Expected Calibration Error (ECE) [27] and Uncertainty Calibration Error (UCE) [28] focus on aligning predicted probabilities with true correctness across the entire confidence range. However, this broad averaging places equal weight on all predictions, including low-confidence ones that are often ignored in real applications. In practice, such predictions are typically treated as unreliable by default, regardless of how well they are calibrated. What matters more is the accuracy of high-confidence predictions, since these are the outputs that users are most likely to trust. For code-related tasks, errors in this high-confidence region are especially costly. Yet, current calibration metrics often under-represent these cases, providing limited insight into how well the model performs when it is most certain. As a result, improvements in overall calibration may obscure critical failures in the predictions that matter most for reliable deployment.

To address the limitations of existing work, this paper investigates the practical reliability of calibrated deep code models through a focused study of code classification tasks. We intentionally restrict our empirical evaluation to defect prediction and vulnerability detection because they provide a clean setting in which correctness and uncertainty can be defined at the example level. This allows us to assess behavioral calibration and selective prediction without conflating the analysis with unresolved measurement issues in generative code tasks. At the same time, this setting remains important in its own right as code classification is a core form of code understanding, and it provides a meaningful basis for evaluating how well code models distinguish reliable from unreliable predictions in software engineering workflows.

Within this scope, we study two related questions. First, we evaluate whether current uncertainty signals are effective for selective prediction, that is, whether they can distinguish which predictions a model should make and which it should defer (Section IV). Second, we examine whether standard post-hoc calibration techniques improve a model's ability to separate reliable from unreliable predictions. While these methods are designed to align predicted probabilities with empirical correctness, their value for deployment-oriented decision-making in code tasks remains unclear.

Through a systematic study across SE tasks, we assess how uncertainty estimation and calibration influence a model's capacity to support selective prediction. Our study yields three takeaways about reliability in deep code classification. First, uncertainty signals can remain poorly calibrated and often fail to reliably prioritize the highest-confidence predictions, which are most critical for practical deployment. This limits how effectively selective prediction can stratify outputs by reliability. As a result, selective prediction gains can plateau and become unstable at high rejection, where decisions are driven by a small retained subset and minor ranking errors have outsized impact. Second, post-hoc calibration improves probability alignment but does not guarantee improved selective decision quality. Even when calibration metrics improve, models can continue to produce high-confidence mistakes, which directly undermines accept–defer behavior. Third, commonly used evaluation metrics provide incomplete guidance when used in isolation. Global calibration scores summarize average alignment but can miss the failure mode most relevant to deployment, namely whether errors are assigned low confidence. This motivates reporting calibration and selective prediction performance jointly, and analyzing how ranking quality changes across the confidence spectrum.

Building on these empirical results, the paper develops a broader account of reliability in deep code models. We show that reliability failure is shaped jointly by data ambiguity, representational bias, optimization objectives, and deployment-time decisions, rather than by score miscalibration alone. This explains why better global calibration does not always translate into safer selective prediction. More importantly, it motivates a shift in software engineering research toward decision-oriented reliability methods and evaluation criteria that emphasize accepted-set safety and behavior in the high-confidence region.

In summary, this paper makes the following contributions:

• Joint focus on calibration and abstention: We study uncertainty calibration together with selective prediction, which are ignored in prior calibration work.

• Empirical study: A large-scale evaluation of 13 uncertainty metrics and three post-hoc calibration methods across seven code models and two SE tasks, revealing persistent miscalibration, especially in high-confidence regions.

• Analysis of metric limitations: We show that common calibration metrics (e.g., ECE) often fail to reflect true prediction reliability.

• Operationalizing uncertainty for SE: We show how uncertainty should be evaluated for accept–defer deployment using calibration quality, selective-prediction quality, and retained-region risk.

References (61)