Graph Matching Networks for Learning the Similarity of Graph Structured Objects

This paper addresses the challenging problem of retrieval and matching of graph structured objects , and makes two key contributions . First , we demonstrate how Graph Neural Networks ( GNN ) , which have emerged as an effective model for various supervised prediction problems defined on structured data , can be trained to produce embedding of graphs in vector spaces that enables efficient similarity reasoning . Second , we propose a novel Graph Matching Network model that , given a pair of graphs as input , computes a similarity score between them by jointly reasoning on the pair through a new cross-graph attention-based matching mechanism . We demonstrate the effectiveness of our models on different domains including the challenging problem of control-flow-graph based function similarity search that plays an important role in the detection of vulnerabilities in software systems . The experimental analysis demonstrates that our models are not only able to exploit structure in the context of similarity learning but they can also outperform domain-specific baseline systems that have been carefully hand-engineered for these problems . 1 INTRODUCTION . Graphs are natural representations for encoding relational structures that are encountered in many domains . Expectedly , computations defined over graph structured data are employed in a wide variety of fields , from the analysis of molecules for computational biology and chemistry ( Gilmer et al. , 2017 ; Yan et al. , 2005 ) , to the analysis of knowledge graphs or graph structured parses for natural language understanding . In the past few years graph neural networks ( GNNs ) have emerged as an effective class of models for learning representations of structured data and for solving various supervised prediction problems on graphs . Such models are invariant to permutations of graph elements by design and compute graph node representations through a propagation process which iteratively aggregates local structural information ( Scarselli et al. , 2009 ; Li et al. , 2015 ; Gilmer et al. , 2017 ) . These node representations are then used directly for node classification , or pooled into a graph vector for graph classification . Problems beyond supervised classification or regression are relatively less well-studied for GNNs . In this paper we study the problem of similarity learning for graph structured objects , which appears in many important real world applications , in particular similarity based retrieval in graph databases . One motivating application is the computer security problem of binary function similarity search , where given a binary which may or may not contain code with known vulnerabilities , we wish to check whether any control-flow-graph in this binary is sufficiently similar to a database of known-vulnerable functions . This helps identify vulnerable statically linked libraries in closed-source software , a recurring problem ( CVE , 2010 ; 2018 ) for which no good solutions are currently available . Figure 1 shows one example from this application , where the binary functions are represented as control flow graphs annotated with assembly instructions . This similarity learning problem is very challenging as subtle differences can make two graphs be semantically very different , while graphs with different structures can still be similar . A successful model for this problem should therefore ( 1 ) exploit the graph structures , and ( 2 ) be able to reason about the similarity of graphs both from the graph structures as well as from learned semantics . In order to solve the graph similarity learning problem , we investigate the use of GNNs in this context , explore how they can be used to embed graphs into a vector space , and learn this embedding model to make similar graphs close in the vector space , and dissimilar graphs far apart . One important property of this model is that , it maps each graph independently to an embedding vector , and then all the similarity computation happens in the vector space . Therefore , the embeddings of graphs in a large database can be precomputed and indexed , which enables efficient retrieval with fast nearest neighbor search data structures like k-d trees ( Bentley , 1975 ) or locality sensitive hashing ( Gionis et al. , 1999 ) . We further propose an extension to GNNs which we call Graph Matching Networks ( GMNs ) for similarity learning . Instead of computing graph representations independently for each graph , the GMNs compute a similarity score through a cross-graph attention mechanism to associate nodes across graphs and identify differences . By making the graph representation computation dependent on the pair , this matching model is more powerful than the embedding model , providing a nice accuracy-computation trade-off . We evaluate the proposed models and baselines on three tasks : a synthetic graph edit-distance learning task which captures structural similarity only , and two real world tasks - binary function similarity search and mesh retrieval , which require reasoning about both the structural and semantic similarity . On all tasks , the proposed approaches outperform established baselines and structure agnostic models ; in more detailed ablation studies , we found that the Graph Matching Networks consistently outperform the graph embedding model and Siamese networks . To summarize , the contributions of this paper are : ( 1 ) we demonstrate how GNNs can be used to produce graph embeddings for similarity learning ; ( 2 ) we propose the new Graph Matching Networks that computes similarity through cross-graph attention-based matching ; ( 3 ) empirically we show that the proposed graph similarity learning models achieve good performance across a range of applications , outperforming structure agnostic models and established hand-engineered baselines . 2 RELATED WORK . Graph Neural Networks and Graph Representation Learning The history of graph neural networks ( GNNs ) goes back to at least the early work by Gori et al . ( 2005 ) and Scarselli et al . ( 2009 ) , who proposed to use a propagation process to learn node representations . These models have been further developed by incorporating modern deep learning components ( Li et al. , 2015 ; Veličković et al. , 2017 ; Bruna et al. , 2013 ) . A separate line of work focuses on generalizing convolutions to graphs ( Bruna et al. , 2013 ; Bronstein et al. , 2017 ) . Popular graph convolutional networks also compute node updates by aggregating information in local neighborhoods ( Kipf & Welling , 2016 ) , making them the same family of models as GNNs . GNNs have been successfully used in many domains ( Kipf & Welling , 2016 ; Veličković et al. , 2017 ; Battaglia et al. , 2016 ; 2018 ; Niepert et al. , 2016 ; Duvenaud et al. , 2015 ; Gilmer et al. , 2017 ; Dai et al. , 2017 ; Li et al. , 2018 ; Wang et al. , 2018a ; b ) . Most of the previous work on GNNs focus on supervised prediction problems ( with exceptions like ( Dai et al. , 2017 ; Li et al. , 2018 ; Wang et al. , 2018a ) ) . The graph similarity learning problem we study in this paper and the new graph matching model can be good additions to this family of models . Graph Similarity Search and Graph Kernels Graph similarity search has been studied extensively in database and data mining communities ( Yan et al. , 2005 ; Dijkman et al. , 2009 ) . The similarity is typically defined by either exact matches ( full-graph or sub-graph isomorphism ) ( Berretti et al. , 2001 ; Shasha et al. , 2002 ; Yan et al. , 2004 ; Srinivasa & Kumar , 2003 ) or some measure of structural similarity , e.g . in terms of graph edit distances ( Willett et al. , 1998 ; Raymond et al. , 2002 ) . Most of the approaches proposed in this direction are not learning-based , and focus on efficiency . Graph kernels are kernels on graphs designed to capture the graph similarity , and can be used in kernel methods for e.g . graph classification ( Vishwanathan et al. , 2010 ; Shervashidze et al. , 2011 ) . Popular graph kernels include those that measure the similarity between walks or paths on graphs ( Borgwardt & Kriegel , 2005 ; Kashima et al. , 2003 ; Vishwanathan et al. , 2010 ) , kernels based on limited-sized substructures ( Horváth et al. , 2004 ; Shervashidze et al. , 2009 ) and kernels based on sub-tree structures ( Shervashidze & Borgwardt , 2009 ; Shervashidze et al. , 2011 ) . Graph kernels are usually used in models that may have learned components , but the kernels themselves are handdesigned and motivated by graph theory . They can typically be formulated as first computing the feature vectors for each graph ( the kernel embedding ) , and then take inner product between these vectors to compute the kernel value . One exception is ( Yanardag & Vishwanathan , 2015 ) where the co-occurrence of graph elements ( substructures , walks , etc . ) are learned , but the basic elements are still hand-designed . Compared to these approaches , our graph neural network based similarity learning framework learns the similarity metric end-to-end . Distance Metric Learning Learning a distance metric between data points is the key focus of the area of metric learning . Most of the early work on metric learning assumes that the data already lies in a vector space , and only a linear metric matrix is learned to properly measure the distance in this space to group similar examples together and dissimilar examples to be far apart ( Xing et al. , 2003 ; Weinberger & Saul , 2009 ; Davis et al. , 2007 ) . More recently the ideas of distance metric learning and representation learning have been combined in applications like face verification , where deep convolutional neural networks are learned to map similar images to similar representation vectors ( Chopra et al. , 2005 ; Hu et al. , 2014 ; Sun et al. , 2014 ) . In this paper , we focus on representation and similarity metric learning for graphs , and our graph matching model goes one step beyond the typical representation learning methods by modeling the cross-graph matchings . Siamese Networks Siamese networks ( Bromley et al. , 1994 ; Baldi & Chauvin , 1993 ) are a family of neural network models for visual similarity learning . These models typically consist of two networks with shared parameters applied to two input images independently to compute representations , a small network is then used to fuse these representations and compute a similarity score . They can be thought of as learning both the representations and the similarity metric . Siamese networks have achieved great success in many visual recognition and verification tasks ( Bromley et al. , 1994 ; Baldi & Chauvin , 1993 ; Koch et al. , 2015 ; Bertinetto et al. , 2016 ; Zagoruyko & Komodakis , 2015 ) . In the experiments we adapt Siamese networks to handle graphs , but found our graph matching networks to be more powerful as they do cross-graph computations and therefore fuse information from both graphs early in the computation process . Independent of our work , recently ( Shyam et al. , 2017 ) proposed a cross-example attention model for visual similarity as an alternative to Siamese networks based on similar motivations and achieved good results . 3 DEEP GRAPH SIMILARITY LEARNING . Given two graphs G1 = ( V1 , E1 ) and G2 = ( V2 , E2 ) , we want a model that produces the similarity score s ( G1 , G2 ) between them . Each graph G = ( V , E ) is represented as sets of nodes V and edges E , optionally each node i ∈ V can be associated with a feature vector xi , and each edge ( i , j ) ∈ E associated with a feature vector xij . These features can represent , e.g . type of a node , direction of an edge , etc . If a node or an edge does not have any associated features , we set the corresponding vector to a constant vector of 1s . We propose two models for graph similarity learning : a model based on standard GNNs for learning graph embeddings , and the new and more powerful GMNs . The two models are illustrated in Figure 2 .

Summary: The authors present two methods for learning a similarity score between pairs of graphs. They first is to use a shared GNN for each graph to produce independent graph embeddings on which a similarity score is computed. The authors improve this model using pairs of graphs as input and utilizing a cross-graph attention-mechanism in combination with graph convolution. The proposed approach is evaluated on synthetic and real world tasks. It is clearly shown that the proposed approach of cross-graph attention is useful for the given task (at the cost of extra computation).