用对抗游戏生成代码语义差异数据,提升大模型编程理解能力
Program Semantic Inequivalence Game with Large Language Models
- 构建生成与评估双代理对抗机制,自动合成语义差异代码对
- 在跨语言漏洞检测中,仅用Python训练即提升C/C++漏洞识别率
- 显著改善复杂语义任务表现,适合需增强代码逻辑推理的开发者
大型语言模型在日常编码任务中表现良好,但在需要深入程序语义推理的复杂任务上仍会失败。本文提出一种基于语义不等价博弈(SInQ)的合成数据生成方法:生成代理从真实编程任务中衍生出语义不同的代码变体,评估代理则识别二者行为差异的输入样本。两者半对抗式训练,共同提升对代码底层逻辑的理解。我们在多个代码生成与理解基准上进行评估,包括跨语言漏洞检测(Lu et al., 2021),结果显示即使仅在Python数据上训练,该方法仍显著提升C/C++代码的漏洞检测性能;在更具挑战性的Python内置标识符替换基准(Miceli Barone et al., 2023)上,现代LLM仍存在困难,而本方法取得明显改进。我们公开实验代码及生成的合成数据,可用于微调大模型。
原文摘要 · Abstract (English)
Large Language Models (LLMs) can achieve strong performance on everyday coding tasks, but they can fail on complex tasks that require non-trivial reasoning about program semantics. Finding training examples to teach LLMs to solve these tasks can be challenging. In this work, we explore a method to synthetically generate code reasoning training data based on a semantic inequivalence game (SInQ): a generator agent creates program variants that are semantically distinct, derived from a dataset of real-world programming tasks, while an evaluator agent has to identify input examples for which they behave differently. The agents train each other semi-adversarially, improving their ability to understand the underlying logic of code. We evaluated our approach on multiple code generation and understanding benchmarks, including cross-language vulnerability detection (Lu et al., 2021),, where our method improves vulnerability detection in C/C++ code despite being trained exclusively on Python code, and the challenging Python builtin identifier swap benchmark (Miceli Barone et al., 2023),, showing that whereas modern LLMs still struggle with this benchmark, our approach yields substantial improvements. We release the code needed to replicate the experiments, as well as the generated synthetic data, which can be used to fine-tune LLMs.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。