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

PSCS:一种基于路径的语义代码搜索神经模型

PSCS: A Path-based Neural Model for Semantic Code Search

Zhensu Sun, Yan Liu, Chen Yang, Yu Qian

摘要:

为了获得代码片段以供重用,程序员更喜欢搜索相关文档,例如,博客或问答,而不是代码本身。主要原因是由于查询和代码片段之间的语义多样性和不匹配。已经提出了深度学习模型来应对这一挑战。与使用信息检索技术的方法相比,深度学习模型不会因将用户意图细化为关键字而导致信息丢失。然而,以前的工作的性能并不令人满意,因为他们忽略了代码结构的重要性。当代码的语义(例如,标识符名称(API)是模糊的,代码结构可能是模型使用的唯一功能。在这种情况下,以前的作品重新学习的结构信息,从词汇标记的代码,这是非常困难的模型没有任何领域知识。在这项工作中,我们提出了PSCS,一个基于路径的神经模型的语义代码搜索。我们的模型编码的AST路径所代表的代码的语义和结构。我们训练和评估我们的模型超过330 k-19 k查询函数对,分别。评估结果表明,当考虑匹配的前10个结果时,PSCS实现了47.6%的成功率和30.4%的平均倒数排名(MRR)。所提出的方法显着优于DeepCS,第一种将深度学习应用于代码搜索任务的方法,以及CARLCS,一种最先进的方法,在DeepCS的基础上引入了共同关注的表示学习模型。通过对代码特征的消融研究,论证了代码结构的重要性,为进一步研究模型设计提供了启示。

英文摘要:

To obtain code snippets for reuse, programmers prefer to search for related documents, e.g., blogs or Q&A, instead of code itself. The major reason is due to the semantic diversity and mismatch between queries and code snippets. Deep learning models have been proposed to address this challenge. Compared with approaches using information retrieval techniques, deep learning models do not suffer from the information loss caused by refining user intention into keywords. However, the performance of previous works is not satisfactory because they ignore the importance of code structure. When the semantics of code (e.g., identifier names, APIs) are ambiguous, code structure may be the only feature for the model to utilize. In that case, previous works relearn the structural information from lexical tokens of code, which is extremely difficult for a model without any domain knowledge. In this work, we propose PSCS, a path-based neural model for semantic code search. Our model encodes both the semantics and structures of code represented by AST paths. We train and evaluate our model over 330k-19k query-function pairs, respectively. The evaluation results demonstrate that PSCS achieves a SuccessRate of 47.6% and a Mean Reciprocal Rank (MRR) of 30.4% when considering the top-10 results with a match. The proposed approach significantly outperforms both DeepCS, the first approach that applies deep learning to code search task, and CARLCS, a state-of-the-art approach that introduces a co-attentive representation learning model on the basis of DeepCS. The importance of code structure is demonstrated with an ablation study on code features, which enlightens model design for further studies.

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

↑