计算机科学 ›› 2023, Vol. 50 ›› Issue (5): 64-71.doi: 10.11896/jsjkx.220100094
孙雪凯, 蒋烈辉
SUN Xuekai, JIANG Liehui
摘要: 对代码进行分析研究具有很多的应用场景,例如代码抄袭检测、软件漏洞搜索等。随着人工智能的发展,神经网络技术被广泛应用于代码分析和研究。然而,现有的方法要么简单地将代码视为普通的自然语言处理,要么使用太过复杂的规则对代码进行采样,前者的处理方式容易造成代码关键信息的丢失,而后者会造成算法过于复杂,模型的训练需要花费较长的时间。Alon等提出了一种名为Code2vec的算法,该算法采用了一种简单且有效的代码表示方法,相比之前的代码分析方法有着显著的优势,但Code2vec算法仍存在一些局限性。因此,在其基础上提出了一种基于神经网络的代码嵌入方法,该方法的主要思想是将代码函数表示为代码的嵌入向量。首先将一个代码函数分解为一系列抽象语法树路径,然后通过神经网络去学习如何表示每一条路径,最后将所有路径聚合成一个嵌入向量来表示当前的代码函数。文中实现了一个基于该方法的原型系统,实验结果表明,相比Code2vec,所提算法的结构更加简单、训练速度更快。
中图分类号:
[1]ZHANG D,LUO P.Survey of code similarity detection methods and tools[J].Computer Science,2020,47(3):5-10. [2]CHEN Q Y,LI S P,YAN M,et al.Code clone detection:A literature review[J].Journal of Software,2019,30(4):962-980. [3]ALON U,ZILBERSTEIN M,LEVY O,et al.Code2vec:learning distributed representations of code[J].Proceedings of the Programming Languages,2019,3(POPL):1-29. [4]SHI Z C,ZHOU Y.Method of Code Features Automated Ex-traction[J].Journal of Frontiers of Computer Science and Technology,2021,15(3):456-467. [5]KAMIYA T,KUSUMOTO S,INOUE K.CCFinder:a multilinguistic token-based code clone detection system for large scale source code[J].IEEE Transactions on Software Engineering,2002,28(7):654-670. [6]SAJNANI H,SAINI V,SVAJLENKO J,et al.SourcererCC:scaling code clone detection to big-code[C]//Proceedings of the 38th International Conference on Software Engineering.2016:1157-1168. [7]JIANG L,MISHERGHI G,SU Z,et al.DECKARD:scalable and accurate tree-based detection of code clones[C]//International Conference on Software Engineering.IEEE,2006. [8]ZHOU Y,YAN X,YANG W,et al.Augmenting Java method comments generation with context information based on neural networks[J].The Journal of Systems and Software,2019,156(Oct.):328-340. [9]YAN X,ZHOU Y,HUANG Z Q.Code snippets recommendation based on sequence to sequence model[J].Journal of Frontiers of Computer Science and Technology,2020,14(5):731-739. [10]HU X,LI G,XIA X,et al.Deep code comment generation[C]//Proceedings of the 26th Conference on Program Comprehension.2018:200-210. [11]WHITE M,TUFANO M,VENDOME C,et al.Deep learningcode fragments for code clone detection[C]//Proceedings of the 31st IEEE/ACM International Conference on Automated Software Engineering.2016:87-98. [12]WAN Y,ZHAO Z,YANG M,et al.Improving automaticsource code summarization via deep reinforcement learning[C]//Proceedings of the 33rd IEEE/ACM International Conference on Automated Software Engineering.2018:397-407. [13]MOU L L,LI G,ZHANG L,et al.Convolutional neural net-works over tree structures for programming language processing[C]//Proceedings of the 30th AAAI Conference on Artificial Intelligence.2016:1287-1293. [14]ALLAMANIS M,PENG H,SUTTON C.Aconvolutional at-tention network for extreme summarization of source code[C]//Proceedings of the 33nd International Conference on Machine Learning.2016:2091-2100. [15]IYER S,KONSTAS I,CHEUNG A,et al.Summarizing source code using a neural attention model[C]//Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics.2016. [16]XU X J,LIU C,QIAN F,et al.Neural network-based graphembedding for cross-platform binary code similarity detection[C]//Proceedings of the 2017 ACM SIGSAC Conference on Computer and Communications Security.2017:363-376. [17]XIONG H,YAN H H,GUO T,et al.Code similarity detection:a survey[J].Computer Science,2010,37(8):9-14,76. [18]DONALDSON J L,LANCASTER A M,SPOSATO P H.Aplagiarism detection system[C]//ACM SIGCSE Bulletin.1981:21-25. [19]ENGELS S,LAKSHMANAN V,CRAIG M.Plagiarism detection using feature-based neural networks[C]//ACM SIGCSE Bulletin.2007:34-38. [20]RUBINSTEIN R.The cross-entropy method for combinatorial and continuous optimization[J].Methodology and Computing in Applied Probability,1999,1(2):127-190. [21]ALON U,ZILBERSTEIN M,LEVY O,et al.A general path-based representation forpredicting program properties[C]//Proceedings of the 39th ACM SIGPLAN Conference.ACM,2018. [22]KINGMA D P,BA J.Adam:a method for stochastic optimization[J].arXiv:1412.6980,2017. [23]SRIVASTAVA N,HINTON G,KRIZHEVSKY A,et al.Dropout:a simple way to prevent neural networks from overfitting[J].Journal of Machine Learning Research,2014,15(1):1929-1958. [24]BENGIO Y,GLOROT X.Understanding the difficulty of trai-ning deep feed forward neural networks[C]//Proceedings of the 13th International Conference on Artificial Intelligence and Statistics.2010:249-256. |
|