paperbot · PL 论文追踪

全部论文 待读 收藏

P2 CodeGen4Libs: A Two-Stage Approach for Library-Oriented Code Generation

CodeGen4Libs:一种面向库的代码生成两阶段方法
ASE 2023 38th IEEE/ACM International Conference on Automated Software Engineering (ASE)2023匹配度 2/10 · 该论文研究基于机器学习的库导向代码生成(先生成 import 再生成代码),属于代码生成方向,而非用户核心关注的静态分析、形式化验证、浮点程序分析或贝叶斯程序分析;也未涉及 LLM/Agent 对分析工具的改进或对 Agentic 程序的分析。引用 61 inbox
Mingwei Liu, Tianyong Yang, Yiling Lou, Xueying Du, Ying Wang, Xin Peng
crossref: 2026-09-12dblp: 2026-09-12

AI 速览

一句话:提出两阶段库导向代码生成方法 CodeGen4Libs,先生成 import 再生成代码,显著优于基线。

该文关注库导向代码生成这一更贴近实践的场景:生成的代码需在给定第三方库下实现自然语言查询的功能。作者先通过 66 名参与者的调研说明该场景的重要性,并重新审视现有基于学习的代码生成技术,发现其在此场景下效果有限。为此提出 CodeGen4Libs,将任务拆为两阶段:import 生成阶段根据查询与给定库生成导入语句,代码生成阶段再基于生成的 import 与查询生成具体代码。作者在包含 403,780 条数据项的数据集上开展实验,结果表明 CodeGen4Libs 在 import 生成和代码生成两个阶段均优于基线,EM 最高提升 97.4%,BLEU 提升 54.5%,Hit@All 提升 53.5%。

问题
现有基于学习的代码生成方法在“库导向代码生成”场景中效果有限,即难以根据自然语言查询和指定第三方库生成能正确使用该库的代码。
方法
提出 CodeGen4Libs 两阶段方法:先为自然语言查询和给定第三方库生成 import 语句,再基于生成的 import 与查询生成具体代码。
评估
在 403,780 条数据项的数据集上进行实验,比较 import 生成与代码生成两阶段相对基线的表现,并报告 EM、BLEU、Hit@All 等指标提升。
原文摘要(Abstract)

Automated code generation has been extensively studied in recent literature. In this work, we first survey 66 participants to motivate a more pragmatic code generation scenario, i.e., library-oriented code generation, where the generated code should implement the functionally of the natural language query with the given library. We then revisit existing learning-based code generation techniques and find they have limited effectiveness in such a library-oriented code generation scenario. To address this limitation, we propose a novel library-oriented code generation technique, CodeGen4Libs, which incorporates two stages: import generation and code generation. The import generation stage generates import statements for the natural language query with the given third-party libraries, while the code generation stage generates concrete code based on the generated imports and the query. To evaluate the effectiveness of our approach, we conduct extensive experiments on a dataset of 403,780 data items. Our results demonstrate that CodeGen4Libs outperforms baseline models in both import generation and code generation stages, achieving improvements of up to 97.4% on EM (Exact Match), 54.5% on BLEU, and 53.5% on Hit@All. Overall, our proposed CodeGen4Libs approach shows promising results in generating high-quality code with specific third-party libraries, which can improve the efficiency and effectiveness of software development.

链接与引用

DOI 原文 · DBLP

BibTeX
@inproceedings{LiuYLDWP23,
  title = {CodeGen4Libs: A Two-Stage Approach for Library-Oriented Code Generation},
  author = {Mingwei Liu and Tianyong Yang and Yiling Lou and Xueying Du and Ying Wang and Xin Peng},
  booktitle = {ASE},
  year = {2023},
  doi = {10.1109/ase56229.2023.00159}
}