arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2410.16229cs.CL
收藏

基于检索增强语言模型构建代码助手

Building A Coding Assistant via the Retrieval-Augmented Language Model

Xinze Li, Hanbin Wang, Zhenghao Liu, Shi Yu, Shuo Wang, Yukun Yan, Yukai Fu, Yu Gu, Ge Yu

AI总结:

本研究提出代码助手CONAN,由结构感知检索器和双视图检索增强生成模型组成,通过代码-文档对齐等预训练任务提升代码表示能力,在代码生成任务上优于现有检索增强模型,还可辅助大语言模型提升代码任务效能。

摘要:

预训练语言模型在代码检索、代码生成、代码摘要和代码补全等代码相关任务中已展现出强大的效能。本文提出基于检索增强语言模型的代码助手CONAN(COde assistaNt viA retrieval-augmeNted language model),旨在通过模拟人类编码过程中的知识寻求行为来构建代码助手。具体而言,该模型由代码结构感知检索器CONAN-R和基于双视图代码表示的检索增强生成模型CONAN-G组成。CONAN-R通过代码-文档对齐任务和掩码实体预测任务对CodeT5进行预训练,使语言模型具备代码结构感知能力,并学习代码片段与文档的有效表示。随后CONAN-G设计了双视图代码表示机制,用于实现检索增强的代码生成模型,它将代码文档描述作为提示,帮助语言模型更好地理解代码语义。我们的实验表明,CONAN在不同代码生成任务上取得了令人信服的性能,且显著优于以往的检索增强代码生成模型。进一步分析显示,CONAN通过对齐代码-文档数据对,并在代码数据中通过掩码与预测实体来捕捉结构语义,从而为代码片段和文档学习到定制化的表示。此外,检索到的代码片段和文档从编程语言和自然语言两个维度提供了必要信息,以辅助代码生成过程。CONAN还可作为大语言模型(LLMs)的助手,以更短的代码文档长度为LLMs提供外部知识,提升其在各类代码任务上的效能,展现出CONAN提取必要信息并帮助过滤检索到的代码文档中噪声的能力。

英文摘要:

Pretrained language models have shown strong effectiveness in code-related tasks, such as code retrieval, code generation, code summarization, and code completion tasks. In this paper, we propose COde assistaNt viA retrieval-augmeNted language model (CONAN), which aims to build a code assistant by mimicking the knowledge-seeking behaviors of humans during coding. Specifically, it consists of a code structure aware retriever (CONAN-R) and a dual-view code representation-based retrieval-augmented generation model (CONAN-G). CONAN-R pretrains CodeT5 using Code-Documentation Alignment and Masked Entity Prediction tasks to make language models code structure-aware and learn effective representations for code snippets and documentation. Then CONAN-G designs a dual-view code representation mechanism for implementing a retrieval-augmented code generation model. CONAN-G regards the code documentation descriptions as prompts, which help language models better understand the code semantics. Our experiments show that CONAN achieves convincing performance on different code generation tasks and significantly outperforms previous retrieval augmented code generation models. Our further analyses show that CONAN learns tailored representations for both code snippets and documentation by aligning code-documentation data pairs and capturing structural semantics by masking and predicting entities in the code data. Additionally, the retrieved code snippets and documentation provide necessary information from both program language and natural language to assist the code generation process. CONAN can also be used as an assistant for Large Language Models (LLMs), providing LLMs with external knowledge in shorter code document lengths to improve their effectiveness on various code tasks. It shows the ability of CONAN to extract necessary information and help filter out the noise from retrieved code documents.

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

↑