[论文解读] FRANC: A Lightweight Framework for High-Quality Code Generation
FRANC 是一种轻量级、与模型无关的框架,通过静态过滤、质量感知排序和提示工程,提升基于大语言模型的代码生成质量。在 Java 中,其可编译性提升 9%–46%,在 Python 中提升 10%–43%;NDCG@10 提升 0.0763,且能修复 80% 的问题提示,延迟极低(0.08–1.98 秒)。
In recent years, the use of automated source code generation utilizing transformer-based generative models has expanded, and these models can generate functional code according to the requirements of the developers. However, recent research revealed that these automatically generated source codes can contain vulnerabilities and other quality issues. Despite researchers' and practitioners' attempts to enhance code generation models, retraining and fine-tuning large language models is time-consuming and resource-intensive. Thus, we describe FRANC, a lightweight framework for recommending more secure and high-quality source code derived from transformer-based code generation models. FRANC includes a static filter to make the generated code compilable with heuristics and a quality-aware ranker to sort the code snippets based on a quality score. Moreover, the framework uses prompt engineering to fix persistent quality issues. We evaluated the framework with five Python and Java code generation models and six prompt datasets, including a newly created one in this work (SOEval). The static filter improves 9% to 46% Java suggestions and 10% to 43% Python suggestions regarding compilability. The average improvement over the NDCG@10 score for the ranking system is 0.0763, and the repairing techniques repair the highest 80% of prompts. FRANC takes, on average, 1.98 seconds for Java; for Python, it takes 0.08 seconds.
研究动机与目标
- 解决大语言模型生成源代码中日益严重的安全漏洞和低质量代码问题。
- 通过引入轻量级后处理框架,减少对大型语言模型进行昂贵微调的需求。
- 使开发者无需重新训练模型,即可获得更高质量、可编译且安全的代码。
- 提供可配置、与模型无关的解决方案,集成静态过滤、质量评分和基于提示的修复功能。
- 在 Python 和 Java 的多种代码生成模型及真实世界提示上,验证框架的有效性。
提出的方法
- 应用静态过滤器,利用启发式方法移除或修复不可编译的代码,提升语法正确性。
- 集成现成的静态分析工具(如 Pmd、Checkstyle、Spotbugs),检测代码异味和漏洞,用于质量评分。
- 实现质量感知排序器,基于多工具聚合的质量指标对代码片段进行评分和排序。
- 利用大语言模型驱动的提示工程,为低质量代码生成修复建议,重点关注持续性问题。
- 设计模块化、与模型无关的处理流程,通过过滤、排序和修复阶段处理提示,无需模型微调。
- 利用从 Stack Overflow 衍生的新 70 个提示数据集,评估框架在真实场景下的适用性和鲁棒性。
实验结果
研究问题
- RQ1在不进行模型微调的情况下,轻量级框架在多大程度上能提升大语言模型生成代码的可编译性?
- RQ2质量感知排序系统在跨多种模型和提示时,识别最高质量代码片段的有效性如何?
- RQ3提示工程技术能否自动修复生成代码中的持续性质量问题?
- RQ4FRANC 在不同编程语言(Python 和 Java)及不同代码生成模型上的表现如何?
- RQ5在实时代码生成工作流中,FRANC 的运行时开销是多少?
主要发现
- 静态过滤器在多个模型上使 Java 代码的可编译性提升 9%–46%,Python 代码提升 10%–43%。
- 质量感知排序器在 NDCG@10 上实现了平均 0.0763 的提升,表明与人工评估的相关性更强。
- 提示工程技术成功修复了最高 80% 的问题提示,证明其在修复重复性质量问题方面的有效性。
- FRANC 延迟极低,平均处理 Python 代码耗时 0.08 秒,Java 代码耗时 1.98 秒,适合实时应用。
- 该框架在五种代码生成模型(CodeParrot、InCoder、CodeGen、PolyCoder、GPT-3.5-turbo)及多样化提示集上表现出强大的泛化能力。
- 复现包(含新 FRANC 提示数据集)已公开发布于 https://github.com/s2e-lab/FRANC,便于复现与扩展。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。