Implementation of Graph Convolutional Networks in TensorFlow
We present a scalable approach for semi-supervised learning on graph-structured data that is based on an efficient variant of convolutional neural networks which operate directly on graphs. We motivate the choice of our convolutional architecture via a localized first-order approximation of spectral graph convolutions. Our model scales linearly in the number of graph edges and learns hidden layer representations that encode both local graph structure and features of nodes. In a number of experiments on citation networks and on a knowledge graph dataset we demonstrate that our approach outperforms related methods by a significant margin.READ FULL TEXT VIEW PDF
Graph convolutional networks(GCNs) have become the most popular approach...
Graph convolutional neural networks (GCNs) have recently demonstrated
We propose a novel spectral convolutional neural network (CNN) model on ...
Graph convolutional networks (GCNs) have shown promising results in
Graph convolution operator of the GCN model is originally motivated from...
Graph Convolutional Networks (GCNs) have proven to be successful tools f...
Graph convolutional networks (GCN) have been recently applied to
Implementation of Graph Convolutional Networks in TensorFlow
Graph Convolutional Networks in PyTorch
Tensorflow implementation of Graph Convolutional Network
We consider the problem of classifying nodes (such as documents) in a graph (such as a citation network), where labels are only available for a small subset of nodes. This problem can be framed as graph-based semi-supervised learning, where label information is smoothed over the graph via some form of explicit graph-based regularization(Zhu et al., 2003; Zhou et al., 2004; Belkin et al., 2006; Weston et al., 2012)
, e.g. by using a graph Laplacian regularization term in the loss function:
Here, denotes the supervised loss w.r.t. the labeled part of the graph, can be a neural network-like differentiable function, is a weighing factor and
is a matrix of node feature vectors. denotes the unnormalized graph Laplacian of an undirected graph with nodes , edges , an adjacency matrix (binary or weighted) and a degree matrix . The formulation of Eq. 1 relies on the assumption that connected nodes in the graph are likely to share the same label. This assumption, however, might restrict modeling capacity, as graph edges need not necessarily encode node similarity, but could contain additional information.
In this work, we encode the graph structure directly using a neural network model and train on a supervised target for all nodes with labels, thereby avoiding explicit graph-based regularization in the loss function. Conditioning on the adjacency matrix of the graph will allow the model to distribute gradient information from the supervised loss and will enable it to learn representations of nodes both with and without labels.
Our contributions are two-fold. Firstly, we introduce a simple and well-behaved layer-wise propagation rule for neural network models which operate directly on graphs and show how it can be motivated from a first-order approximation of spectral graph convolutions (Hammond et al., 2011). Secondly, we demonstrate how this form of a graph-based neural network model can be used for fast and scalable semi-supervised classification of nodes in a graph. Experiments on a number of datasets demonstrate that our model compares favorably both in classification accuracy and efficiency (measured in wall-clock time) against state-of-the-art methods for semi-supervised learning.
In this section, we provide theoretical motivation for a specific graph-based neural network model that we will use in the rest of this paper. We consider a multi-layer Graph Convolutional Network (GCN) with the following layer-wise propagation rule:
Here, is the adjacency matrix of the undirected graph with added self-connections.
is the identity matrix,and is a layer-specific trainable weight matrix.
denotes an activation function, such as the. is the matrix of activations in the layer; . In the following, we show that the form of this propagation rule can be motivated111We provide an alternative interpretation of this propagation rule based on the Weisfeiler-Lehman algorithm (Weisfeiler & Lehmann, 1968) in Appendix A. via a first-order approximation of localized spectral filters on graphs (Hammond et al., 2011; Defferrard et al., 2016).
We consider spectral convolutions on graphs defined as the multiplication of a signal (a scalar for every node) with a filter parameterized by in the Fourier domain, i.e.:
is the matrix of eigenvectors of the normalized graph Laplacian
, with a diagonal matrix of its eigenvaluesand
being the graph Fourier transform of. We can understand as a function of the eigenvalues of , i.e. . Evaluating Eq. 3 is computationally expensive, as multiplication with the eigenvector matrix is . Furthermore, computing the eigendecomposition of in the first place might be prohibitively expensive for large graphs. To circumvent this problem, it was suggested in Hammond et al. (2011) that can be well-approximated by a truncated expansion in terms of Chebyshev polynomials up to order:
with a rescaled . denotes the largest eigenvalue of . is now a vector of Chebyshev coefficients. The Chebyshev polynomials are recursively defined as , with and . The reader is referred to Hammond et al. (2011) for an in-depth discussion of this approximation.
Going back to our definition of a convolution of a signal with a filter , we now have:
with ; as can easily be verified by noticing that . Note that this expression is now -localized since it is a -order polynomial in the Laplacian, i.e. it depends only on nodes that are at maximum steps away from the central node (-order neighborhood). The complexity of evaluating Eq. 5 is , i.e. linear in the number of edges. Defferrard et al. (2016) use this -localized convolution to define a convolutional neural network on graphs.
A neural network model based on graph convolutions can therefore be built by stacking multiple convolutional layers of the form of Eq. 5, each layer followed by a point-wise non-linearity. Now, imagine we limited the layer-wise convolution operation to (see Eq. 5), i.e. a function that is linear w.r.t. and therefore a linear function on the graph Laplacian spectrum.
In this way, we can still recover a rich class of convolutional filter functions by stacking multiple such layers, but we are not limited to the explicit parameterization given by, e.g., the Chebyshev polynomials. We intuitively expect that such a model can alleviate the problem of overfitting on local neighborhood structures for graphs with very wide node degree distributions, such as social networks, citation networks, knowledge graphs and many other real-world graph datasets. Additionally, for a fixed computational budget, this layer-wise linear formulation allows us to build deeper models, a practice that is known to improve modeling capacity on a number of domains (He et al., 2016).
In this linear formulation of a GCN we further approximate , as we can expect that neural network parameters will adapt to this change in scale during training. Under these approximations Eq. 5 simplifies to:
with two free parameters and . The filter parameters can be shared over the whole graph. Successive application of filters of this form then effectively convolve the -order neighborhood of a node, where is the number of successive filtering operations or convolutional layers in the neural network model.
In practice, it can be beneficial to constrain the number of parameters further to address overfitting and to minimize the number of operations (such as matrix multiplications) per layer. This leaves us with the following expression:
with a single parameter . Note that now has eigenvalues in the range . Repeated application of this operator can therefore lead to numerical instabilities and exploding/vanishing gradients when used in a deep neural network model. To alleviate this problem, we introduce the following renormalization trick: , with and .
We can generalize this definition to a signal with input channels (i.e. a -dimensional feature vector for every node) and filters or feature maps as follows:
where is now a matrix of filter parameters and is the convolved signal matrix. This filtering operation has complexity , as can be efficiently implemented as a product of a sparse matrix with a dense matrix.
Having introduced a simple, yet flexible model for efficient information propagation on graphs, we can return to the problem of semi-supervised node classification. As outlined in the introduction, we can relax certain assumptions typically made in graph-based semi-supervised learning by conditioning our model both on the data and on the adjacency matrix of the underlying graph structure. We expect this setting to be especially powerful in scenarios where the adjacency matrix contains information not present in the data , such as citation links between documents in a citation network or relations in a knowledge graph. The overall model, a multi-layer GCN for semi-supervised learning, is schematically depicted in Figure 1.
In the following, we consider a two-layer GCN for semi-supervised node classification on a graph with a symmetric adjacency matrix (binary or weighted). We first calculate in a pre-processing step. Our forward model then takes the simple form:
Here, is an input-to-hidden weight matrix for a hidden layer with feature maps. is a hidden-to-output weight matrix. The softmax activation function, defined as with , is applied row-wise. For semi-supervised multi-class classification, we then evaluate the cross-entropy error over all labeled examples:
where is the set of node indices that have labels.
The neural network weights and are trained using gradient descent. In this work, we perform batch gradient descent using the full dataset for every training iteration, which is a viable option as long as datasets fit in memory. Using a sparse representation for , memory requirement is , i.e. linear in the number of edges. Stochasticity in the training process is introduced via dropout (Srivastava et al., 2014)
. We leave memory-efficient extensions with mini-batch stochastic gradient descent for future work.
In practice, we make use of TensorFlow(Abadi et al., 2015) for an efficient GPU-based implementation222Code to reproduce our experiments is available at https://github.com/tkipf/gcn. of Eq. 9 using sparse-dense matrix multiplications. The computational complexity of evaluating Eq. 9 is then , i.e. linear in the number of graph edges.
Our model draws inspiration both from the field of graph-based semi-supervised learning and from recent work on neural networks that operate on graphs. In what follows, we provide a brief overview on related work in both fields.
A large number of approaches for semi-supervised learning using graph representations have been proposed in recent years, most of which fall into two broad categories: methods that use some form of explicit graph Laplacian regularization and graph embedding-based approaches. Prominent examples for graph Laplacian regularization include label propagation (Zhu et al., 2003), manifold regularization (Belkin et al., 2006) and deep semi-supervised embedding (Weston et al., 2012).
Recently, attention has shifted to models that learn graph embeddings with methods inspired by the skip-gram model (Mikolov et al., 2013). DeepWalk (Perozzi et al., 2014) learns embeddings via the prediction of the local neighborhood of nodes, sampled from random walks on the graph. LINE (Tang et al., 2015) and node2vec (Grover & Leskovec, 2016) extend DeepWalk with more sophisticated random walk or breadth-first search schemes. For all these methods, however, a multi-step pipeline including random walk generation and semi-supervised training is required where each step has to be optimized separately. Planetoid (Yang et al., 2016) alleviates this by injecting label information in the process of learning embeddings.
as a form of recurrent neural network. Their framework requires the repeated application of contraction maps as propagation functions until node representations reach a stable fixed point. This restriction was later alleviated inLi et al. (2016) by introducing modern practices for recurrent neural network training to the original graph neural network framework. Duvenaud et al. (2015) introduced a convolution-like propagation rule on graphs and methods for graph-level classification. Their approach requires to learn node degree-specific weight matrices which does not scale to large graphs with wide node degree distributions. Our model instead uses a single weight matrix per layer and deals with varying node degrees through an appropriate normalization of the adjacency matrix (see Section 3.1).
A related approach to node classification with a graph-based neural network was recently introduced in Atwood & Towsley (2016). They report complexity, limiting the range of possible applications. In a different yet related model, Niepert et al. (2016) convert graphs locally into sequences that are fed into a conventional 1D convolutional neural network, which requires the definition of a node ordering in a pre-processing step.
Our method is based on spectral graph convolutional neural networks, introduced in Bruna et al. (2014) and later extended by Defferrard et al. (2016) with fast localized convolutions. In contrast to these works, we consider here the task of transductive node classification within networks of significantly larger scale. We show that in this setting, a number of simplifications (see Section 2.2) can be introduced to the original frameworks of Bruna et al. (2014) and Defferrard et al. (2016) that improve scalability and classification performance in large-scale networks.
We test our model in a number of experiments: semi-supervised document classification in citation networks, semi-supervised entity classification in a bipartite graph extracted from a knowledge graph, an evaluation of various graph propagation models and a run-time analysis on random graphs.
We closely follow the experimental setup in Yang et al. (2016). Dataset statistics are summarized in Table 1. In the citation network datasets—Citeseer, Cora and Pubmed (Sen et al., 2008)—nodes are documents and edges are citation links. Label rate denotes the number of labeled nodes that are used for training divided by the total number of nodes in each dataset. NELL (Carlson et al., 2010; Yang et al., 2016) is a bipartite graph dataset extracted from a knowledge graph with 55,864 relation nodes and 9,891 entity nodes.
We consider three citation network datasets: Citeseer, Cora and Pubmed (Sen et al., 2008). The datasets contain sparse bag-of-words feature vectors for each document and a list of citation links between documents. We treat the citation links as (undirected) edges and construct a binary, symmetric adjacency matrix . Each document has a class label. For training, we only use 20 labels per class, but all feature vectors.
NELL is a dataset extracted from the knowledge graph introduced in (Carlson et al., 2010). A knowledge graph is a set of entities connected with directed, labeled edges (relations). We follow the pre-processing scheme as described in Yang et al. (2016). We assign separate relation nodes and for each entity pair as and . Entity nodes are described by sparse feature vectors. We extend the number of features in NELL by assigning a unique one-hot representation for every relation node, effectively resulting in a 61,278-dim sparse feature vector per node. The semi-supervised task here considers the extreme case of only a single labeled example per class in the training set. We construct a binary, symmetric adjacency matrix from this graph by setting entries , if one or more edges are present between nodes and .
We simulate random graph datasets of various sizes for experiments where we measure training time per epoch. For a dataset withnodes we create a random graph assigning edges uniformly at random. We take the identity matrix as input feature matrix , thereby implicitly taking a featureless approach where the model is only informed about the identity of each node, specified by a unique one-hot vector. We add dummy labels for every node.
Unless otherwise noted, we train a two-layer GCN as described in Section 3.1 and evaluate prediction accuracy on a test set of 1,000 labeled examples. We provide additional experiments using deeper models with up to 10 layers in Appendix B. We choose the same dataset splits as in Yang et al. (2016)
with an additional validation set of 500 labeled examples for hyperparameter optimization (dropout rate for all layers, L2 regularization factor for the first GCN layer and number of hidden units). We do not use the validation set labels for training.
For the citation network datasets, we optimize hyperparameters on Cora only and use the same set of parameters for Citeseer and Pubmed. We train all models for a maximum of 200 epochs (training iterations) using Adam (Kingma & Ba, 2015) with a learning rate of and early stopping with a window size of , i.e. we stop training if the validation loss does not decrease for 10 consecutive epochs. We initialize weights using the initialization described in Glorot & Bengio (2010) and accordingly (row-)normalize input feature vectors. On the random graph datasets, we use a hidden layer size of 32 units and omit regularization (i.e. neither dropout nor L2 regularization).
We compare against the same baseline methods as in Yang et al. (2016), i.e. label propagation (LP) (Zhu et al., 2003), semi-supervised embedding (SemiEmb) (Weston et al., 2012), manifold regularization (ManiReg) (Belkin et al., 2006) and skip-gram based graph embeddings (DeepWalk) (Perozzi et al., 2014). We omit TSVM (Joachims, 1999), as it does not scale to the large number of classes in one of our datasets.
We further compare against the iterative classification algorithm (ICA) proposed in Lu & Getoor (2003)
in conjunction with two logistic regression classifiers, one for local node features alone and one for relational classification using local features and an aggregation operator as described inSen et al. (2008). We first train the local classifier using all labeled training set nodes and use it to bootstrap class labels of unlabeled nodes for relational classifier training. We run iterative classification (relational classifier) with a random node ordering for 10 iterations on all unlabeled nodes (bootstrapped using the local classifier). L2 regularization parameter and aggregation operator (count vs. prop, see Sen et al. (2008)) are chosen based on validation set performance for each dataset separately.
Lastly, we compare against Planetoid (Yang et al., 2016), where we always choose their best-performing model variant (transductive vs. inductive) as a baseline.
Results are summarized in Table 2. Reported numbers denote classification accuracy in percent. For ICA, we report the mean accuracy of 100 runs with random node orderings. Results for all other baseline methods are taken from the Planetoid paper (Yang et al., 2016). Planetoid* denotes the best model for the respective dataset out of the variants presented in their paper.
|GCN (this paper)||(7s)||(4s)||(38s)||(48s)|
|GCN (rand. splits)|
We further report wall-clock training time in seconds until convergence (in brackets) for our method (incl. evaluation of validation error) and for Planetoid. For the latter, we used an implementation provided by the authors333https://github.com/kimiyoung/planetoid and trained on the same hardware (with GPU) as our GCN model. We trained and tested our model on the same dataset splits as in Yang et al. (2016) and report mean accuracy of 100 runs with random weight initializations. We used the following sets of hyperparameters for Citeseer, Cora and Pubmed: 0.5 (dropout rate), (L2 regularization) and (number of hidden units); and for NELL: 0.1 (dropout rate), (L2 regularization) and (number of hidden units).
We compare different variants of our proposed per-layer propagation model on the citation network datasets. We follow the experimental set-up described in the previous section. Results are summarized in Table 3. The propagation model of our original GCN model is denoted by renormalization trick (in bold). In all other cases, the propagation model of both neural network layers is replaced with the model specified under propagation model. Reported numbers denote mean classification accuracy for 100 repeated runs with random weight matrix initializations. In case of multiple variables per layer, we impose L2 regularization on all weight matrices of the first layer.
Here, we report results for the mean training time per epoch (forward pass, cross-entropy calculation, backward pass) for 100 epochs on simulated random graphs, measured in seconds wall-clock time. See Section 5.1 for a detailed description of the random graph dataset used in these experiments. We compare results on a GPU and on a CPU-only implementation444Hardware used: 16-core Intel R - Xeon R - CPU E5-2640 v3 @ 2.60GHz, GeForce R - GTX TITAN X in TensorFlow (Abadi et al., 2015). Figure 2 summarizes the results.
In the experiments demonstrated here, our method for semi-supervised node classification outperforms recent related methods by a significant margin. Methods based on graph-Laplacian regularization (Zhu et al., 2003; Belkin et al., 2006; Weston et al., 2012) are most likely limited due to their assumption that edges encode mere similarity of nodes. Skip-gram based methods on the other hand are limited by the fact that they are based on a multi-step pipeline which is difficult to optimize. Our proposed model can overcome both limitations, while still comparing favorably in terms of efficiency (measured in wall-clock time) to related methods. Propagation of feature information from neighboring nodes in every layer improves classification performance in comparison to methods like ICA (Lu & Getoor, 2003), where only label information is aggregated.
We have further demonstrated that the proposed renormalized propagation model (Eq. 8) offers both improved efficiency (fewer parameters and operations, such as multiplication or addition) and better predictive performance on a number of datasets compared to a naïve -order model (Eq. 6) or higher-order graph convolutional models using Chebyshev polynomials (Eq. 5).
Here, we describe several limitations of our current model and outline how these might be overcome in future work.
In the current setup with full-batch gradient descent, memory requirement grows linearly in the size of the dataset. We have shown that for large graphs that do not fit in GPU memory, training on CPU can still be a viable option. Mini-batch stochastic gradient descent can alleviate this issue. The procedure of generating mini-batches, however, should take into account the number of layers in the GCN model, as the -order neighborhood for a GCN with layers has to be stored in memory for an exact procedure. For very large and densely connected graph datasets, further approximations might be necessary.
Our framework currently does not naturally support edge features and is limited to undirected graphs (weighted or unweighted). Results on NELL however show that it is possible to handle both directed edges and edge features by representing the original directed graph as an undirected bipartite graph with additional nodes that represent edges in the original graph (see Section 5.1 for details).
Through the approximations introduced in Section 2, we implicitly assume locality (dependence on the -order neighborhood for a GCN with layers) and equal importance of self-connections vs. edges to neighboring nodes. For some datasets, however, it might be beneficial to introduce a trade-off parameter in the definition of :
This parameter now plays a similar role as the trade-off parameter between supervised and unsupervised loss in the typical semi-supervised setting (see Eq. 1). Here, however, it can be learned via gradient descent.
We have introduced a novel approach for semi-supervised classification on graph-structured data. Our GCN model uses an efficient layer-wise propagation rule that is based on a first-order approximation of spectral convolutions on graphs. Experiments on a number of network datasets suggest that the proposed GCN model is capable of encoding both graph structure and node features in a way useful for semi-supervised classification. In this setting, our model outperforms several recently proposed methods by a significant margin, while being computationally efficient.
We would like to thank Christos Louizos, Taco Cohen, Joan Bruna, Zhilin Yang, Dave Herman, Pramod Sinha and Abdul-Saboor Sheikh for helpful discussions. This research was funded by SAP.
TensorFlow: Large-scale machine learning on heterogeneous systems, 2015.
Transductive inference for text classification using support vector machines.In International Conference on Machine Learning (ICML), volume 99, pp. 200–209, 1999.
A neural network model for graph-structured data should ideally be able to learn representations of nodes in a graph, taking both the graph structure and feature description of nodes into account. A well-studied framework for the unique assignment of node labels given a graph and (optionally) discrete initial node labels is provided by the 1-dim Weisfeiler-Lehman (WL-1) algorithm (Weisfeiler & Lehmann, 1968):
Here, denotes the coloring (label assignment) of node (at iteration ) and is its set of neighboring node indices (irrespective of whether the graph includes self-connections for every node or not). is a hash function. For an in-depth mathematical discussion of the WL-1 algorithm see, e.g., Douglas (2011).
We can replace the hash function in Algorithm 1 with a neural network layer-like differentiable function with trainable parameters as follows:
where is an appropriately chosen normalization constant for the edge . Further, we can take now to be a vector of activations of node in the neural network layer. is a layer-specific weight matrix and denotes a differentiable, non-linear activation function.
By choosing , where denotes the degree of node , we recover the propagation rule of our Graph Convolutional Network (GCN) model in vector form (see Eq. 2)555Note that we here implicitly assume that self-connections have already been added to every node in the graph (for a clutter-free notation)..
This—loosely speaking—allows us to interpret our GCN model as a differentiable and parameterized generalization of the 1-dim Weisfeiler-Lehman algorithm on graphs.
From the analogy with the Weisfeiler-Lehman algorithm, we can understand that even an untrained GCN model with random weights can serve as a powerful feature extractor for nodes in a graph. As an example, consider the following 3-layer GCN model:
We apply this model on Zachary’s karate club network (Zachary, 1977). This graph contains 34 nodes, connected by 154 (undirected and unweighted) edges. Every node is labeled by one of four classes, obtained via modularity-based clustering (Brandes et al., 2008). See Figure 2(a) for an illustration.
We take a featureless approach by setting , where is the by identity matrix. is the number of nodes in the graph. Note that nodes are randomly ordered (i.e. ordering contains no information). Furthermore, we choose a hidden layer dimensionality666We originally experimented with a hidden layer dimensionality of (i.e. same as output layer), but observed that a dimensionality of resulted in less frequent saturation of units and therefore visually more pleasing results. of and a two-dimensional output (so that the output can immediately be visualized in a 2-dim plot).
On this simple example of a GCN applied to the karate club network it is interesting to observe how embeddings react during training on a semi-supervised classification task. Such a visualization (see Figure 4
) provides insights into how the GCN model can make use of the graph structure (and of features extracted from the graph structure at later layers) to learn embeddings that are useful for a classification task.
We consider the following semi-supervised learning setup: we add a softmax layer on top of our model (Eq.13) and train using only a single labeled example per class (i.e. a total number of 4 labeled nodes). We train for 300 training iterations using Adam (Kingma & Ba, 2015) with a learning rate of on a cross-entropy loss.
Figure 4 shows the evolution of node embeddings over a number of training iterations. The model succeeds in linearly separating the communities based on minimal supervision and the graph structure alone. A video of the full training process can be found on our website777http://tkipf.github.io/graph-convolutional-networks/.
In these experiments, we investigate the influence of model depth (number of layers) on classification performance. We report results on a 5-fold cross-validation experiment on the Cora, Citeseer and Pubmed datasets (Sen et al., 2008) using all labels. In addition to the standard GCN model (Eq. 2
), we report results on a model variant where we use residual connections(He et al., 2016) between hidden layers to facilitate training of deeper models by enabling the model to carry over information from the previous layer’s input:
On each cross-validation split, we train for 400 epochs (without early stopping) using the Adam optimizer (Kingma & Ba, 2015) with a learning rate of . Other hyperparameters are chosen as follows: 0.5 (dropout rate, first and last layer), (L2 regularization, first layer), 16 (number of units for each hidden layer) and 0.01 (learning rate). Results are summarized in Figure 5.
For the datasets considered here, best results are obtained with a 2- or 3-layer model. We observe that for models deeper than 7 layers, training without the use of residual connections can become difficult, as the effective context size for each node increases by the size of its -order neighborhood (for a model with layers) with each additional layer. Furthermore, overfitting can become an issue as the number of parameters increases with model depth.