Ensemble-Based Uncertainty Estimation for Code Correctness Estimation

Yunxiang Wei, Tianlin Li, Yuwei Zheng, Yanni Dong, Aishan Liu, Qiang Hu, Xiaoyu Zhang, Mingfei Cheng, Jian YangarXiv 2026

TL;DR

While Large Language Models (LLMs) are excellent at generating code, they are frequently "confidently wrong," repeatedly producing identical but incorrect solutions that fool standard single-model uncertainty checks. This paper introduces Ensemble Semantic Entropy (ESE), a method that aggregates outputs from diverse models to catch these hidden errors through cross-model disagreement. By using ESE as a routing signal in a cascading framework (Cas), the authors maintain state-of-the-art code generation accuracy while slashing computational costs (FLOPs) by up to 64.9%.

What Problem Does This Paper Address?

When using LLMs for code generation, how do we know if the generated code is actually correct without running an exhaustive, expensive test suite?

A popular approach is Uncertainty Estimation, specifically Semantic Entropy (SE). The idea is simple: sample multiple code snippets from a single model. If the model consistently generates programs that do the same thing (i.e., they are semantically equivalent), the model is confident, and the code is likely correct. If the outputs vary wildly, the model is uncertain.

However, the authors identify a critical flaw: LLM overconfidence. A single model will often converge on a consistent but incorrect logic pattern across multiple diverse generations. To a standard single-model SE metric, this looks like "confident correctness," resulting in a dangerous false positive.

Figure 1: Calculation of Ensemble Semantic Entropy on a motivating example. The problem requires traversing an array nums backwards to collect integers from 1 to 𝑘with minimal steps. Qwen3-8B generates three programs that share the same incorrect semantics (only counting numbers within [1,𝑘]), resulting in zero semantic entropy. GLM4-9B, however, generates programs that incorrectly output indices in forward order. By aggregating these five programs, the ensemble reveals the semantic disagreement, resulting in high uncertainty that correctly flags the error, effectively avoiding the false positive.

Methods

To counter single-model overconfidence, the authors propose two core innovations:

  1. Ensemble Semantic Entropy (ESE & EDSE): Instead of sampling from one model, ESE samples from an ensemble of diverse model families (e.g., GLM and Qwen). The key insight is that while an individual model family might be confidently wrong in a specific way, different model families rarely share the exact same blind spots. Programs are grouped into clusters using Functional Clustering (Func)—meaning they are executed on a set of inputs, and those that produce identical outputs are clustered together. ESE then calculates the entropy across these multi-model clusters. EDSE is a black-box variant that uses empirical frequencies when token-level probabilities are unavailable.
  2. Cas: A Multi-layer Cascading Framework: To make this practical and cost-effective, the authors design a test-time scaling framework. Instead of running a massive, expensive model for every prompt, the system starts with a cheaper, lightweight ensemble (Layer 1). It computes a cascade score based on public test pass rates and ESE. If the confidence is high, it exits early. If ESE detects high uncertainty, the problem escalates to a larger, more powerful model (Layer 2).

Datasets

The approach was evaluated on LiveCodeBench (Release v2), a rigorous benchmark consisting of recent competitive programming problems (from platforms like AtCoder and Codeforces). LiveCodeBench is specifically designed to prevent data contamination and features high-quality, hidden test cases to verify functional correctness.

Key Insights and Ideas

  • Spurious Consistency is Real: As shown in the paper's analysis, when single models generate incorrect code, they still cluster around a dominant incorrect answer up to 49% of the time. When ensembling diverse models, this spurious consistency drops to just 6%.
  • Functionality Over Form: To measure code uncertainty, you must evaluate execution behavior, not text similarity. The authors compared five clustering methods (including text-based BLEU, NLI entailment, and code embeddings). Functional clustering (Func) vastly outperformed all of them in correlating uncertainty with actual correctness.
Figure 2: Comparison of the distribution of the largest cluster sizes in incorrect problems. Single models (GLM4-9B, Qwen3- 8B) frequently show high consistency in incorrect answers, whereas the ensemble substantially reduces this spurious consistency.

Key Results

  • Stronger Correctness Signal: ESE and EDSE consistently showed a much stronger negative Pearson correlation with program errors compared to single-model baselines.
  • Better Selective Generation: In tasks where the model must choose whether to accept an answer or abstain under strict False Positive Rate (FPR) constraints (e.g., 5% FPR), ESE improved prediction accuracy by 53.4% for Qwen3-Coder-30B.
  • Massive Compute Savings: The Cas cascading framework achieved near-identical performance to standard heavy-compute scaling (Best-of-N sampling on a massive model) while reducing inference compute (FLOPs) by 64.9% on Qwen3-Coder-485B and 63.1% on gpt-oss-20B.

Limitations and Future Work

  • Benchmark Scope: Evaluation was restricted to competitive programming problems with unique, well-defined correct behaviors. How ESE handles open-ended tasks with multiple distinct, valid algorithmic approaches remains an open question.
  • Test Generation Bias: The functional clustering relies on an LLM (Qwen3-Coder-30B) to generate the initial test inputs. If the test generator itself shares blind spots with the code generators, it could introduce evaluation bias.
  • Ensemble Overhead: While cascading saves compute overall, maintaining and running multiple distinct model families in production adds engineering and infrastructure complexity.

Summary updated

BibTeX
@misc{wei2026ensemble,
  author = {Yunxiang Wei and Tianlin Li and Yuwei Zheng and Yanni Dong and Aishan Liu and Qiang Hu and Xiaoyu Zhang and Mingfei Cheng and Jian Yang},
  title = {{Ensemble-Based Uncertainty Estimation for Code Correctness Estimation}},
  year = {2026},
  eprint = {2603.27098},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2603.27098},
}
Figure