110
55

GraphSearchNet: Enhancing GNNs via Capturing Global Dependency for Semantic Code Search

Abstract

Code search aims to retrieve the accurate code fragments based on a natural language query to improve the software productivity and quality. However, automated deep code search is still challenging due to the semantic gap between the program and the natural language query. Most existing deep learning-based approaches for code search rely on the sequential text eg., feeding the program and the query as a flat sequence of tokens to learn the program semantics and the structural information for both program and the query is not fully considered. Furthermore, the widely adopted Graph Neural Networks (GNNs) have proved the effectiveness in learning program semantics, however they also suffer from capturing the global dependency between any pair of nodes in the constructed graph, which hinder the model learning capacity. In this paper, to address these challenges, we design a novel neural network framework, named GraphSearchNet, to enable an effective and accurate source code search by jointly learning rich semantics of both source code and natural language queries. Specifically, we propose to encode both source code and queries into two separated graphs with Bidirectional GGNN to capture the local structural information of the programs and queries. We further enhance it by utilizing the effective multi-head attention mechanism to supplement the global dependency that BiGGNN missed to improve the model learning capacity. The extensive experiments on both Java and Python language from the public benchmark illustrate that GraphSearchNet outperforms current state-of-the-art works by a significant margin. We further conduct a quantitative analysis based on the real queries to further illustrate the effectiveness of our approach.

View on arXiv
Comments on this paper