arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2405.02355cs.SEcs.AI
收藏

CodeGRAG:通过图检索增强生成弥合自然语言与编程语言之间的鸿沟

CodeGRAG: Bridging the Gap between Natural Language and Programming Language via Graphical Retrieval Augmented Generation

Shanghai Jiao Tong University(上海交通大学);Huawei Noah’s Ark Lab Shanghai(华为诺亚实验室)

Kounianhua Du, Jizheng Chen, Renting Rui, Huacan Chai, Lingyue Fu, Wei Xia, Yasheng Wang, Ruiming Tang, Yong Yu, Weinan Zhang

AI总结:

针对自然语言与编程语言间的句法鸿沟等问题,提出图检索增强代码生成框架CodeGRAG,通过构建代码图视图、软硬提示技术提升大语言模型代码生成及跨语言代码生成性能。

摘要:

利用大语言模型生成代码在软件开发变革中展现出可观的价值。尽管大语言模型已展现出智能性,但由于自然语言与编程语言之间存在句法鸿沟和词汇不匹配问题,其在代码生成方面的特异性仍有待提升。本文提出CodeGRAG,一种图检索增强代码生成框架,用于弥合自然语言(NL)与编程语言(PL)之间的鸿沟,以提升大语言模型(LLMs)的性能。CodeGRAG基于代码块的控制流和数据流构建代码块的图视图,以更好地解读编程领域知识,这能够帮助基于自然语言的大语言模型更好地理解代码句法,并充当不同编程语言之间的桥梁。为将提取到的结构化知识融入基础模型,我们提出:1)硬元图提示模板,将具有挑战性的句法图转化为信息丰富的图视图,适用于无需微调的模型;2)软提示技术,通过使用由GNN(图神经网络)专家模型编码的软信号对模型进行微调,将编程语言的领域知识注入模型参数。具体而言,我们设计了两种约束条件以提升对齐效果和结构表达能力,从而提高单令牌大小的外部<GraphEmb>的信息含量,以增强代码生成效果。CodeGRAG显著提升了大语言模型的代码生成能力,甚至能为跨语言代码生成带来性能提升。实现代码可在https://anonymous.4open.science/r/Code-5970/ 获取。

英文摘要:

Utilizing large language models to generate codes has shown promising meaning in software development revolution. Despite the intelligence shown by the large language models, their specificity in code generation can still be improved due to the syntactic gap and mismatched vocabulary existing between natural language and programming languages. In this paper, we propose CodeGRAG, a Graphical Retrieval Augmented Code Generation framework that bridges the gap between NL and PL to enhance the performance of LLMs. CodeGRAG builds the graphical view of code blocks based on the control flow and data flow of them to better interpret the programming domain knowledge, which can facilitate natural language based LLMs for better understanding of code syntax and serve as a bridge among different programming languages. To take the extracted structural knowledge into the foundation models, we propose 1) a hard meta-graph prompt template to transform the challenging syntax graph into informative graphical view for tuning-free models and 2) a soft prompting technique that injects the domain knowledge of programming languages into model parameters via finetuning the models with the soft signals encoded by GNN expert model. Specifically, two constraints are designed to improve the alignment and structure expressiveness, contributing to the informativeness of the single-token-sized external <GraphEmb> for enhanced code generation. CodeGRAG significantly improves the code generation ability of LLMs and can even offer performance gain for cross-lingual code generation. Implementation is available at https://anonymous.4open.science/r/Code-5970/ .

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

↑