预训练语言模型在代码检索、代码生成、代码摘要和代码补全等代码相关任务中已展现出强大的效能。本文提出基于检索增强语言模型的代码助手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-Augmented Predictions: LLM Assistants Improve Human Forecasting Accuracy
London School of Economics and Political Science(伦敦政治经济学院);Massachusetts Institute of Technology(麻省理工学院);Federal Reserve Bank of Chicago(芝加哥联邦储备银行);University of California San Diego(加利福尼亚大学圣迭戈分校);University of Pennsylvania(宾夕法尼亚大学)
Domain-Specific Improvement on Psychotherapy Chatbot Using Assistant
Czech Technical University in Prague(布拉格捷克技术大学);National Institute of Mental Health in Prague(布拉格国家精神卫生研究所);The University of Hong Kong(香港大学);Shenzhen Mental Health Centre(深圳市精神卫生中心)
Large Language Models Are Effective Human Annotation Assistants, But Not Good Independent Annotators
Department of Computer Science, University of Maryland(大学计算机科学系);National Consortium for the Study of Terrorism and Responses to Terrorism(反恐与反恐响应国家研究中心)
TAMA: Tool-Augmented Multimodal Agent for Procedural Activity Understanding
Language Technologies Institute, Carnegie Mellon University(卡内基梅隆大学语言技术研究所);National Institute of Advanced Industrial Science and Technology (AIST)(国家先进工业科学与技术研究院)
SpectraQuery: A Hybrid Retrieval-Augmented Conversational Assistant for Battery Science
Mechanical Engineering, Stanford University(斯坦福大学机械工程系);Applied Energy Division, SLAC National Accelerator Laboratory(SLAC国家加速器实验室应用能源部门);Institute of Computational and Mathematical Engineering, Stanford University(斯坦福大学计算与数学工程研究所)