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

Abstract

Code Large Language Models (CodeLLMs) have ushered in a new era in code generation advancements. However, selecting the best code solutions from all possible CodeLLM outputs remains a challenge. Previous methods often overlooked the intricate functional similarities and interactions between solution clusters. We introduce SRank, a novel reranking strategy for selecting the best solutions from code generation, focusing on modeling the relationships between clusters of solutions. By quantifying the functional overlap between solution clusters, our approach provides a better ranking strategy for code solutions. Empirical results show that our method achieves remarkable results on the pass@1 score. For instance, on the Human-Eval benchmark, we achieve 69.66% in pass@1 with Codex002, 75.31% with WizardCoder, 53.99% with StarCoder, and 60.55% with CodeGen, surpassing state-of-the-art code generation reranking methods such as CodeT and Coder-Reviewer on the same CodeLLM by a significant margin (approximately 6.1% improvement on average). Even in scenarios with a limited number of sampled solutions and test cases, our approach demonstrates robustness and superiority, marking a new benchmark in code generation reranking.

Introduction

Large Language Models (LLMs) like GPT-4 or StarCoder have demonstrated significant capabilities in automated code generation. However, these models are not infallible. To improve the likelihood of obtaining a correct solution, a common practice is to "sample" the model multiple times, generating a large pool of candidate programs. The critical challenge then lies in reranking: identifying the most likely correct solution from this pool to present to the user.

Existing reranking techniques typically group candidates into clusters based on identical execution outputs for a given set of test cases. However, these methods often treat clusters as independent entities, ignoring the "intricate functional similarities" between them. SRank addresses this by modeling the interactions between different functional groups, leveraging the principle that while incorrect solutions tend to fail in diverse ways, correct solutions—even if syntactically different—exhibit high functional overlap.

Methods

SRank introduces a shift from ranking individual solutions to modeling inter-cluster relationships. The framework operates through a four-stage pipeline:

  1. Generation: A CodeLLM generates $N$ code solutions and $M$ synthetic test cases based on a natural language task description.
  2. Clustering: Solutions are grouped into clusters ($C_1, C_2, ... C_K$) if they produce identical execution outputs across all test cases.
  3. Functional Overlap (Interaction Matrix): The core innovation involves calculating an interaction matrix $I$. Each entry $I_{ij}$ quantifies the degree to which Cluster $i$ and Cluster $j$ produce the same output across the test suite.
  4. Final Ranking: A final ranking score for each cluster is computed by combining the interaction matrix with cluster-specific features, such as cluster size or pass rates.
Overview of the SRank framework for code solution reranking.

This approach moves beyond binary pass/fail metrics. By analyzing the degree of agreement between clusters, SRank becomes more robust to noisy, model-generated test cases that might contain errors.

Experimental Results

The researchers evaluated SRank across three primary benchmarks: HumanEval, MBPP-S, and the more challenging APPS dataset. The method was tested against a variety of models, including Codex, WizardCoder, StarCoder, and CodeGen.

SRank consistently outperformed existing state-of-the-art reranking methods like CodeT and Coder-Reviewer. As shown in the performance comparison table, SRank achieved a pass@1 score of 75.31% with WizardCoder34B on HumanEval, a substantial improvement over the 68.90% achieved by greedy decoding and the 72.36% by CodeT.

Comparison of SRank against baseline methods on HumanEval and MBPP-S benchmarks.

Across various models, SRank provided an average improvement of approximately 6.1% over previous reranking methods. Notably, the system maintains its superiority even with a limited number of sampled solutions and test cases, making it computationally efficient for real-world deployment. Even on world-class models like Claude 3 Opus, SRank improved the pass@1 score from 78.05% to 79.18%.

Conclusion

SRank establishes a new benchmark in code generation reranking by effectively modeling inter-cluster functional overlaps. By leveraging the consensus among different but similar functional groups, it identifies correct solutions more reliably than methods that treat clusters in isolation. Future work includes extending this approach to a multilingual context and exploring its effectiveness on complex system-level tasks where output definitions are less straightforward.

Implementation available at: https://github.com/FSoft-AI4Code/SRank-CodeRanker

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