一句话:提出面向LLM代码生成的集成方法,通过语法与语义相似度及行为等价性投票,从多模型候选中选出最可靠程序。
集成学习在机器学习中已被广泛用于提升鲁棒性与泛化能力,但尚未应用于大语言模型的代码生成任务。本文提出一种针对LLM代码生成的集成方法:不再依赖单一模型的输出,而是从不同LLM生成多个候选程序,再通过结构化投票机制选出最可靠的解。投票时,利用CodeBLEU计算候选间的语法与语义相似度,并借助CrossHair的差分行为分析判定行为等价性,最后聚合这些相似度分数,选择与候选共识最一致的方案。在HumanEval和更具挑战性的LiveCodeBench数据集上,该方法分别达到90.2%和50.2%的准确率,优于表现最好的单模型GPT-4o(83.5%和43.4%)。即使仅使用免费开源模型,也能取得80.5%和41.6%的准确率,说明该方法在资源受限场景下同样可行。
Ensemble learning has been widely used in machine learning to improve model robustness, accuracy, and generalization, but has not yet been applied to code generation tasks with large language models (LLMs). In this paper, we propose an ensemble approach for LLMs in code generation. Instead of relying on the output of a single model, we generate multiple candidate programs from different LLMs and apply a structured voting mechanism to select the most reliable solution. For voting, we compute syntactic and semantic similarity using CodeBLEU and behavioral equivalence using CrossHair’s differential behavior analysis. By aggregating these similarity scores, we select the program that best aligns with the consensus among the candidates. Our experiments show that our ensemble approach consistently outperforms standalone LLMs on the well-known HumanEval and the more challenging LiveCodeBench datasets, achieving an accuracy of 90.2% and 50.2%, respectively, on the two datasets. In comparison, the best-performing LLM (GPT-4o) has an accuracy of 83.5% and 43.4%, respectively. Furthermore, even when restricted to free open source models, our method achieves an accuracy of 80.5% and 41.6%, respectively, demonstrating the viability of our approach in resource-constrained settings.
@inproceedings{abs-2503-15838,
title = {Enhancing LLM Code Generation with Ensembles: A Similarity-Based Selection Approach},
author = {Tarek Mahmud and Bin Duan and Corina Păsăreanu and Guowei Yang},
booktitle = {ICSE},
year = {2026},
doi = {10.1145/3744916.3773143}
}