Fine-grained Approaches for Confidence Calibration of LLMs in Automated Code Revision
Abstract
In today's AI-assisted software engineering landscape, developers increasingly depend on LLMs that are highly capable, yet inherently imperfect. The tendency of these models to produce incorrect outputs can reduce developer productivity. To this end, a canonical mitigation method is to provide calibrated confidence scores that faithfully reflect their likelihood of correctness at the instance-level. Such information allows users to make immediate decisions regarding output acceptance, abstain error-prone outputs, and better align their expectations with the model's capabilities. Since post-trained LLMs do not inherently produce well-calibrated confidence scores, researchers have developed post-hoc calibration methods, with global Platt-scaling of sequence-level confidence scores proving effective in many generative software engineering tasks but remaining unreliable or unexplored for automated code revision (ACR) tasks such as program repair, vulnerability repair, and code refinement. We hypothesise that the coarse-grained nature of this conventional method makes it ill-suited for ACR tasks, where correctness is often determined by local edit decisions and miscalibration can be sample-dependent, thereby motivating fine-grained confidence calibration. To address this, our study proposes local Platt-scaling applied separately to three different fine-grained confidence scores. Through experiments across 3 separate tasks and correctness metrics, as well as 14 different models of various sizes, we find that fine-grained confidence scores consistently achieve lower calibration error across a broader range of probability intervals, and this effect is further amplified when global Platt-scaling is applied. Our proposed approaches offer a practical solution to eliciting well-calibrated confidence scores, enabling more trustworthy and streamlined usage of imperfect models in ACR tasks.
Figures & tables
| Study | Task | Single-Inference Confidence Score | Post-hoc Scaler |
| Spiess et al. [ 21 ] | Function Synthesis Line-level Completion Automated Program Repair | Average Token Probability Sequence Likelihood | Global Platt-Scaling |
| Virk et al. [ 22 ] | Code Summarisation | Average Token Probability Normalised Sequence Likelihood | Global Platt-Scaling |
| (Ours) | Automated Program Repair Vulnerability Repair Automated Code Refinement | Average Token Probability Normalised Sequence Likelihood Minimum Token Probability Lowest- Token Probability Attention-Weighted Uncertainty | Global Platt-Scaling Local Platt-Scaling |
| Bold: Contribution from this Study | |||
| DCF-Bug | DCF-Vul | CR-Trans | ||||||
| n=777 | n=1,041 | n=900 | ||||||
| Model | Size | EM | EP | EM | EP | CP | EM | EP |
| 8B | 32.9 | 59.3 | 7.7 | 29.2 | 59.6 | 36.3 | 59.3 | |
| Llama-3.1 | 70B | 34.5 | 58.0 | 9.7 | 31.2 | 72.9 | 45.9 | 67.1 |
| 7B | 32.3 | 55.6 | 8.8 | 26.1 | 40.2 | 40.1 | 60.4 | |
| CodeLlama | 70B | 40.5 | 66.8 | 12.0 | 29.0 | 44.9 | 51.8 | 72.4 |
| EM | EP | ||||||||||||||||||||||||||||||
| sl_norm | avg | min | low-K | attn- | sl_norm | avg | min | low-K | attn- | ||||||||||||||||||||||
| Model | Size | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ||||||||||
| 8B | 0.11 | 0.21 | 3 | 0.03 | 0.21 | 2 | 0.05 | 0.16 | 9 | 0.06 | 0.18 | 7 | 0.04 | 0.18 | 7 | 0.07 | 0.23 | 3 | 0.06 | 0.23 | 2 | 0.08 | 0.21 | 8 | 0.08 | 0.21 | 7 | 0.08 | 0.22 | 7 | |
| Llama-3.1 | 70B | 0.11 | 0.21 | 3 | 0.12 | 0.22 | 2 | 0.04 | 0.18 | 8 | 0.04 | 0.18 | 7 | 0.04 | 0.18 | 7 | 0.12 | 0.22 | 2 | 0.10 | 0.23 | 2 | 0.04 | 0.20 | 7 | 0.04 | 0.21 | 6 | 0.04 | 0.21 | 6 |
| 7B | - | - | 1 | - | - | 1 | 0.04 | 0.19 | 8 | 0.06 | 0.21 | 5 | 0.04 | 0.20 | 6 | 0.05 | 0.24 | 2 | - | - | 1 | 0.04 | 0.22 | 7 | 0.03 | 0.23 | 6 | 0.03 | 0.23 | 6 | |
| CodeLlama | 70B | 0.03 | 0.24 | 2 | - | - | 1 | 0.04 | 0.20 | 8 | 0.08 | 0.21 | 7 | 0.08 | 0.21 | 7 | - | - | 1 | - | - | 1 | 0.05 | 0.18 | 6 | 0.06 | 0.19 | 5 | 0.06 | 0.19 | 5 |
| EP | CP | ||||||||||||||||||||||||||||||
| sl_norm | avg | min | low-K | attn- | sl_norm | avg | min | low-K | attn- | ||||||||||||||||||||||
| Model | Size | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ||||||||||
| 8B | 0.04 | 0.20 | 2 | 0.02 | 0.20 | 2 | 0.02 | 0.19 | 7 | 0.02 | 0.20 | 4 | 0.02 | 0.20 | 4 | 0.04 | 0.24 | 2 | - | - | 1 | 0.06 | 0.23 | 5 | 0.04 | 0.24 | 4 | - | - | 1 | |
| Llama-3.1 | 70B | 0.03 | 0.21 | 2 | 0.03 | 0.21 | 2 | 0.05 | 0.19 | 6 | 0.05 | 0.20 | 5 | 0.05 | 0.20 | 5 | - | - | 1 | - | - | 1 | 0.05 | 0.19 | 3 | - | - | 1 | - | - | 1 |
| 7B | 0.02 | 0.19 | 2 | - | - | 1 | 0.03 | 0.19 | 3 | 0.02 | 0.19 | 3 | 0.01 | 0.19 | 3 | 0.03 | 0.24 | 2 | 0.03 | 0.24 | 2 | 0.04 | 0.24 | 3 | 0.02 | 0.24 | 4 | 0.03 | 0.24 | 2 | |
| CodeLlama | 70B | 0.03 | 0.21 | 2 | - | - | 1 | 0.03 | 0.20 | 2 | 0.03 | 0.20 | 3 | 0.03 | 0.20 | 3 | - | - | 1 | - | - | 1 | - | - | 1 | 0.08 | 0.25 | 2 | 0.08 | 0.25 | 2 |
| EM | EP | ||||||||||||||||||||||||||||||
| sl_norm | avg | min | low-K | attn- | sl_norm | avg | min | low-K | attn- | ||||||||||||||||||||||
| Model | Size | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ||||||||||
| 8B | 0.22 | 0.27 | 2 | 0.23 | 0.27 | 2 | 0.16 | 0.20 | 6 | 0.17 | 0.22 | 4 | 0.17 | 0.23 | 4 | 0.23 | 0.27 | 3 | 0.24 | 0.28 | 2 | 0.17 | 0.23 | 7 | 0.18 | 0.24 | 6 | 0.18 | 0.24 | 5 | |
| Llama-3.1 | 70B | 0.25 | 0.28 | 2 | 0.25 | 0.29 | 2 | 0.17 | 0.22 | 7 | 0.19 | 0.25 | 5 | 0.19 | 0.25 | 5 | 0.21 | 0.24 | 3 | 0.21 | 0.25 | 3 | 0.14 | 0.21 | 7 | 0.16 | 0.23 | 5 | 0.16 | 0.23 | 5 |
| 7B | - | - | 1 | - | - | 1 | 0.19 | 0.23 | 6 | 0.21 | 0.25 | 4 | 0.21 | 0.25 | 4 | 0.29 | 0.31 | 2 | 0.29 | 0.31 | 2 | 0.25 | 0.27 | 5 | 0.26 | 0.29 | 4 | 0.26 | 0.29 | 4 | |
| CodeLlama | 70B | 0.31 | 0.33 | 2 | 0.31 | 0.34 | 2 | 0.21 | 0.25 | 7 | 0.25 | 0.29 | 5 | 0.25 | 0.29 | 5 | 0.31 | 0.29 | 2 | 0.32 | 0.30 | 2 | 0.26 | 0.25 | 5 | 0.28 | 0.27 | 4 | 0.28 | 0.27 | 4 |
| EM | EP | ||||||||||||||||||
| min | low-K | attn- | min | low-K | attn- | ||||||||||||||
| Model | Size | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ||||||
| 8B | 0.03 (-0.02) | 0.15 (-0.01) | 9 (=0) | 0.03 (-0.03) | 0.18 (=0) | 7 (=0) | 0.03 (-0.01) | 0.18 (=0) | 7 (=0) | 0.06 (-0.02) | 0.20 (-0.01) | 9 (+1) | 0.05 (-0.03) | 0.21 (=0) | 8 (+1) | 0.06 (-0.02) | 0.22 (=0) | 9 (+2) | |
| Llama-3.1 | 70B | 0.03 (-0.01) | 0.17 (-0.01) | 8 (=0) | 0.04 (=0) | 0.18 (=0) | 7 (=0) | 0.04 (=0) | 0.18 (=0) | 7 (=0) | 0.03 (-0.01) | 0.20 (=0) | 8 (+1) | 0.04 (=0) | 0.21 (=0) | 6 (=0) | 0.04 (=0) | 0.21 (=0) | 6 (=0) |
| 7B | 0.02 (-0.02) | 0.19 (=0) | 8 (=0) | 0.03 (-0.03) | 0.21 (=0) | 5 (=0) | 0.02 (-0.02) | 0.20 (=0) | 6 (=0) | 0.03 (-0.01) | 0.22 (=0) | 7 (=0) | 0.03 (=0) | 0.23 (=0) | 6 (=0) | 0.03 (=0) | 0.23 (=0) | 6 (=0) | |
| CodeLlama | 70B | 0.04 (=0) | 0.20 (=0) | 8 (=0) | 0.07 (-0.01) | 0.20 (-0.01) | 7 (=0) | 0.07 (-0.01) | 0.20 (-0.01) | 7 (=0) | 0.04 (-0.01) | 0.18 (=0) | 7 (+1) | 0.06 (=0) | 0.19 (=0) | 5 (=0) | 0.06 (=0) | 0.19 (=0) | 5 (=0) |
| EP | CP | ||||||||||||||||||
| min | low-K | attn- | min | low-K | attn- | ||||||||||||||
| Model | Size | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ||||||
| 8B | 0.02 (=0) | 0.19 (=0) | 7 (=0) | 0.02 (=0) | 0.20 (=0) | 4 (=0) | 0.02 (=0) | 0.20 (=0) | 5 (+1) | 0.03 (-0.03) | 0.23 (=0) | 5 (=0) | 0.03 (-0.01) | 0.24 (=0) | 4 (=0) | 0.02 | 0.24 | 3 (+2) | |
| Llama-3.1 | 70B | 0.05 (=0) | 0.19 (=0) | 6 (=0) | 0.05 (=0) | 0.20 (=0) | 5 (=0) | 0.05 (=0) | 0.20 (=0) | 5 (=0) | 0.04 (-0.01) | 0.19 (=0) | 3 (=0) | 0.05 | 0.20 | 3 (+2) | 0.05 | 0.20 | 3 (+2) |
| 7B | 0.03 (=0) | 0.19 (=0) | 3 (=0) | 0.03 (=0) | 0.19 (=0) | 3 (=0) | 0.01 (=0) | 0.19 (=0) | 3 (=0) | 0.03 (-0.01) | 0.24 (=0) | 3 (=0) | 0.02 (=0) | 0.24 (=0) | 4 (=0) | 0.03 (=0) | 0.24 (=0) | 2 (=0) | |
| CodeLlama | 70B | 0.02 (-0.01) | 0.20 (=0) | 3 (+1) | 0.03 (=0) | 0.20 (=0) | 4 (+1) | 0.03 (=0) | 0.20 (=0) | 4 (+1) | 0.05 | 0.23 | 6 (+5) | 0.05 (-0.03) | 0.24 (-0.01) | 2 (=0) | 0.05 (-0.03) | 0.24 (-0.01) | 2 (=0) |
| EM | EP | ||||||||||||||||||
| min | low-K | attn- | min | low-K | attn- | ||||||||||||||
| Model | Size | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ECE | BC | ||||||
| 8B | 0.13 (-0.03) | 0.20 (=0) | 9 (+3) | 0.18 (-0.01) | 0.22 (=0) | 4 (=0) | 0.17 (=0) | 0.23 (=0) | 4 (=0) | 0.07 (-0.10) | 0.22 (-0.01) | 9 (+2) | 0.11 (-0.07) | 0.23 (-0.01) | 8 (+2) | 0.18 (=0) | 0.24 (=0) | 5 (=0) | |
| Llama-3.1 | 70B | 0.08 (-0.09) | 0.22 (=0) | 9 (+2) | 0.19 (=0) | 0.25 (=0) | 5 (=0) | 0.19 (=0) | 0.25 (=0) | 5 (=0) | 0.09 (-0.05) | 0.20 (-0.01) | 8 (+1) | 0.08 (-0.08) | 0.21 (-0.02) | 7 (+2) | 0.16 (=0) | 0.23 (=0) | 5 (=0) |
| 7B | 0.12 (-0.07) | 0.22 (-0.01) | 8 (+2) | 0.21 (=0) | 0.25 (=0) | 4 (=0) | 0.21 (=0) | 0.25 (=0) | 4 (=0) | 0.10 (-0.15) | 0.22 (-0.05) | 7 (+2) | 0.18 (-0.08) | 0.25 (-0.04) | 7 (+3) | 0.26 (=0) | 0.29 (=0) | 4 (=0) | |
| CodeLlama | 70B | 0.10 (-0.11) | 0.22 (-0.03) | 8 (+1) | 0.23 (+0.02) | 0.28 (-0.01) | 8 (+3) | 0.25 (=0) | 0.29 (=0) | 5 (=0) | 0.18 (-0.08) | 0.22 (-0.03) | 7 (+2) | 0.12 (-0.16) | 0.21 (-0.06) | 8 (+4) | 0.28 (=0) | 0.27 (=0) | 4 (=0) |
| EM | EP | ||||||
| Model | Scaler | ECE | BC | ECE | BC | ||
| Platt-scaling | 0.04 (0.04) | 0.20 (0.20) | 8 (8) | 0.05 (0.04) | 0.18 (0.18) | 6 (7) | |
| Temperature-scaling | 0.18 (0.18) | 0.24 (0.24) | 4 (4) | 0.02 (0.02) | 0.18 (0.18) | 4 (6) | |
| Histogram Binning | 0.04 (0.05) | 0.20 (0.20) | 5 (7) | 0.05 (0.05) | 0.18 (0.18) | 6 (6) | |
| CodeLlama-70b | Isotonic Regression | 0.05 (0.04) | 0.20 (0.20) | 8 (6) | 0.05 (0.05) | 0.18 (0.19) | 5 (6) |
| Platt-scaling | 0.04 (0.04) | 0.18 (0.17) | 8 (8) | 0.05 (0.03) | 0.18 (0.18) | 7 (8) | |
| EP | CP | ||||||
| Model | Scaler | ECE | BC | ECE | BC | ||
| Platt-scaling | 0.05 (0.05) | 0.19 (0.19) | 6 (6) | 0.05 (0.04) | 0.19 (0.19) | 3 (3) | |
| Temperature-scaling | 0.18 (0.17) | 0.22 (0.21) | 7 (10) | 0.23 (0.23) | 0.25 (0.25) | 2 (2) | |
| Histogram Binning | 0.04 (0.04) | 0.19 (0.19) | 5 (5) | 0.05 (0.04) | 0.19 (0.19) | 2 (3) | |
| Llama-3.1-70B | Isotonic Regression | 0.04 (0.04) | 0.19 (0.19) | 5 (5) | 0.05 (0.04) | 0.19 (0.19) | 2 (3) |
| Platt-scaling | 0.06 (0.05) | 0.19 (0.19) | 6 (6) | 0.03 (0.03) | 0.23 (0.22) | 3 (5) | |
| EM | EP | ||||||
| Model | Scaler | ECE | BC | ECE | BC | ||
| Platt-scaling | 0.21 (0.10) | 0.25 (0.22) | 7 (8) | 0.26 (0.18) | 0.25 (0.22) | 5 (7) | |
| Temperature-scaling | 0.09 (0.08) | 0.21 (0.21) | 4 (5) | 0.21 (0.13) | 0.23 (0.20) | 3 (5) | |
| Histogram Binning | 0.20 (0.08) | 0.24 (0.21) | 6 (7) | 0.23 (0.16) | 0.24 (0.21) | 5 (6) | |
| CodeLlama-70b | Isotonic Regression | 0.20 (0.07) | 0.24 (0.21) | 7 (7) | 0.23 (0.16) | 0.24 (0.21) | 5 (7) |
| Platt-scaling | 0.19 (0.12) | 0.21 (0.21) | 6 (10) | 0.20 (0.08) | 0.20 (0.17) | 7 (8) | |
Confidence Estimation in Language Models
Confidence estimation in language models measures whether a model’s uncertainty signals predict answer correctness and support reliable decisions.
See all 246 papers