Abstract
Large Language Models (CodeLLMs) have significantly advanced automated code generation. However, selecting the single correct solution from a pool of sampled candidates remains a persistent challenge. Traditional reranking methods, such as CodeT, cluster solutions based on execution outputs but treat these clusters as independent entities. We present SRank, a novel reranking strategy that models the "functional overlap" between clusters to identify the most representative and likely correct program. By leveraging inter-cluster relationships, SRank achieves a significant average improvement of ~6.1% over previous state-of-the-art methods across major benchmarks including HumanEval and MBPP-S.
1. Introduction
When generating code with models like GPT-4 or StarCoder, researchers typically employ sampling-based decoding to produce multiple candidate solutions. The primary hurdle is the "reranking" problem: identifying the correct solution among dozens or hundreds of candidates. Existing state-of-the-art (SOTA) approaches like AlphaCode or CodeT utilize execution-based clustering, where programs producing identical outputs for a set of test cases are grouped. The largest cluster is then prioritized under the assumption that popularity correlates with correctness.
However, these methods suffer from a "cluster isolation" problem. They ignore the nuanced functional similarities between different clusters. Two clusters might fail on different edge cases but agree on the majority of test inputs; current methods fail to utilize this shared "partial correctness." SRank addresses this by shifting the focus from cluster size to inter-cluster consensus.
2. The SRank Methodology
SRank introduces a four-step pipeline designed to model the functional relationships within the candidate pool:
- Generation: The CodeLLM generates a set of candidate solutions (S) and a corresponding set of model-generated test cases (T).
- Clustering: Solutions are executed against the test cases. Programs that produce identical output sets are grouped into clusters.
- Computing the Interaction Matrix (I): This is the core innovation of SRank. It calculates the "functional overlap" between every pair of clusters. If Cluster A and Cluster B produce the same output for 8 out of 10 test cases, their overlap score is 0.8.
- Final Scoring: The final rank is derived by multiplying this Interaction Matrix by a validation vector (V), which incorporates traditional features like cluster size or pass rates.
The intuition behind SRank is that while there are many ways to be wrong, there are fewer ways to be "mostly right." Incorrect solutions tend to fail in diverse, inconsistent ways. A solution that exhibits high functional agreement with the rest of the candidate pool—even if it is not in the largest cluster—is statistically more likely to be correct.
3. Experimental Setup
The effectiveness of SRank was evaluated across three major benchmarks:
- HumanEval: The industry standard for evaluating basic Python coding tasks.
- MBPP-S (Sanitized): A collection of entry-level Python programming concepts.
- APPS: Challenging competition-level programming problems categorized into Introduction, Interview, and Competition levels.
The researchers tested SRank against a diverse fleet of models, including WizardCoder (15B/34B), StarCoder, CodeGen, Codex, and Claude 3 Opus.
4. Key Results and Analysis
SRank consistently outperformed existing SOTA rerankers like CodeT and Coder-Reviewer. On HumanEval, SRank achieved a 75.31% pass@1 with WizardCoder34B, a substantial improvement over the 66.9% achieved by Coder-Reviewer.
Key observations from the results include:
- Average Gains: SRank provided an average improvement of ~6.1% across various models and benchmarks.
- Robustness: The method proved effective even with limited sample sizes or test cases, enhancing its practical utility for real-world deployment where compute is a constraint.
- Scalability: On the APPS "Competition" level tasks, SRank maintained its lead over baselines, demonstrating that the "consensus" approach scales effectively with problem difficulty.
5. Conclusion and Future Work
SRank provides a powerful execution-based lens for filtering CodeLLM hallucinations. By prioritizing "consensus over popularity," it effectively identifies the most functionally sound programs. Future work will focus on extending SRank to multilingual benchmarks and exploring its application in more complex domains like system architecture or UI code, where functional overlap is more difficult to quantify through simple outputs.
Summary updated