Code Is More Than Text: Uncertainty Estimation for Code Generation

Yuling Shi, Caiqi Zhang, Yuexian Li, Haopeng Wang, Yeheng Chen, Nigel Collier, Xiaodong GuarXiv 2026

TL;DR

Current uncertainty estimation methods for LLM code generation treat code like standard natural language text, failing to capture its unique structural and executable nature. This paper introduces a three-axis framework—lexical, algorithmic, and functional—tailored specifically to code characteristics. The resulting ensemble significantly boosts uncertainty detection accuracy, while its single-pass lexical component offers a highly efficient, low-cost alternative to expensive multi-pass baselines.

What Problem Does This Paper Address?

When Large Language Models (LLMs) are deployed as code generators, they often produce "silently wrong" programs—outputs that look perfectly fine syntactically but contain critical logical bugs. Knowing when to trust an LLM's output (uncertainty estimation, or UE) is vital for safe deployment, autocomplete filtering, and agentic workflows.

However, existing code UE techniques are direct ports from natural language processing, treating code as a uniform sequence of tokens. This ignores three fundamental truths about code:

  1. Token Fragility: A single flipped character or operator can completely break a program.
  2. Intent-Code Gap: The high-level algorithmic strategy can be correct even if the low-level syntax implementation has minor variations or errors.
  3. Executability: Unlike natural language text, code can be run and verified dynamically.

Methods

The authors propose a code-specific framework that evaluates uncertainty along three orthogonal axes:

  1. Lexical Uncertainty (Top-K Max Entropy): Instead of averaging token entropy across the entire sequence (which dilutes the signal of critical errors), this method isolates and averages only the $K$ highest-entropy tokens (default $K=5$). This directly targets token fragility.
  2. Algorithmic Uncertainty (Pseudo-code Consistency): To bridge the intent-code gap, the model is prompted to generate multiple natural-language solution plans (pseudo-code) rather than raw code. The consistency among these plans is measured using a step-aware ROUGE-L metric.
  3. Functional Uncertainty (Behavioral Consistency): Capitalizing on executability, the model self-generates test cases, executes the generated candidate code against them, and computes the failure rate as an uncertainty score.

The final approach combines these three signals into a rank-normalized weighted ensemble.

The proposed three-axis uncertainty estimation framework for code generation.

Datasets

The framework was evaluated across four prominent Python code generation benchmarks:

  • APPS (Introductory & Interview subsets): Focuses on competitive programming problems with varying algorithmic depth.
  • HumanEval: A standard benchmark of short, function-level programming tasks.
  • MBPP (Mostly Basic Python Problems): Contains fundamental programming problems.
  • HumanEval-X: Used to test cross-language generalization across C++, Java, Go, and JavaScript.

Key Insights and Ideas

  • Uncertainty is Sparse: Traditional natural language metrics average entropy across the whole sequence. In code, uncertainty is highly localized; focusing strictly on the top-5 most uncertain tokens yields a much cleaner signal.
  • The Orthogonality of Code Signals: Pairwise correlations between the lexical, algorithmic, and functional axes are remarkably low (Pearson coefficients between 0.10 and 0.22). This proves they capture completely distinct failure modes: syntax slips vs. strategic confusion vs. semantic runtime errors.
  • Code vs. Comment Entropy: Splitting token entropy reveals a fascinating asymmetry. Code token uncertainty strongly correlates with actual bugs, whereas comment token uncertainty actually anti-correlates with functional correctness. Naively averaging them together hurts performance.
Figure 2: Per-sample disagreement analysis on Qwen3- Coder-30B on MBPP.

Key Results

  • State-of-the-Art Performance: Across five code LLMs (including Qwen3 and DeepSeek-Coder-V2), the three-axis ensemble improved the average Area Under the Receiver Operating Characteristic (AUROC) from 0.696 (the strongest natural language baseline) to 0.776 (+8.1 points).
  • High Efficiency: On Qwen3-14B, the single-pass Top-5 token entropy matched the performance of the strongest multi-pass baseline while being over 3× cheaper computationally, making it ideal for latency-sensitive applications like real-time IDE autocomplete.

Limitations and Future Work

  • Execution Environment Dependency: The functional axis relies heavily on having a secure, sandboxed execution environment, which may not always be available or easy to configure for complex, multi-file software systems.
  • Scope of Tasks: The study primarily targets function-level code generation with well-defined inputs and outputs. Extending this framework to open-ended tasks like large-scale refactoring or multi-file repository edits remains an open challenge.
  • Downstream Integration: While the paper establishes strong calibration performance, future work is needed to explore how these uncertainty metrics perform when integrated directly into downstream agentic decision-making policies or human-in-the-loop triage systems.

Summary updated

BibTeX
@misc{shi2026code,
  author = {Yuling Shi and Caiqi Zhang and Yuexian Li and Haopeng Wang and Yeheng Chen and Nigel Collier and Xiaodong Gu},
  title = {{Code Is More Than Text: Uncertainty Estimation for Code Generation}},
  year = {2026},
  eprint = {2606.09577},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2606.09577},
}
Figure