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