skip to main content
research-article

Deep Graph Matching and Searching for Semantic Code Retrieval

Published:10 May 2021Publication History
Skip Abstract Section

Abstract

Code retrieval is to find the code snippet from a large corpus of source code repositories that highly matches the query of natural language description. Recent work mainly uses natural language processing techniques to process both query texts (i.e., human natural language) and code snippets (i.e., machine programming language), however, neglecting the deep structured features of query texts and source codes, both of which contain rich semantic information. In this article, we propose an end-to-end deep graph matching and searching (DGMS) model based on graph neural networks for the task of semantic code retrieval. To this end, we first represent both natural language query texts and programming language code snippets with the unified graph-structured data, and then use the proposed graph matching and searching model to retrieve the best matching code snippet. In particular, DGMS not only captures more structural information for individual query texts or code snippets, but also learns the fine-grained similarity between them by cross-attention based semantic matching operations. We evaluate the proposed DGMS model on two public code retrieval datasets with two representative programming languages (i.e., Java and Python). Experiment results demonstrate that DGMS significantly outperforms state-of-the-art baseline models by a large margin on both datasets. Moreover, our extensive ablation studies systematically investigate and illustrate the impact of each part of DGMS.

References

  1. Wasi Ahmad, Saikat Chakraborty, Baishakhi Ray, and Kai-Wei Chang. 2020. A transformer-based approach for source code summarization. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics,. 4998--5007.Google ScholarGoogle ScholarCross RefCross Ref
  2. Miltiadis Allamanis, Earl T. Barr, Premkumar Devanbu, and Charles Sutton. 2018. A survey of machine learning for big code and naturalness. ACM Computing Surveys 51, 4 (2018), 1--37.Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Miltiadis Allamanis, Marc Brockschmidt, and Mahmoud Khademi. 2018. Learning to represent programs with graphs. In Proceedings of the International Conference on Learning Representations. OpenReview.net, Vancouver, BC, Canada.Google ScholarGoogle Scholar
  4. Uri Alon, Shaked Brody, Omer Levy, and Eran Yahav. 2019. Code2seq: Generating sequences from structured representations of code. In Proceedings of the International Conference on Learning Representations. OpenReview.net, New Orleans, LA.Google ScholarGoogle Scholar
  5. Uri Alon, Roy Sadaka, Omer Levy, and Eran Yahav. 2020. Structural language models of code. In Proceedings of the Thirty-seventh International Conference on Machine Learning. PMLR, Virtual Event, 245--256.Google ScholarGoogle Scholar
  6. Uri Alon, Meital Zilberstein, Omer Levy, and Eran Yahav. 2019. Code2vec: Learning distributed representations of code. Proceedings of the ACM on Programming Languages 3, POPL (2019), 40:1–40:29. https://dl.acm.org/doi/10.1145/3290353.Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Yunsheng Bai, Hao Ding, Song Bian, Ting Chen, Yizhou Sun, and Wei Wang. 2019. Simgnn: A neural network approach to fast graph similarity computation. In Proceedings of the 12th ACM International Conference on Web Search and Data Mining. ACM, Melbourne, Australia, 384--392.Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Vassileios Balntas, Edgar Riba, Daniel Ponsa, and Krystian Mikolajczyk. 2016. Learning local feature descriptors with triplets and shallow convolutional neural networks. In Proceedings of the British Machine Vision Conference. BMVA Press, York, UK, 3.Google ScholarGoogle ScholarCross RefCross Ref
  9. Piotr Bojanowski, Edouard Grave, Armand Joulin, and Tomas Mikolov. 2017. Enriching word vectors with subword information. Transactions of the Association for Computational Linguistics 5 (2017), 135--146. https://www.aclweb.org/anthology/Q17-1010/.Google ScholarGoogle ScholarCross RefCross Ref
  10. Marc Brockschmidt, Miltiadis Allamanis, Alexander L. Gaunt, and Oleksandr Polozov. 2019. Generative code modeling with graphs. In Proceedings of the International Conference on Learning Representations. OpenReview.net, New Orleans, LA.Google ScholarGoogle Scholar
  11. Jane Bromley, Isabelle Guyon, Yann LeCun, Eduard Säckinger, and Roopak Shah. 1993. Signature verification using a “siamese” time delay neural network. In Proceedings of the Advances in Neural Information Processing Systems. Morgan-Kaufmann, Denver, Colorado, 737--744.Google ScholarGoogle ScholarCross RefCross Ref
  12. Michael M. Bronstein, Joan Bruna, Yann LeCun, Arthur Szlam, and Pierre Vandergheynst. 2017. Geometric deep learning: Going beyond euclidean data. IEEE Signal Processing Magazine 34, 4 (2017), 18--42.Google ScholarGoogle ScholarCross RefCross Ref
  13. Jose Cambronero, Hongyu Li, Seohyun Kim, Koushik Sen, and Satish Chandra. 2019. When deep learning met code search. In Proceedings of the 2019 27th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering. ACM, Tallinn, Estonia, 964--974.Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Yu Chen, Lingfei Wu, and Mohammed Zaki. 2020. Iterative deep graph learning for graph neural networks: Better and robust node embeddings. In Proceedings of the Advances in Neural Information Processing Systems. Curran Associates, Inc., Virtual Event.Google ScholarGoogle Scholar
  15. Kyunghyun Cho, Bart Van Merriënboer, Caglar Gulcehre, Dzmitry Bahdanau, Fethi Bougares, Holger Schwenk, and Yoshua Bengio. 2014. Learning phrase representations using RNN encoder–decoder for statistical machine translation. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing. ACL, Doha, Qatar, 1724--1734.Google ScholarGoogle ScholarCross RefCross Ref
  16. Noam Chomsky. 1956. Three models for the description of language. IRE Transactions on Information Theory 2, 3 (1956), 113--124.Google ScholarGoogle ScholarCross RefCross Ref
  17. Ronan Collobert and Samy Bengio. 2004. Links between perceptrons, MLPs and SVMs. In Proceedings of the 21st International Conference on Machine Learning. ACM, Banff, Alberta, Canada, 23.Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Milan Cvitkovic, Badal Singh, and Animashree Anandkumar. 2019. Open vocabulary learning on source code with a graph-structured cache. In Proceedings of the 36th International Conference on Machine Learning. PMLR, Long Beach, California, 1475--1485.Google ScholarGoogle Scholar
  19. Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova. 2019. BERT: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies. ACL, Minneapolis, Minnesota, 4171--4186.Google ScholarGoogle Scholar
  20. Federico Errica, Marco Podda, Davide Bacciu, and Alessio Micheli. 2020. A fair comparison of graph neural networks for graph classification. In Proceedings of the International Conference on Learning Representations. OpenReview.net, Addis Ababa, Ethiopia. Retrieved from https://openreview.net/forum?id=HygDF6NFPB.Google ScholarGoogle Scholar
  21. Facebook Research. 2019. Releasing a new benchmark and data set for evaluating neural code search models. Retrieved from https://ai.facebook.com/blog/neural-code-search-evaluation-dataset/.Google ScholarGoogle Scholar
  22. Patrick Fernandes, Miltiadis Allamanis, and Marc Brockschmidt. 2019. Structured neural summarization. In Proceedings of the International Conference on Learning Representations. OpenReview.net, New Orleans, LA.Google ScholarGoogle Scholar
  23. Matthias Fey and Jan E. Lenssen. 2019. Fast graph representation learning with PyTorch geometric. In Proceedings of the ICLR Workshop on Representation Learning on Graphs and Manifolds. OpenReview.net, New Orleans, LA.Google ScholarGoogle Scholar
  24. Justin Gilmer, Samuel S. Schoenholz, Patrick F. Riley, Oriol Vinyals, and George E. Dahl. 2017. Neural message passing for quantum chemistry. In Proceedings of the 34th International Conference on Machine Learning. PMLR, Sydney, NSW, Australia, 1263--1272.Google ScholarGoogle Scholar
  25. Xiaodong Gu, Hongyu Zhang, and Sunghun Kim. 2018. Deep code search. In Proceedings of the 40th International Conference on Software Engineering. Association for Computing Machinery, Gothenburg, Sweden, 933--944.Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Rajarshi Haldar, Lingfei Wu, Jinjun Xiong, and Julia Hockenmaier. 2020. A multi-perspective architecture for semantic code search. In Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics. ACL, Virtual Event, 8563--8568.Google ScholarGoogle ScholarCross RefCross Ref
  27. Will Hamilton, Zhitao Ying, and Jure Leskovec. 2017. Inductive representation learning on large graphs. In Proceedings of the Advances in Neural Information Processing Systems. Curran Associates, Inc., Long Beach, CA, 1024--1034.Google ScholarGoogle Scholar
  28. Emily Hill, Lori Pollock, and K. Vijay-Shanker. 2011. Improving source code search with natural language phrasal representations of method signatures. In Proceedings of the 26th IEEE/ACM International Conference on Automated Software Engineering. IEEE Computer Society, Lawrence, KS, 524--527.Google ScholarGoogle Scholar
  29. Sepp Hochreiter and Jürgen Schmidhuber. 1997. Long short-term memory. Neural Computation 9, 8 (1997), 1735--1780.Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Hamel Husain, Ho-Hsiang Wu, Tiferet Gazit, Miltiadis Allamanis, and Marc Brockschmidt. 2019. Codesearchnet challenge: Evaluating the state of semantic code search. arXiv preprint arXiv:1909.09436 (2019).Google ScholarGoogle Scholar
  31. Srinivasan Iyer, Ioannis Konstas, Alvin Cheung, and Luke Zettlemoyer. 2016. Summarizing source code using a neural attention model. In Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers). ACL, Berlin, Germany, 2073--2083.Google ScholarGoogle ScholarCross RefCross Ref
  32. Daniel Jurafsky and James H. Martin. 2019. Speech and Language Processing: An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition (3rd draft ed.). Retrieved from https://web.stanford.edu/ jurafsky/slp3/.Google ScholarGoogle Scholar
  33. Yoon Kim. 2014. Convolutional neural networks for sentence classification. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing. ACL, Doha, Qatar, 1746--1751.Google ScholarGoogle ScholarCross RefCross Ref
  34. Thomas N. Kipf and Max Welling. 2017. Semi-supervised classification with graph convolutional networks. In Proceedings of the 5th International Conference on Learning Representations. OpenReview.net, Toulon, France.Google ScholarGoogle Scholar
  35. Alexander LeClair, Sakib Haque, Linfgei Wu, and Collin McMillan. 2020. Improved code summarization via a graph neural network. arXiv preprint arXiv:2004.02843 (2020).Google ScholarGoogle Scholar
  36. Hongyu Li, Seohyun Kim, and Satish Chandra. 2019. Neural code search evaluation dataset. arXiv preprint arXiv:1908.09804 (2019).Google ScholarGoogle Scholar
  37. Yujia Li, Daniel Tarlow, Marc Brockschmidt, and Richard S. Zemel. 2016. Gated graph sequence neural networks. In Proceedings of the 4th International Conference on Learning Representations, Yoshua Bengio and Yann LeCun (Eds.). OpenReview.net, San Juan, Puerto Rico.Google ScholarGoogle Scholar
  38. Xiang Ling, Lingfei Wu, Saizhuo Wang, Tengfei Ma, Fangli Xu, Alex X Liu, Chunming Wu, and Shouling Ji. 2020. Multi-Level Graph Matching Networks for Deep Graph Similarity Learning. arXiv preprint arXiv:2007.04395 (2020).Google ScholarGoogle Scholar
  39. Erik Linstead, Sushil Bajracharya, Trung Ngo, Paul Rigor, Cristina Lopes, and Pierre Baldi. 2009. Sourcerer: Mining searching internet-scale software repositories. Data Mining and Knowledge Discovery 18, 2 (2009), 300--336.Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Fei Lv, Hongyu Zhang, Jian-guang Lou, Shaowei Wang, Dongmei Zhang, and Jianjun Zhao. 2015. Codehow: Effective code search based on api understanding and extended boolean model. In Proceedings of the 30th IEEE/ACM International Conference on Automated Software Engineering. IEEE Computer Society, Lincoln, NE, 260--270.Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Christopher D. Manning, Mihai Surdeanu, John Bauer, Jenny Finkel, Steven J. Bethard, and David McClosky. 2014. The stanford CoreNLP natural language processing toolkit. In Proceedings of 52nd Annual Meeting of the Association for Computational Linguistics: System Demonstrations, Baltimore, MD, 55--60.Google ScholarGoogle ScholarCross RefCross Ref
  42. Collin McMillan, Mark Grechanik, Denys Poshyvanyk, Qing Xie, and Chen Fu. 2011. Portfolio: Finding relevant functions and their usage. In Proceedings of the 33rd International Conference on Software Engineering. ACM, Waikiki, Honolulu , HI, 111--120.Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Yusuke Oda, Hiroyuki Fudaba, Graham Neubig, Hideaki Hata, Sakriani Sakti, Tomoki Toda, and Satoshi Nakamura. 2015. Learning to generate pseudo-code from source code using statistical machine translation (t). In Proceedings of the 30th IEEE/ACM International Conference on Automated Software Engineering. IEEE Computer Society, Lincoln, NE, 574--584.Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Lawrence Page, Sergey Brin, Rajeev Motwani, and Terry Winograd. 1999. The PageRank Citation Ranking: Bringing Order to the Web. Technical Report 1999-66. Stanford InfoLab. Retrieved from http://ilpubs.stanford.edu:8090/422/.Google ScholarGoogle Scholar
  45. Adam Paszke, Sam Gross, Francisco Massa, Adam Lerer, James Bradbury, Gregory Chanan, Trevor Killeen, Zeming Lin, Natalia Gimelshein, Luca Antiga, Alban Desmaison, Andreas Köpf, Edward Yang, Zachary DeVito, Martin Raison, Alykhan Tejani, Sasank Chilamkurthy, Benoit Steiner, Lu Fang, Junjie Bai, and Soumith Chintala. 2019. PyTorch: An imperative style, high-performance deep learning library. In Proceedings of the Advances in Neural Information Processing Systems. Curran Associates, Inc., Vancouver, BC, Canada, 8026--8037.Google ScholarGoogle Scholar
  46. Jeffrey Pennington, Richard Socher, and Christopher D. Manning. 2014. GloVe: Global vectors for word representation. In Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing. ACL, Doha, Qatar, 1532--1543.Google ScholarGoogle Scholar
  47. Yu Rong, Tingyang Xu, Junzhou Huang, Wenbing Huang, Hong Cheng, Yao Ma, Yiqi Wang, Tyler Derr, Lingfei Wu, and Tengfei Ma. 2020. Deep graph learning: Foundations, advances and applications. In Proceedings of the 26th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining. ACM, 3555--3556.Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. Saksham Sachdev, Hongyu Li, Sifei Luan, Seohyun Kim, Koushik Sen, and Satish Chandra. 2018. Retrieval on source code: A neural code search. In Proceedings of the 2nd ACM SIGPLAN International Workshop on Machine Learning and Programming Languages. ACM, Philadelphia, PA, 31--41.Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. Franco Scarselli, Marco Gori, Ah Chung Tsoi, Markus Hagenbuchner, and Gabriele Monfardini. 2008. The graph neural network model. IEEE Transactions on Neural Networks 20, 1 (2008), 61--80.Google ScholarGoogle ScholarDigital LibraryDigital Library
  50. Michael Schlichtkrull, Thomas N. Kipf, Peter Bloem, Rianne Van Den Berg, Ivan Titov, and Max Welling. 2018. Modeling relational data with graph convolutional networks. In Proceedings of the European Semantic Web Conference. Springer, Heraklion, Crete, Greece, 593--607.Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. Renuka Sindhgatta. 2006. Using an information retrieval system to retrieve source code samples. In Proceedings of the 28th International Conference on Software Engineering. ACM, Shanghai, China, 905--908.Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. Kenneth Slonneger and Barry L. Kurtz. 1995. Formal Syntax and Semantics of Programming Languages. Addison-Wesley Reading.Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Łukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In Proceedings of the Advances in Neural Information Processing Systems. Curran Associates, Inc., Long Beach, CA, 5998--6008.Google ScholarGoogle Scholar
  54. Petar Velickovic, Guillem Cucurull, Arantxa Casanova, Adriana Romero, Pietro Liò, and Yoshua Bengio. 2018. Graph attention networks. In Proceedings of the 6th International Conference on Learning Representations. OpenReview.net, Vancouver, BC, Canada.Google ScholarGoogle Scholar
  55. Yao Wan, Jingdong Shu, Yulei Sui, Guandong Xu, Zhou Zhao, Jian Wu, and Philip Yu. 2019. Multi-modal attention network learning for semantic source code retrieval. In Proceedings of the 34th IEEE/ACM International Conference on Automated Software Engineering. IEEE, San Diego, CA, 13--25.Google ScholarGoogle ScholarDigital LibraryDigital Library
  56. Shuohang Wang and Jing Jiang. 2017. A compare-aggregate model for matching text sequences. In Proceedings of the International Conference on Learning Representations. OpenReview.net, Toulon, France.Google ScholarGoogle Scholar
  57. Zhiguo Wang, Wael Hamza, and Radu Florian. 2017. Bilateral multi-perspective matching for natural language sentences. In Proceedings of the 26th International Joint Conference on Artificial Intelligence. ijcai.org, Melbourne, Australia, 4144--4150.Google ScholarGoogle ScholarCross RefCross Ref
  58. Lingfei Wu, Ian En-Hsu Yen, Zhen Zhang, Kun Xu, Liang Zhao, Xi Peng, Yinglong Xia, and Charu Aggarwal. 2019. Scalable global alignment graph kernel using random features: From node embedding to graph embedding. In Proceedings of the 25th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining. ACM, Anchorage, AK, 1418--1428.Google ScholarGoogle ScholarDigital LibraryDigital Library
  59. Zonghan Wu, Shirui Pan, Fengwen Chen, Guodong Long, Chengqi Zhang, and S. Yu Philip. 2021. A comprehensive survey on graph neural networks. IEEE Transactions on Neural Networks and Learning Systems 32, 1 (2021), 4--24.Google ScholarGoogle ScholarCross RefCross Ref
  60. Tian Xie and Jeffrey C Grossman. 2018. Crystal graph convolutional neural networks for an accurate and interpretable prediction of material properties. Physical Review Letters 120, 14 (2018), 145301.Google ScholarGoogle ScholarCross RefCross Ref
  61. Keyulu Xu, Weihua Hu, Jure Leskovec, and Stefanie Jegelka. 2019. How powerful are graph neural networks? In Proceedings of the 7th International Conference on Learning Representations. OpenReview.net, New Orleans, LA.Google ScholarGoogle Scholar
  62. Ziyu Yao, Jayavardhan Reddy Peddamail, and Huan Sun. 2019. CoaCor: Code annotation for code retrieval with reinforcement learning. In Proceedings of The World Wide Web Conference. ACM, San Francisco, CA, 2203--2214.Google ScholarGoogle ScholarDigital LibraryDigital Library
  63. Muhan Zhang and Yixin Chen. 2018. Link prediction based on graph neural networks. In Proceedings of the Advances in Neural Information Processing Systems. Curran Associates, Inc., Montréal, Canada, 5165--5175.Google ScholarGoogle Scholar
  64. Zhen Zhang, Yijian Xiang, Lingfei Wu, Bing Xue, and Arye Nehorai. 2019. KerGM: Kernelized graph matching. In Proceedings of the Advances in Neural Information Processing Systems. Curran Associates, Inc., Vancouver, BC, Canada, 3335--3346.Google ScholarGoogle Scholar

Index Terms

  1. Deep Graph Matching and Searching for Semantic Code Retrieval

          Recommendations

          Comments

          Login options

          Check if you have access through your login credentials or your institution to get full access on this article.

          Sign in

          Full Access

          • Published in

            cover image ACM Transactions on Knowledge Discovery from Data
            ACM Transactions on Knowledge Discovery from Data  Volume 15, Issue 5
            October 2021
            508 pages
            ISSN:1556-4681
            EISSN:1556-472X
            DOI:10.1145/3461317
            Issue’s Table of Contents

            Copyright © 2021 ACM

            Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

            Publisher

            Association for Computing Machinery

            New York, NY, United States

            Publication History

            • Published: 10 May 2021
            • Accepted: 1 January 2021
            • Received: 1 September 2020
            Published in tkdd Volume 15, Issue 5

            Permissions

            Request permissions about this article.

            Request Permissions

            Check for updates

            Qualifiers

            • research-article
            • Research
            • Refereed

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader

          HTML Format

          View this article in HTML Format .

          View HTML Format