paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Two Birds with One Stone: Boosting Code Generation and Code Search via a Generative Adversarial Network

一石二鸟:通过生成对抗网络提升代码生成与代码搜索
OOPSLA 7(OOPSLA2)2023匹配度 2/10 · 该论文研究代码生成与代码搜索的对抗训练,属于机器学习与程序语言交叉,但与用户关注的静态分析、Agentic程序、浮点/贝叶斯程序分析以及用LLM改进验证等方向均无直接关联。引用 21 inbox
Shangwen Wang, Bo Lin, Zhensu Sun, Ming Wen, Yepang Liu, Yan Lei, Xiaoguang Mao
crossref: 2026-09-10

AI 速览

一句话:用GAN将代码生成与代码搜索互为生成器与判别器,通过对抗训练实现相互提升。

从自然语言描述自动生成代码是软件工程的长期目标,现有代码生成与代码搜索方法效果有限。本文洞察二者可互补:生成器需要生成代码的质量反馈,可由搜索器提供;搜索器需要更多训练数据,可由生成器扩充。为此提出基于生成对抗网络(GAN)的方法,将代码生成作为生成器、代码搜索作为判别器,并进行定制化设计,通过对抗训练实现相互提升。在八种设置下评估,两者性能均持续显著提升。例如以NatGen为生成器、GraphCodeBERT为判别器,在大规模Python数据集上,代码生成CodeBLEU提升32%,代码搜索MRR提升12%。

问题
现有代码生成与代码搜索技术效果有限,如何进一步提升二者性能是软件工程中的关键问题。
方法
提出基于GAN的统一框架,将代码生成与代码搜索分别作为生成器和判别器,通过对抗训练让二者相互促进,并针对任务进行定制化设计。
评估
在八种设置下进行评估,使用CodeBLEU和MRR等指标,与NatGen、GraphCodeBERT等基线对比,验证了方法对代码生成与代码搜索均有显著提升。
原文摘要(Abstract)

Automatically transforming developers' natural language descriptions into source code has been a longstanding goal in software engineering research. Two types of approaches have been proposed in the literature to achieve this: code generation, which involves generating a new code snippet, and code search, which involves reusing existing code. However, despite existing efforts, the effectiveness of the state-of-the-art techniques remains limited. To seek for further advancement, our insight is that code generation and code search can help overcome the limitation of each other: the code generator can benefit from feedback on the quality of its generated code, which can be provided by the code searcher, while the code searcher can benefit from the additional training data augmented by the code generator to better understand code semantics. Drawing on this insight, we propose a novel approach that combines code generation and code search techniques using a generative adversarial network (GAN), enabling mutual improvement through the adversarial training. Specifically, we treat code generation and code search as the generator and discriminator in the GAN framework, respectively, and incorporate several customized designs for our tasks. We evaluate our approach in eight different settings, and consistently observe significant performance improvements for both code generation and code search. For instance, when using NatGen, a state-of-the-art code generator, as the generator and GraphCodeBERT, a state-of-the-art code searcher, as the discriminator, we achieve a 32% increase in CodeBLEU score for code generation, and a 12% increase in mean reciprocal rank for code search on a large-scale Python dataset, compared to their original performances.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@article{paperbot1851,
  title = {Two Birds with One Stone: Boosting Code Generation and Code Search via a Generative Adversarial Network},
  author = {Shangwen Wang and Bo Lin and Zhensu Sun and Ming Wen and Yepang Liu and Yan Lei and Xiaoguang Mao},
  journal = {Proceedings of the ACM on Programming Languages},
  volume = {7},
  number = {OOPSLA2},
  year = {2023},
  doi = {10.1145/3622815}
}