论文标题
CSSAM:代码搜索代码语义和结构的注意
CSSAM:Code Search via Attention Matching of Code Semantics and Structures
论文作者
论文摘要
尽管不断努力提高代码搜索的有效性和效率,但两个问题仍未解决。首先,编程语言具有固有的牢固结构链接,并且代码作为文本形式的特征挖掘将省略其中包含的结构信息。其次,代码和查询之间存在潜在的语义关系,跨序列对齐代码和文本是具有挑战性的,因此在相似性匹配期间,向量在空间上保持一致。为了解决这两个问题,在本文中,提出了一个名为CSSAM的代码搜索模型(代码语义和结构注意匹配)。通过引入语义和结构匹配机制,CSSAM有效提取并融合了多维代码功能。具体而言,开发了交叉和残留层,以促进代码和查询在令牌级别的高纬度空间比对。通过利用剩余相互作用,匹配模块旨在保留更多的代码语义和描述性特征,从而增强了代码及其相应查询文本之间的粘附。此外,为了提高模型对代码固有结构的理解,提出了一个名为CSRG的代码表示结构(代码语义表示图),用于共同表示抽象语法树节点和代码的数据流。根据两个包含540K和330K代码段的公开可用数据集的实验结果,CSSAM在两个数据集中分别在获得最高的SR@1/5/10,MRR和NDCG@50方面,大大优于基线。此外,进行消融研究是为了定量衡量CSSAM每个关键组成部分对代码搜索效率和有效性的影响,这为改进高级代码搜索解决方案提供了见解。
Despite the continuous efforts in improving both the effectiveness and efficiency of code search, two issues remained unsolved. First, programming languages have inherent strong structural linkages, and feature mining of code as text form would omit the structural information contained inside it. Second, there is a potential semantic relationship between code and query, it is challenging to align code and text across sequences so that vectors are spatially consistent during similarity matching. To tackle both issues, in this paper, a code search model named CSSAM (Code Semantics and Structures Attention Matching) is proposed. By introducing semantic and structural matching mechanisms, CSSAM effectively extracts and fuses multidimensional code features. Specifically, the cross and residual layer was developed to facilitate high-latitude spatial alignment of code and query at the token level. By leveraging the residual interaction, a matching module is designed to preserve more code semantics and descriptive features, that enhances the adhesion between the code and its corresponding query text. Besides, to improve the model's comprehension of the code's inherent structure, a code representation structure named CSRG (Code Semantic Representation Graph) is proposed for jointly representing abstract syntax tree nodes and the data flow of the codes. According to the experimental results on two publicly available datasets containing 540k and 330k code segments, CSSAM significantly outperforms the baselines in terms of achieving the highest SR@1/5/10, MRR, and NDCG@50 on both datasets respectively. Moreover, the ablation study is conducted to quantitatively measure the impact of each key component of CSSAM on the efficiency and effectiveness of code search, which offers the insights into the improvement of advanced code search solutions.