arXivDaily arXiv每日学术速递 周一至周五更新
北美退伍军人节(Veterans Day),12 日无更新
arXiv 2408.09345cs.IRcs.SE
收藏

基于命名无关对比多视图学习的深度代码搜索

Deep Code Search with Naming-Agnostic Contrastive Multi-View Learning

Jiadong Feng, Wei Li, Suhuang Wu, Zhao Wei, Yong Xu, Juhong Wang, Hui Li

AI总结:

针对不同命名规范影响深度代码搜索的问题,提出命名无关的代码搜索方法NACS,通过对比多视图学习剥离变量名信息并捕获AST结构固有属性,显著提升了搜索性能并可适配增强现有方法。

摘要:

软件开发是一项重复性任务,因为开发者通常会复用现有实现或从中获取灵感。代码搜索是指在软件开发过程中,根据开发者表达为查询的意图,从代码库中检索相关代码片段,其重要性日益凸显。由于深度学习在各类应用中取得成功,大量基于深度学习的代码搜索方法涌现并取得了可喜的成果。然而,开发者可能不遵循相同的命名规范,同一变量在不同实现中可能具有不同的变量名,这给依赖显式变量对应关系来理解源代码的基于深度学习的代码搜索方法带来了挑战。为克服这一挑战,我们提出了一种基于对比多视图代码表示学习的命名无关代码搜索方法(NACS)。NACS从抽象语法树(AST,源代码抽象语法结构的表示)中剥离与变量名绑定的信息,专注于仅从AST结构中捕获固有属性。我们使用语义级和语法级增强技术来准备现实合理的数据,并在NACS中采用对比学习设计图视图建模组件,以增强对代码片段的理解。我们进一步在路径视图中对AST进行建模,通过多视图学习来强化图视图建模组件。大量实验表明,与基线相比,NACS提供了更优的代码搜索性能,并且NACS能够适应并帮助现有代码搜索方法克服不同命名规范的影响。我们的实现可在https://github.com/KDEGroup/NACS获取。

英文摘要:

Software development is a repetitive task, as developers usually reuse or get inspiration from existing implementations. Code search, which refers to the retrieval of relevant code snippets from a codebase according to the developer's intent that has been expressed as a query, has become increasingly important in the software development process. Due to the success of deep learning in various applications, a great number of deep learning based code search approaches have sprung up and achieved promising results. However, developers may not follow the same naming conventions and the same variable may have different variable names in different implementations, bringing a challenge to deep learning based code search methods that rely on explicit variable correspondences to understand source code. To overcome this challenge, we propose a naming-agnostic code search method (NACS) based on contrastive multi-view code representation learning. NACS strips information bound to variable names from Abstract Syntax Tree (AST), the representation of the abstract syntactic structure of source code, and focuses on capturing intrinsic properties solely from AST structures. We use semantic-level and syntax-level augmentation techniques to prepare realistically rational data and adopt contrastive learning to design a graph-view modeling component in NACS to enhance the understanding of code snippets. We further model ASTs in a path view to strengthen the graph-view modeling component through multi-view learning. Extensive experiments show that NACS provides superior code search performance compared to baselines and NACS can be adapted to help existing code search methods overcome the impact of different naming conventions. Our implementation is available at https://github.com/KDEGroup/NACS.

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

↑