1.Key Laboratory of Aerospace Information Security and Trusted Computing,Ministry of Education,School of Cyber Science and Engineering,Wuhan University,Wuhan 430072,Hubei,China
2.School of Business Administration,Hunan University,Changsha 410082,Hunan,China
Show less
文章历史+
Received
Published
2022-12-10
2023-12-24
Issue Date
2026-07-23
PDF (2487K)
摘要
在代码搜索任务中,已有的基于深度学习的算法,一方面不能有效提取代码特征和查询特征之间的细粒度交互关系,另一方面未考虑特征之间潜在的结构化特征,无法实现更精确的匹配。本文提出了一种基于交互和图注意力网络的代码搜索模型IGANCS(Interaction and Graph Attention Network based model for Code Search)。该模型通过引入基于相似度矩阵的交互机制,学习代码特征和查询特征的细粒度交互关系,实现代码与查询之间的对齐;引入图注意力机制,利用自注意力层学习代码和查询中隐藏的结构化特征,更深入地挖掘代码和查询的结构化语义;利用最大池化机制分别聚合代码特征和查询特征,提取最重要的特征信息。本文在公开的Java数据集和Python数据集上对IGANCS进行了评估。实验结果表明,IGANCS在Mean Reciprocal Rank(MRR)和SuccessRate@1/5/10指标上优于已有的基线模型。
Abstract
In code search tasks, existing deep learning-based code search algorithms struggle to capture the fine-grained interaction information between the code features and query features. Also, these approaches neglect the underlying structured features between features, leading to precise matching failure. This work proposes an Interaction and Graph Attention Network⁃based model for Code Search (IGANCS) to address these issues. Initially, by incorporating a similarity⁃matrix based interaction mechanism, IGANCS learns the fine-grained interactive relationship between code features and query features, facilitating alignment between the code and the query. Following this, a graph attention mechanism is introduced, utilizing a self-attention layer to learn the hidden structured features within the code and the query. This enables a more in-depth exploration of the structured semantics of both the code and the query. Finally, the model aggregates code features and query features separately using a max-pooling mechanism, extracting the most essentia feature information. This paper evaluates IGANCS using publicly available Java and Python datasets. Experimental results show that IGANCS surpasses existing baseline models on metrics, including Mean Reciprocal Rank and SuccessRate@1/5/10.
总的来说,以上代码搜索方法未能有效挖掘代码和查询的细粒度交互关系,并且忽略了特征之间潜在的结构化语义特征,这两方面的问题都限制了代码搜索方法的搜索准确性。为了解决这些问题,本文提出了一种基于交互和图注意力网络的代码搜索模型IGANCS(interaction and graph attention network⁃based model for code search,IGANCS)。为了验证模型的有效性,本文在两个公开的数据集上评估了IGANCS并将IGANCS与最新的信息检索模型CodeHow以及三种先进的基于深度学习的模型DeepCS、UNIF和MP-CAT进行了比较。
图4显示了IGANCS和其他模型在Java测试数据集上对于查询“adds a listener for all of this Controller's lifecycle events”“remove a table from the memory database”和“gets the file from a Java file object”的第一个搜索结果。可以注意到,IGANCS为上述三个查询在第一个搜索结果中返回了正确的代码,而DeepCS、UNIF和MP-CAT都没能返回正确的搜索结果。主要原因在于,DeepCS、UNIF和MP-CAT模型在联合嵌入过程中缺乏细粒度交互,并且忽略了代码和查询深层的结构化特征。IGANCS不仅考虑了代码特征和查询特征细粒度的对应关系,还挖掘了特征之间潜在的结构化信息,因此搜索结果更加准确。
CHANW K, CHENGH, LO D. Searching connected API subgraph via text phrases[C]//Proceedings of the ACM SIGSOFT 20th International Symposium on the Foundations of Software Engineering. New York: ACM, 2012: 1-11. DOI: 10.1145/2393596.2393606 .
[2]
MCMILLANC, GRECHANIKM, POSHYVANYKD, et al. Portfolio: Finding relevant functions and their usage[C]//Proceedings of the 33rd International Conference on Software Engineering. New York: ACM, 2011: 111-120. DOI: 10.1145/1985793.1985809 .
[3]
LINSTEADE, BAJRACHARYAS, NGO T, et al. Sourcerer: Mining and searching internet-scale software repositories[J]. Data Mining and Knowledge Discovery, 2009, 18(2): 300-336. DOI: 10.1007/s10618-008-0118-x .
[4]
LÜF, ZHANGH Y, LOUJ G, et al. CodeHow: Effective code search based on API understanding and extended Boolean model (E)[C]//2015 30th IEEE/ACM International Conference on Automated Software Engineering (ASE). New York: IEEE Press, 2016: 260-270. DOI: 10.1109/ASE.2015.42 .
[5]
GUX D, ZHANGH Y, KIMS. Deep code search[C]//Proceedings of the 40th International Conference on Software Engineering. New York: ACM, 2018: 933-944. DOI: 10.1145/3180155.3180167 .
[6]
WANY, SHUJ D, SUIY L, et al. Multi-modal attention network learning for semantic source code retrieval[C]//2019 34th IEEE/ACM International Conference on Automated Software Engineering (ASE). New York: IEEE Press, 2020: 13-25. DOI: 10.1109/ASE.2019.00012 .
[7]
LINGC Y, LINZ Q, ZOUY Z, et al. Adaptive deep code search[C]//Proceedings of the 28th International Conference on Program Comprehension. New York: ACM, 2020: 48-59. DOI: 10.1145/3387904.3389278 .
[8]
CAMBRONEROJ, LIH Y, KIMS, et al. When deep learning met code search[C]//Proceedings of the 2019 27th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering. New York: ACM, 2019: 964-974. DOI: 10.1145/3338906.3340458 .
[9]
YAOZ Y, PEDDAMAILJ R, SUNH. CoaCor: Code annotation for code retrieval with reinforcement learning[C]//WWW'19: The World Wide Web Conference. New York: ACM, 2019: 2203-2214. DOI: 10.1145/3308558.3313632 .
[10]
SUNDERMEYERM, SCHLÜTERR, NEYH. LSTM Neural Networks for Language Modeling[DB/OL].[2022-10-10]. DOI: 10.21437/interspeech.2012-65 .
[11]
HALDARR, WUL F, XIONGJ J, et al. A Multi-perspective Architecture for Semantic Code Search[DB/OL].[2022-10-10]. DOI: 10.18653/v1/2020.acl-main.758 .
[12]
VELIČKOVIĆP, CUCURULLG, CASANOVAA, et al. Graph Attention Networks[EB/OL]. [2022-10-11].
[13]
MCMILLANC, GRECHANIKM, POSHYVANYKD, et al. Exemplar: A source code search engine for finding highly relevant applications[J]. IEEE Transactions on Software Engineering, 2012, 38(5): 1069-1087. DOI: 10.1109/TSE.2011.84 .
[14]
ALONU, ZILBERSTEINM, LEVYO, et al. code2vec: Learning distributed representations of code[J]. Proceedings of the ACM on Programming Languages, 2019, 3(POPL): 1-29. DOI: 10.1145/3290353 .
[15]
ALONU, BRODYS, LEVYO, et al. code2seq: Generating Sequences from Structured Representations of Code[EB/OL]. [2022-10-10].
[16]
XUL, YANGH H, LIUC, et al. Two-stage attention-based model for code search with textual and structural features[C]//2021 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER). New York: IEEE Press, 2021: 342-353. DOI: 10.1109/SANER50967.2021.00039 .
[17]
HUX, LIG, XIAX, et al. Deep code comment generation[C]//Proceedings of the 26th Conference on Program Comprehension. New York: ACM, 2018: 200-210. DOI: 10.1145/3196321.3196334 .
[18]
BARONEA V M, SENNRICHR. A Parallel Corpus of Python Functions and Documentation Strings for Automated Code Documentation and Code Generation[EB/OL]. [2022-10-10]. DOI: 10.1007/979-8-8688-0160-0_4 .
[19]
LIX, WANGZ R, WANGQ X, et al. Relationship-aware code search for JavaScript frameworks[C]//Proceedings of the 2016 24th ACM SIGSOFT International Symposium on Foundations of Software Engineering. New York: ACM, 2016: 690-701. DOI: 10.1145/2950290.2950341 .
[20]
YEX, BUNESCUR, LIUC. Learning to rank relevant files for bug reports using domain knowledge[C]//Proceedings of the 22nd ACM SIGSOFT International Symposium on Foundations of Software Engineering. New York: ACM,2014: 689-699. DOI:10.1145/2635868.2635874 .
[21]
LIL, DONGR H, CHENL. Context-aware co-attention neural network for service recommendations[C]//2019 IEEE 35th International Conference on Data Engineering Workshops (ICDEW). New York: IEEE Press, 2019: 201-208. DOI: 10.1109/ICDEW.2019.00-11 .
[22]
WANGZ H, LIUX H, LIH S, et al. CAMP: Cross-modal adaptive message passing for text-image retrieval[C]//2019 IEEE/CVF International Conference on Computer Vision (ICCV). New York: IEEE Press, 2020: 5763-5772. DOI: 10.1109/ICCV.2019.00586 .
[23]
LEEK H, CHENX, HUAG, et al. Stacked cross attention for image-text matching[C]//European Conference on Computer Vision. Cham: Springer, 2018: 212-228.10.1007/978-3-030-01225-0_13. DOI: 10.1007/978-3-030-01225-0_13 .
[24]
LIUB, ZHANGT, NIUD, et al. Matching Long Text Documents via Graph Convolutional Networks[DB/OL]. [2022-02-03].
[25]
LIUC X, MAOZ D, ZHANGT Z, et al. Graph structured network for image-text matching[C]//2020 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR). New York: IEEE Press, 2020: 10921-10930. DOI: 10.1109/cvpr42600.2020.01093 .