Introspective Uncertainty Estimation for LLM-Based Code Generation
Organizations: Fachbereich Design Informatik Medien der Hochschule RheinMain
Abstract
Large Language Models (LLMs) are increasingly used for code generation but can produce fluent yet functionally incorrect outputs, which limits trust in their usage for practical software engineering workflows. This thesis investigates whether Introspective Uncertainty Estimation (IUE), based on internal hidden-state representations of LLMs, can reliably indicate correctness at the response and line levels for code generation tasks. The objective is to determine the extent to which hidden states encode information about functional code correctness and how this can be leveraged for practical risk assessment and fault localization. Methodologically, this thesis combines response-level evaluation on LiveCodeBench (LCB) and BigCodeBench (BCB) with an augmentation pipeline that derives token- and line-level labels from incorrect programs. In this setup, it compares static and dynamic response-level features, evaluates generalization across tasks, programming domains, and token positions, and studies line-level fault localization. The results show that hidden states contain a strong response-level correctness signal. Static single-token probes perform best, while more elaborate dynamic strategies yield no consistent gains. While generalization across tasks, domains, and token positions is feasible, setting-dependent degradation largely remains for real-world software projects. At a fine granularity, line-level prediction is substantially harder than response-level estimation. However, in a conditional localization setup with known-incorrect programs, Top-K point-of-failure ranking remains effective. Overall, the findings suggest that hidden states are a robust and informative resource for estimating functional code correctness, supporting a two-stage workflow that combines response-level risk screening with targeted line-level prioritization.
Figures & tables
| Difficulty | Count | Percentage |
|---|---|---|
| Easy | 322 | 30.5% |
| Medium | 383 | 36.3% |
| Hard | 350 | 33.2% |
| Model | Release Date | Knowledge Cutoff | Layers | Hidden Sizes |
|---|---|---|---|---|
| Qwen3-Coder [ 49 ] | Jul 31, 2025 | Nov 20, 2024 | 48 | 2048 |
| GPT-OSS-20B [ 33 ] | Aug 5, 2025 | Jun 1, 2024 | 24 | 2880 |
| NVIDIA-Nemotron-3-Nano [ 31 ] | Dec 15, 2025 | Nov 25, 2025 | 52 | 2688 |
| Olmo 3.1 Instruct (32B) [ 32 ] | Nov 20, 2025 | Dec 1, 2024 | 64 | 5120 |
| Model | LCB | BCB Instruct | BCB Fusion |
|---|---|---|---|
| Qwen3-Coder | 5561 / 3963 / 1026 | 5348 / 6052 / 0 | 6743 / 4650 / 7 |
| GPT-OSS-20B | 6488 / 1504 / 2558 | 5148 / 6195 / 57 | 6493 / 4847 / 60 |
| NVIDIA-Nemotron-3-Nano | 4641 / 663 / 5246 | 4949 / 6379 / 72 | 6217 / 5056 / 127 |
| Olmo 3.1 Instruct (32B) | 4551 / 3381 / 2618 | 4122 / 6732 / 546 | 5252 / 5869 / 279 |
| Model | Kept (n, %) | Dropped by Filter (n, %) | ||
|---|---|---|---|---|
| no_program | no_fix_found | line_filter | ||
| Qwen3-Coder | 6329 (59.99%) | 1134 (10.75%) | 1928 (18.27%) | 1159 (10.99%) |
| GPT-OSS-20B | 6756 (64.04%) | 2672 (25.33%) | 893 (8.46%) | 229 (2.17%) |
| Var. | Tokens T/F (%F) | Lines T/F (%F) | Tok. | Line | Diff. E/M/H (%) |
| Qwen3-Coder | |||||
| V1 | 756482/11431 (1.49%) | 105056/1290 (1.21%) | 121.3 | 16.8 | 49.3/39.1/11.6 |
| V2 | 833748/137425 (14.15%) | 116387/18194 (13.52%) | 133.2 | 18.5 | 43.3/39.6/17.1 |
| V3 | 182887/137425 (42.90%) | 25575/18194 (41.57%) | 185.0 | 25.3 | 11.0/46.9/42.1 |
| GPT-OSS-20B | |||||
| V1 | 971108/3386 (0.35%) | 143270/393 (0.27%) | 144.2 | 21.3 | 46.7/38.1/15.2 |
| Probe Model | Last Code | Last Token | First Code | First Token |
|---|---|---|---|---|
| XGBoost | 0.9026 | 0.9002 | 0.8804 | 0.8626 |
| MLP (1 hidden layer) | 0.8967 | 0.8945 | 0.8775 | 0.8619 |
| MLP (2 hidden layers) | 0.9057 | 0.8962 | 0.8827 | 0.8638 |
| LLM | LCB (XGBoost / MLP-2) | BCB-Instruct (XGBoost / MLP-2) |
|---|---|---|
| Qwen3-Coder | 0.9026 / 0.9057 | 0.6841 / 0.6947 |
| GPT-OSS-20B | 0.8610 / 0.8519 | 0.6374 / 0.6571 |
| NVIDIA-Nemotron-3-Nano | 0.8911 / 0.8841 | 0.6419 / 0.6381 |
| Olmo 3.1 Instruct (32B) | 0.8542 / 0.8556 | 0.7309 / 0.7407 |
| Dataset | Feature | Qwen3-Coder | GPT-OSS-20B | NVIDIA-Nemotron-3-Nano | Olmo 3.1 Instruct (32B) |
|---|---|---|---|---|---|
| LCB | LC | 0.9026 / 0.8484 /0.4576 | 0.8610 /0.9238/0.3369 | 0.8911 / 0.9581 / 0.4415 | 0.8542 /0.8047/0.3287 |
| L | 0.9002/0.8426/ 0.4814 | 0.8570/0.9213/0.3466 | 0.8621/0.9536/0.3766 | 0.8454/0.8015/ 0.3522 | |
| FC | 0.8804/0.8282/0.4318 | 0.8598/ 0.9287 / 0.3957 | 0.8292/0.9398/0.2869 | 0.8429/ 0.8091 /0.3478 | |
| F | 0.8626/0.8344/0.3445 | 0.7800/0.8912/0.1139 | 0.7981/0.9235/0.1192 | 0.8172/0.7918/0.2762 | |
| BCB-Instruct | LC | 0.6841 / 0.5753 / 0.0957 | 0.6374/0.5541/-0.0280 | 0.6381/0.5168/ 0.0423 | 0.7309 / 0.5026 /0.0802 |
| L | 0.6745/0.5293/0.0720 | 0.6532 / 0.5601 / 0.0596 | 0.6411 / 0.5294 /0.0326 | 0.7251/0.4804/ 0.1100 |
| Dataset | Feature | Qwen3-Coder | GPT-OSS-20B | NVIDIA-Nemotron-3-Nano | Olmo 3.1 Instruct (32B) |
|---|---|---|---|---|---|
| LCB | F+L | 0.9034 / 0.8533 / 0.4860 | 0.8348/0.9115/0.2955 | 0.8993 /0.9522/0.3928 | 0.8559/0.8123/ 0.3275 |
| FC+LC | 0.9012/0.8435/0.4507 | 0.8672 / 0.9309 / 0.3972 | 0.8856/ 0.9562 / 0.4226 | 0.8586 / 0.8168 /0.3200 | |
| BCB-Instruct | F+L | 0.6839 / 0.5808 / 0.0948 | 0.6569 /0.5638/ 0.0756 | 0.6335/0.5313/-0.0132 | 0.6893/0.3971/0.0714 |
| FC+LC | 0.6768/0.5801/0.0787 | 0.6549/ 0.5699 /-0.0422 | 0.6406 / 0.5325 / 0.0345 | 0.7264 / 0.4868 / 0.0730 | |
| BCB-Fusion | F+L | 0.6209/0.7184/0.0356 | 0.7076 / 0.7601 / 0.1247 | 0.6790 / 0.6792 / 0.0345 | 0.7284 / 0.6124 / 0.0810 |
| FC+LC | 0.6680 / 0.7332 / 0.0848 | 0.7011/0.7440/0.1128 | 0.6512/0.6547/-0.0033 | 0.7137/0.5993/0.0602 |
| Dataset | LLM | XGBoost (best single-token) | LSTM (full sequence) | LSTM (newline filter) |
|---|---|---|---|---|
| LCB | Qwen3-Coder | 0.9026 | 0.8897 (-0.0129) | 0.8824 (-0.0202) |
| GPT-OSS-20B | 0.8610 | 0.8508 (-0.0102) | 0.8504 (-0.0106) | |
| NVIDIA-Nemotron-3-Nano | 0.8911 | 0.7851 (-0.1060) | 0.7778 (-0.1133) | |
| Olmo 3.1 Instruct (32B) | 0.8542 | 0.8135 (-0.0407) | 0.8008 (-0.0534) | |
| BCB-Instruct | Qwen3-Coder | 0.6841 | 0.6523 (-0.0318) | 0.6707 (-0.0134) |
| GPT-OSS-20B | 0.6532 | 0.6524 (-0.0008) | 0.6585 (+0.0053) |
| Model, Filter Setting | AUROC | vs. XGBoost |
|---|---|---|
| XGBoost (best single-token baseline) | 0.9026 | 0.0000 |
| LSTM, default entropy filter ( ) | 0.8665 | -0.0361 |
| LSTM, top-entropy ( ) | 0.8770 | -0.0256 |
| LSTM, middle-entropy band ( ) | 0.8779 | -0.0247 |
| LSTM, low-entropy ( ) | 0.8960 | -0.0066 |
| LSTM, low-high entropy band ( ) | 0.8775 | -0.0251 |
| Method | BSS ( ) | Accuracy ( ) |
|---|---|---|
| IUE probe (last-token XGBoost, ours) | 0.5888 | 0.8534 |
| IGLB [ 5 ] | 0.4680 | 0.8239 |
| LINR [ 5 ] | 0.4631 | 0.8216 |
| HB [ 5 ] | 0.3832 | 0.7973 |
| Platt [ 5 ] | 0.3769 | 0.7985 |
| LOGR [ 5 ] | 0.3026 | 0.8269 |
| Train Test | Qwen3-Coder | GPT-OSS-20B | NVIDIA-Nemotron-3-Nano | Olmo 3.1 Instruct (32B) |
|---|---|---|---|---|
| LCB BCB-Instruct | 0.6483 (LC, ) | 0.5970 (L, ) | 0.5838 (F+L, ) | 0.6149 (FC+LC, ) |
| LCB BCB-Fusion | 0.6509 (LC, ) | 0.6875 (L, ) | 0.6236 (L, ) | 0.6713 (L, ) |
| BCB-Instruct LCB | 0.8240 (LC, ) | 0.7342 (LC, ) | 0.7771 (L, ) | 0.7410 (LC, ) |
| BCB-Fusion LCB | 0.8164 (LC, ) | 0.7415 (F+L, ) | 0.8426 (L, ) | 0.8149 (L, ) |
| Model | ID Best | System | Time | Cryptography |
|---|---|---|---|---|
| Qwen3-Coder | 0.6841 | 0.6643 (LC, ) | 0.6402 (L, ) | 0.6353 (L, ) |
| GPT-OSS-20B | 0.6569 | 0.6502 (F+L, ) | 0.6105 (L, ) | 0.6281 (L, ) |
| NVIDIA-Nemotron-3-Nano | 0.6411 | 0.6568 (F+L, ) | 0.6508 (LC, ) | 0.6746 (FC+LC, ) |
| Olmo 3.1 Instruct (32B) | 0.7309 | 0.7107 (LC, ) | 0.7570 (LC, ) | 0.7147 (L, ) |
| Model | Shortfall ( ) | ( ) |
|---|---|---|
| Qwen3-Coder | 0.0217 | -0.0153 |
| GPT-OSS-20B | 0.0219 | -0.0200 |
| NVIDIA-Nemotron-3-Nano | 0.0012 | +0.0218 |
| Olmo 3.1 Instruct (32B) | 0.0178 | -0.0141 |
| Dataset | Model | Random Tail (RT) Fraction | ||||||
|---|---|---|---|---|---|---|---|---|
| 0.001 | 0.05 | 0.25 | 0.5 | 0.75 | 0.95 | 1.0 | ||
| LCB | Qwen3-Coder | 0.9045 | 0.8515 | 0.8351 | 0.8363 | 0.8279 | 0.8326 | 0.8202 |
| GPT-OSS-20B | 0.8551 | 0.7983 | 0.7426 | 0.7364 | 0.7261 | 0.7232 | 0.7212 | |
| NVIDIA-Nemotron-3-Nano | 0.8617 | 0.8128 | 0.7444 | 0.7393 | 0.7808 | 0.7667 | 0.7437 | |
| Olmo 3.1 Instruct (32B) | 0.8440 | 0.7974 | 0.7687 | 0.7563 | 0.7713 | 0.7587 | 0.7708 | |
| BCB-Instruct | Qwen3-Coder | 0.6754 | 0.6302 | 0.5961 | 0.6037 | 0.6027 | 0.5677 | 0.5827 |
| Dataset | Baseline | Qwen3-Coder | GPT-OSS-20B |
|---|---|---|---|
| V1 | Token Line | 0.7258 / 0.0390 | 0.7431 / 0.0533 |
| Line-level (last code token) | 0.7291 / 0.0601 | 0.7318 / 0.0127 | |
| V2 | Token Line | 0.7575 / 0.2308 | 0.7294 / 0.0862 |
| Line-level (last code token) | 0.7639 / 0.2593 | 0.7210 / 0.0651 |
| Dataset | Qwen3-Coder | GPT-OSS-20B |
|---|---|---|
| V1 | 0.7273 / 0.0891 ( ) | 0.7557 / 0.0010 ( ) |
| V2 | 0.7402 / 0.2778 ( ) | 0.7268 / 0.2015 ( ) |
| LLM, Line-level baseline (dataset) | Default F1 ( ) | Best F1 | Best Threshold ( ) |
|---|---|---|---|
| Qwen3-Coder, XGBoost Token Line (V1) | 0.0390 | 0.0660 | 0.8 |
| Qwen3-Coder, XGBoost Line-level (V2) | 0.2593 | 0.3156 | 0.8 |
| Qwen3-Coder, LSTM Line-level (V2) | 0.2778 | 0.2886 | 0.7 |
| Baseline | Qwen3-Coder | GPT-OSS-20B |
|---|---|---|
| XGBoost Token Line | 0.7267 / 0.6675 | 0.7015 / 0.3970 |
| XGBoost Line-level (last code token) | 0.7407 / 0.6560 | 0.7270 / 0.3905 |
| LSTM Line-level | 0.7410 / 0.6456 | 0.7294 / 0.4043 |
| Baseline | Qwen3-Coder | GPT-OSS-20B | ||||
|---|---|---|---|---|---|---|
| Hit@1 | Hit@2 | Hit@3 | Hit@1 | Hit@2 | Hit@3 | |
| Token Line | 0.6163 | 0.7209 | 0.8052 | 0.4937 | 0.6076 | 0.7089 |
| Line-level (last code token) | 0.5669 | 0.6483 | 0.7355 | 0.3418 | 0.5316 | 0.6203 |
| Random (1000 trials) | 0.3766 0.0191 | 0.5102 0.0182 | 0.5883 0.0183 | 0.1940 0.0376 | 0.3054 0.0416 | 0.3836 0.0439 |
Appendix figures & tables7 assets
Supplementary material from the paper’s appendix.
Appendix
| Model | ID Best | Computation |
|---|---|---|
| Qwen3-Coder | 0.6841 | 0.6570 (L, ) |
| GPT-OSS-20B | 0.6569 | 0.6213 (F+L, ) |
| NVIDIA-Nemotron-3-Nano | 0.6411 | 0.6466 (L, ) |
| Olmo 3.1 Instruct (32B) | 0.7309 | 0.7023 (L, ) |
| Model | ID Best | General |
|---|---|---|
| Qwen3-Coder | 0.6841 | 0.6743 (L, ) |
| GPT-OSS-20B | 0.6569 | 0.6402 (L, ) |
| NVIDIA-Nemotron-3-Nano | 0.6411 | 0.6528 (L, ) |
| Olmo 3.1 Instruct (32B) | 0.7309 | 0.7090 (LC, ) |
| Model | ID Best | Network |
|---|---|---|
| Qwen3-Coder | 0.6841 | 0.7294 (F, ) |
| GPT-OSS-20B | 0.6569 | 0.6701 (F, ) |
| NVIDIA-Nemotron-3-Nano | 0.6411 | 0.7259 (F+L, ) |
| Olmo 3.1 Instruct (32B) | 0.7309 | 0.7275 (L, ) |
| Model | ID Best | Visualization |
|---|---|---|
| Qwen3-Coder | 0.6841 | 0.6814 (FC+LC, ) |
| GPT-OSS-20B | 0.6569 | 0.6379 (L, ) |
| NVIDIA-Nemotron-3-Nano | 0.6411 | 0.6328 (LC, ) |
| Olmo 3.1 Instruct (32B) | 0.7309 | 0.6967 (FC+LC, ) |
LLM Uncertainty Estimation
Large language model uncertainty estimation measures when outputs may be wrong, ambiguous, or unreliable to guide safer decisions.
See all 399 papers