让大模型按软件开发流程分步写代码,正确率提升75%。
Lifecycle-Aware code generation: Leveraging Software Engineering Phases in LLMs
- 分阶段引入需求分析、状态机等中间产物,引导模型逐步生成代码。
- 相比单步生成,多步推理正确率显著提升,最高增益达75%。
- 开源模型经训练后超越部分预训练代码模型,适合工程化落地。
大语言模型在自动代码生成方面取得进展,但多数方法直接从问题描述生成代码,忽略结构化软件工程流程。本文提出一种生命周期感知框架,在训练和推理阶段系统性引入需求分析、状态机建模、伪代码等中间产物,使代码生成更贴近标准开发流程,实现更结构化的推理。实验表明,生命周期级微调使代码正确率相比原模型最高提升75%,且各阶段性能增益可累积。多步推理始终优于单步生成,验证了中间引导的有效性。值得注意的是,经本框架微调的开源模型(如DeepSeek-Coder-1.3B)在代码生成上达到或略超预训练于代码的数据集的模型:相对于ChatGPT-3.5、ChatGPT-4o-mini、DeepSeek-R1和LLaMA-8B,其CodeBLEU分别提升34.3%、20.0%、11.2%和22.3%。该方法在仅使用80%以下训练数据时仍保持稳健,消融实验进一步表明每个中间产物对最终代码质量均有独立贡献,其中状态机建模影响最大。源码与详细实验数据已公开于https://anonymous.4open.science/r/Lifecycle-Aware-3CCB。
原文摘要 · Abstract (English)
Recent progress in large language models (LLMs) has advanced automatic code generation, yet most approaches rely on direct, single-step translation from problem descriptions to code, disregarding structured software engineering practices. We introduce a lifecycle-aware framework that systematically incorporates intermediate artifacts such as requirements analysis, state machine modeling, and pseudocode into both the training and inference stages. This design aligns code generation with standard software development phases and enables more structured reasoning. Experiments show that lifecycle-level fine-tuning improves code correctness by up to 75% over the same model before fine-tuning, with performance gains compounding across intermediate stages. Multi-step inference consistently surpasses single-step generation, demonstrating the effectiveness of intermediate scaffolding. Notably, open-source LLMs, once fine-tuned under our framework, match or slightly outperform models pretrained on code. When applied to DeepSeek-Coder-1.3B, our framework yields relative CodeBLEU improvements of 34.3%, 20.0%, 11.2%, and 22.3% over ChatGPT-3.5, ChatGPT-4o-mini, DeepSeek-R1, and LLaMA-8B, respectively. Our pipeline also proves robust with up to 80\% less training data, confirming its resilience. Ablation studies further reveal that each intermediate artifact contributes distinctly to final code quality, with state machine modeling yielding the most substantial impact. Our source code and detailed experimental data are available at https://anonymous.4open.science/r/Lifecycle-Aware-3CCB.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。