arXiv:2410.16229cs.CL2024-10被引 17

用检索增强模型打造会查代码的编程助手,提升生成质量

Building A Coding Assistant via the Retrieval-Augmented Language Model

  • 用代码-文档对齐和实体预测预训练,让模型理解代码结构
  • 双视图表示机制使生成时能有效利用检索到的代码与文档
  • 可作为大模型的外部知识源,过滤噪声并提升编码效率

预训练语言模型在代码检索、生成、摘要和补全等任务中表现优异。本文提出CONAN——一种通过模仿人类编程时的知识搜索行为来构建代码助手的方法。它包含一个代码结构感知检索器(CONAN-R)和基于双视图代码表示的检索增强生成模型(CONAN-G)。CONAN-R 使用 Code-Documentation Alignment 和 Masked Entity Prediction 任务预训练 CodeT5,使模型具备代码结构感知能力,并学习有效的代码片段与文档表示。CONAN-G 设计双视图代码表示机制,将代码文档描述作为提示,帮助模型更好理解代码语义。实验表明,CONAN 在多种代码生成任务中表现优异,显著优于现有检索增强模型。分析显示,其通过代码-文档配对对齐和代码中实体掩码预测,学习到定制化表示;检索到的代码与文档为生成过程提供程序语言与自然语言双重信息支持。此外,CONAN 可作为大语言模型的外部知识辅助工具,在较短文档长度下提供有效信息,提升其在各类代码任务中的表现,展现出良好的信息提取与噪声过滤能力。

原文摘要 · Abstract (English)

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.

代码生成检索增强大模型辅助CodeT5

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。