NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Neural Rankers for Code Generation via Inter-Cluster Modeling

Hung Quoc To, Minh Huynh Nguyen, Nghi D. Q. Bui · Submission to ICLR 2024 · Rejected

TL;DR

When generating code with Large Language Models (CodeLLMs), sampling multiple candidate programs often produces correct solutions alongside subtle bugs. The authors introduce SRank, an execution-based reranking strategy that clusters candidate programs by output and ranks them based on their inter-cluster functional overlap. By measuring how much candidate clusters agree with one another across model-generated test inputs, SRank significantly improves pass@1 accuracy without requiring any model fine-tuning.

What Problem Does This Paper Address?

CodeLLMs generate diverse candidate programs under sampling-based decoding, but identifying the single best solution remains a major bottleneck. Prior reranking techniques cluster solutions (e.g., by matching execution outputs as in AlphaCode, or by grouping programs that pass the same generated unit tests as in CodeT).

However, existing approaches treat clusters in isolation. For example, methods that group solutions based solely on pass/fail outcomes often lump together programs that fail for completely different reasons, obscuring functional distinctions. Furthermore, they miss the broader consensus signals across different clusters: if two clusters disagree on edge cases but agree on the vast majority of inputs, that relationship holds valuable information about program correctness.

Methods

SRank evaluates code candidate clusters collectively through a matrix of execution agreement:

  1. Candidate & Test Generation: Given a programming prompt, the target CodeLLM samples $N$ code solutions and $M$ model-generated test cases (consisting of test inputs $z_i$ and expected outputs $\hat{o}_i$).
  2. Exact-Output Clustering: Solutions are executed against the generated test inputs. Solutions with identical execution output vectors across all inputs are grouped into functional clusters $C = \{C_1, C_2, \dots, C_K\}$.
  3. Inter-Cluster Interaction Matrix ($I$): For each pair of clusters $C_i$ and $C_j$, SRank computes their functional overlap: $$I_{ij} = \frac{1}{M} \sum_{k=1}^M \delta(o_{ik} = o_{jk})$$ where $o_{ik}$ is the execution output of cluster $C_i$ on test input $k$, and $\delta$ is an indicator function.

  4. Validation Vector & Ranking Score ($R$): An internal validation vector $V \in \mathbb{R}^{K \times 1}$ aggregates cluster-level statistics (such as cluster size, pass rate against generated assertions, or sequence log-likelihoods). The final ranking is determined by: $$R = I \cdot V$$ The cluster with the highest cumulative score in $R$ is prioritized, and a representative solution is returned.

Candidate Solutions ──► Run on Test Inputs ──► Functional Clusters
                                                       │
                                            Compute Overlap Matrix (I)
                                            & Cluster Features (V)
                                                       │
                                            Final Score R = I · V

Datasets

The authors evaluated SRank on two standard code synthesis benchmarks:

  • HumanEval: 164 hand-crafted Python programming challenges covering algorithms, comprehension, and basic mathematics.
  • MBPP (Sanitized): ~1,000 crowd-sourced Python programming problems focused on fundamental programming and standard library usage.

Evaluations were conducted across 9 CodeLLMs spanning 6B to 34B parameters, including WizardCoder (15B, 34B), StarCoder, Codex002, and CodeGen/CodeGen2.5.

Key Insights and Ideas

  • The Diversity of Errors: Drawing inspiration from consensus paradigms like RANSAC, the core intuition is that buggy solutions fail in idiosyncratic ways, whereas correct solutions tend to converge on identical behavior. The probability of two independently generated incorrect programs sharing the same wrong functional behavior across diverse inputs is empirically shown to be very low (<10–13%).
  • Interactions Beat Isolated Metrics: A cluster might be relatively small (e.g., lower frequency), but if its outputs overlap heavily with several other large clusters, it is far more likely to be an optimal implementation.
  • Semantic Consistency via Execution: Clustering strictly on identical execution outputs avoids CodeT's pitfall of grouping programs that happen to satisfy the same binary pass/fail conditions while behaving wildly differently on failed tests.

Key Results

SRank achieves consistent improvements across model families over greedy decoding, random sampling, and reranking baselines (CodeT and Coder-Reviewer):

  • HumanEval (pass@1):
  • WizardCoder-34B: Achieves 75.31% (vs. 72.36% for CodeT and 68.90% for greedy).
  • Codex002: Achieves 69.66% (vs. 65.80% for CodeT and 66.90% for Coder-Reviewer).
  • StarCoder: Reaches 53.99% (vs. 50.51% for CodeT and 39.63% for greedy).
  • Delivers an average improvement of ~6.1% over CodeT/Coder-Reviewer and +23.07% over random sampling.
  • MBPP-S (pass@1):
  • WizardCoder-34B reaches 64.14%; Codex002 reaches 69.25%.
  • Shows an average improvement of +17.64% over random sampling.
  • Compatibility: Multiplying the interaction matrix $I$ with alternative ranking features (such as Coder-Reviewer mutual-information scores) consistently boosts their performance (e.g., from 57.15% to 62.69% on HumanEval).

Limitations and Future Work

  • Test Generation Overhead: Executing dozens of solutions on dozens of synthetic test cases increases compute and latency.
  • Sensitivity to Test Count: Ablations indicate that when test cases are sparse (<30 generated tests), noisy interactions can occasionally degrade performance relative to basic cluster sizing.
  • No Learned Verification: SRank relies solely on execution outputs without fine-tuning a dedicated verification model; the authors note that combining inter-cluster consensus with trained neural program verifiers (like LEVER) represents a natural next step.

Summary updated

BibTeX
@inproceedings{to2024neural,
  author = {Hung Quoc To and Minh Huynh Nguyen and Nghi D. Q. Bui},
  title = {{Neural Rankers for Code Generation via Inter-Cluster Modeling}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-acl.220},
}
Figure