Enhancing LLM-Based Code Generation with Complexity Metrics: A Feedback-Driven Approach
Sepidband, Melika, Taherkhani, Hamed, Wang, Song, Hemmati, Hadi
–arXiv.org Artificial Intelligence
--Automatic code generation has gained significant momentum with the advent of Large Language Models (LLMs) such as GPT -4. Although many studies focus on improving the effectiveness of LLMs for code generation, very limited work tries to understand the generated code's characteristics and leverage that to improve failed cases. In this paper, as the most straightforward characteristic of code, we investigate the relationship between code complexity and the success of LLMgenerated code. Using a large set of standard complexity metrics, we first conduct an empirical analysis to explore their correlation with LLM's performance on code generation (i.e., Pass@1). Using logistic regression models, we identify which complexity metrics are most predictive of code correctness. Building on these findings, we propose an iterative feedback method, where LLMs are prompted to generate correct code based on complexity metrics from previous failed outputs. Experiment results show that our approach makes notable improvements, particularly with a smaller LLM (GPT - 3.5 T urbo), where, e.g., Pass@1 increased by 35.71% compared to the baseline's improvement of 12.5% on the HumanEval dataset. The study expands experiments to BigCodeBench and integrates the method with the Reflexion code generation agent, leading to Pass@1 improvements of 20% (GPT -4o) and 23.07% The results highlight that complexity-aware feedback enhances both direct LLM prompting and agent-based workflows. Automatic code generation aims to reduce manual coding and boost productivity [1], with LLMs like GPT -4 [2] making significant advancements. However, ensuring accuracy and correctness remains a challenge. Recently, several approaches have been proposed to enhance LLM-based code generation.
arXiv.org Artificial Intelligence
Jun-2-2025
- Country:
- North America > Canada
- Oceania > New Zealand
- North Island > Waikato (0.04)
- Genre:
- Research Report > New Finding (1.00)
- Technology: