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

CSRS:基于相关匹配和语义匹配的代码搜索

CSRS: Code Search with Relevance Matching and Semantic Matching

Yi Cheng, Li Kuang

摘要:

在软件开发过程中,开发人员经常搜索和重用现有的代码片段。代码搜索旨在根据开发人员输入的自然语言查询从代码库中检索相关代码段。到目前为止,研究人员已经提出了基于信息检索(IR)的方法和基于深度学习(DL)的方法。基于IR的方法专注于关键字匹配,即通过查询和代码片段之间的相关性对代码进行排名,而基于DL的方法专注于捕获语义相关性。然而,现有的方法没有考虑同时捕获两个匹配信号。因此,在本文中,我们提出了CSRS,一个代码搜索模型的相关性匹配和语义匹配。CSRS包括(1)包含不同大小的卷积核的嵌入模块,其可以提取查询和代码的n-gram嵌入,(2)测量词汇匹配信号的相关性匹配模块,以及(3)捕获语义相关性的基于共同注意的语义匹配模块。我们训练和评估CSRS的数据集与18.22米和10 k代码片段。实验结果表明,CSRS实现了0.614的MRR,比两个最先进的模型DeepCS和CARLCS-CNN分别高出33.77%和18.53%。此外,我们还进行了几个实验,以证明CSRS的每个组成部分的有效性。

英文摘要:

Developers often search and reuse existing code snippets in the process of software development. Code search aims to retrieve relevant code snippets from a codebase according to natural language queries entered by the developer. Up to now, researchers have already proposed information retrieval (IR) based methods and deep learning (DL) based methods. The IR-based methods focus on keyword matching, that is to rank codes by relevance between queries and code snippets, while DL-based methods focus on capturing the semantic correlations. However, the existing methods do not consider capturing two matching signals simultaneously. Therefore, in this paper, we propose CSRS, a code search model with relevance matching and semantic matching. CSRS comprises (1) an embedding module containing convolution kernels of different sizes which can extract n-gram embeddings of queries and codes, (2) a relevance matching module that measures lexical matching signals, and (3) a co-attention based semantic matching module to capture the semantic correlation. We train and evaluate CSRS on a dataset with 18.22M and 10k code snippets. The experimental results demonstrate that CSRS achieves an MRR of 0.614, which outperforms two state-of-the-art models DeepCS and CARLCS-CNN by 33.77% and 18.53% respectively. In addition, we also conducted several experiments to prove the effectiveness of each component of CSRS.

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

↑