Enhancing LLM Code Generation with Ensembles: A Similarity-Based Selection Approach

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Mahmud, Tarek, Duan, Bin, Pasareanu, Corina, Yang, Guowei
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866912492090818560
author Mahmud, Tarek
Duan, Bin
Pasareanu, Corina
Yang, Guowei
author_facet Mahmud, Tarek
Duan, Bin
Pasareanu, Corina
Yang, Guowei
contents 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). 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. We show through experiments 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.
format Preprint
id arxiv_https___arxiv_org_abs_2503_15838
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Enhancing LLM Code Generation with Ensembles: A Similarity-Based Selection Approach
Mahmud, Tarek
Duan, Bin
Pasareanu, Corina
Yang, Guowei
Software Engineering
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). 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. We show through experiments 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.
title Enhancing LLM Code Generation with Ensembles: A Similarity-Based Selection Approach
topic Software Engineering
url https://arxiv.org/abs/2503.15838