arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2310.10698cs.CL
收藏

桥接代码语义与LLMs:用于代码生成的语义思维链提示

Bridging Code Semantic and LLMs: Semantic Chain-of-Thought Prompting for Code Generation

Yingwei Ma, Yue Yu, Shanshan Li, Yu Jiang, Yong Guo, Yuanliang Zhang, Yutao Xie, Xiangke Liao

AI总结:

本文提出SeCoT方法,通过引导LLMs生成并整合代码语义信息(如数据流和控制流),在三个基准上显著提升了代码生成的准确性和性能。

摘要:

大型语言模型(LLMs)在代码生成方面展示了卓越的能力。然而,自动化代码生成仍然具有挑战性,因为它需要在自然语言需求和代码之间进行高级语义映射。大多数现有的基于LLMs的代码生成方法依赖于仅解码器的因果语言模型,通常将代码仅视为纯文本标记,即将需求作为提示输入,并将代码输出为扁平的标记序列,这可能遗漏源代码中固有的丰富语义特征。为了弥合这一差距,本文提出了“语义思维链”方法来引入代码的语义信息,命名为SeCoT。我们的动机是源代码的语义信息(例如数据流和控制流)描述了更精确的程序执行行为、意图和功能。通过引导LLM考虑并整合语义信息,我们可以实现对代码更细粒度的理解和表示,从而提高代码生成的准确性。同时,虽然利用此类语义信息的传统技术需要复杂的静态或动态代码分析来获取数据流和控制流等特征,但SeCoT证明了这一过程可以通过LLMs的内在能力(即上下文学习)完全自动化,同时具有泛化性并适用于具有挑战性的领域。虽然SeCoT可以与不同的LLMs一起应用,但本文重点关注强大的GPT风格模型:ChatGPT(闭源模型)和WizardCoder(开源模型)。在三个流行的深度学习基准(即HumanEval、HumanEval-ET和MBPP)上的实验研究表明,SeCoT能够实现最先进的性能,极大地提升了大型模型和代码生成的潜力。

英文摘要:

Large language models (LLMs) have showcased remarkable prowess in code generation. However, automated code generation is still challenging since it requires a high-level semantic mapping between natural language requirements and codes. Most existing LLMs-based approaches for code generation rely on decoder-only causal language models often treate codes merely as plain text tokens, i.e., feeding the requirements as a prompt input, and outputing code as flat sequence of tokens, potentially missing the rich semantic features inherent in source code. To bridge this gap, this paper proposes the "Semantic Chain-of-Thought" approach to intruduce semantic information of code, named SeCoT. Our motivation is that the semantic information of the source code (\eg data flow and control flow) describes more precise program execution behavior, intention and function. By guiding LLM consider and integrate semantic information, we can achieve a more granular understanding and representation of code, enhancing code generation accuracy. Meanwhile, while traditional techniques leveraging such semantic information require complex static or dynamic code analysis to obtain features such as data flow and control flow, SeCoT demonstrates that this process can be fully automated via the intrinsic capabilities of LLMs (i.e., in-context learning), while being generalizable and applicable to challenging domains. While SeCoT can be applied with different LLMs, this paper focuses on the powerful GPT-style models: ChatGPT(close-source model) and WizardCoder(open-source model). The experimental study on three popular DL benchmarks (i.e., HumanEval, HumanEval-ET and MBPP) shows that SeCoT can achieves state-of-the-art performance, greatly improving the potential for large models and code generation.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑