CSSAM:通过代码语义和结构的注意力匹配进行代码搜索
CSSAM:Code Search via Attention Matching of Code Semantics and Structures
摘要:
尽管我们不断努力改善代码检索的成效和效率,但有两个问题仍未解决。首先,程序设计语言具有固有的强结构联系,将代码作为文本形式进行特征挖掘会忽略其中包含的结构信息;其次,代码和查询之间存在潜在的语义关系,在相似性匹配过程中,将代码和文本跨序列对齐以使向量在空间上一致是一个挑战。为了解决这两个问题,本文提出了一个代码搜索模型CSSAM(代码语义和结构注意力匹配)。通过引入语义和结构匹配机制,CSSAM有效地提取和融合多维代码特征。具体来说,交叉和剩余层的开发是为了促进代码和查询在令牌级别的高纬度空间对齐。通过利用剩余的交互,匹配模块的设计,以保持更多的代码语义和描述性的功能,提高代码和其对应的查询文本之间的粘附。此外,为了提高模型对代码内在结构的理解能力,提出了一种代码语义表示图CSRG(Code Semantic Representation Graph)结构,用于联合表示抽象语法树节点和代码的数据流。根据在两个公开的包含540 k和330 k代码段的数据集上的实验结果,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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。