The Graph Neural Network Model
local graph
Chapter 5 — The Graph Neural Network Model
Section titled “Chapter 5 — The Graph Neural Network Model”The first part of this book discussed approaches for learning low-dimensional embeddings of the nodes in a graph. The node embedding approaches we discussed used a shallow embedding approach to generate representations of nodes, where we simply optimized a unique embedding vector for each node. In this chapter, we turn our focus to more complex encoder models. We will introduce the graph neural network (GNN) formalism, which is a general framework for defining deep neural networks on graph data. The key idea is that we want to generate representations of nodes that actually depend on the structure of the graph, as well as any feature information we might have.
The primary challenge in developing complex encoders for graph-structured data is that our usual deep learning toolbox does not apply. For example, convolutional neural networks (CNNs) are well defined only over grid-structured inputs (e.g., images), while recurrent neural networks (RNNs) are well defined only over sequences (e.g., text). To define a deep neural network over general graphs, we need to define a new kind of deep learning architecture.
Permutation invariance and equivariance One reasonable idea for defining a deep neural network over graphs would be to simply use the adjacency matrix as input to a deep neural network. For example, to generate an embedding of an entire graph we could simply flatten the adjacency matrix and feed the result to a multi-layer perceptron (MLP):
where denotes a row of the adjacency matrix and we use to denote vector concatenation.
The issue with this approach is that it depends on the arbitrary ordering of nodes that we used in the adjacency matrix. In other words, such a model is not permutation invariant, and a key desideratum for designing neural networks over graphs is that they should permutation invariant (or equivariant). In mathematical terms, any function that takes an adjacency matrix as input should ideally satisfy one of the two following properties:
where is a permutation matrix. Permutation invariance means that the function does not depend on the arbitrary ordering of the rows/columns in the adjacency matrix, while permutation equivariance means that the output of is permuted in an consistent way when we permute the adjacency matrix. (The shallow encoders we discussed in Part I are an example of permutation equivariant functions.) Ensuring invariance or equivariance is a key challenge when we are learning over graphs, and we will revisit issues surrounding permutation equivariance and invariance often in the ensuing chapters.
5.1 Neural Message Passing
Section titled “5.1 Neural Message Passing”The basic GNN model can be motivated in a variety of ways. The same fundamental GNN model has been derived as a generalization of convolutions to non-Euclidean data [Bruna et al., 2014], as a differentiable variant of belief propagation [Dai et al., 2016], as well as by analogy to classic graph isomorphism tests [Hamilton et al., 2017b]. Regardless of the motivation, the defining feature of a GNN is that it uses a form of neural message passing in which vector messages are exchanged between nodes and updated using neural networks [Gilmer et al., 2017].
In the rest of this chapter, we will detail the foundations of this neural message passing framework. We will focus on the message passing framework itself and defer discussions of training and optimizing GNN models to Chapter 6. The bulk of this chapter will describe how we can take an input graph , along with a set of node features , and use this information to generate node embeddings . However, we will also discuss how the GNN framework can be used to generate embeddings for subgraphs and entire graphs.
5.1.1 Overview of the Message Passing Framework
Section titled “5.1.1 Overview of the Message Passing Framework”During each message-passing iteration in a GNN, a hidden embedding corresponding to each node is updated according to information aggregated from ’s graph neighborhood (Figure 5.1). This message-passing update can be expressed as follows:
where and are arbitrary differentiable functions (i.e., neural networks) and is the “message” that is aggregated from ’s graph neighborhood . We use superscripts to distinguish the embeddings and functions at different iterations of message passing.1
At each iteration of the GNN, the function takes as input the set of embeddings of the nodes in ’s graph neighborhood and generates a message based on this aggregated neighborhood information. The update function then combines the message with the previous embedding of node to generate the updated embedding . The initial embeddings at are set to the input features for all the nodes, i.e., . After running iterations of the GNN message passing, we can use the output of the final layer to define the embeddings for each node, i.e.,
Note that since the function takes a set as input, GNNs defined in this way are permutation equivariant by design.
graph LR
subgraph IG["Input Graph (target node A)"]
direction LR
A((A)) --- B((B))
A --- C((C))
A --- D((D))
B --- C
C --- E((E))
C --- F((F))
E --- F
end
subgraph CT["Two-layer computation graph"]
direction RL
AGG["AGGREGATE"] --> A1((A))
B1((B)) --> AGG
C1((C)) --> AGG
D1((D)) -.-> AGG
aB[" "] --> B1
A2((A)) --> aB
C2((C)) --> aB
aC[" "] --> C1
A3((A)) --> aC
B3((B)) --> aC
E3((E)) --> aC
F3((F)) --> aC
aD[" "] --> D1
A4((A)) --> aD
end
[!visual-conversion] Both panels are transcribed: the input graph’s 6 nodes and 7 edges, and the two-layer computation tree (A ← AGGREGATE ← {B, C, D}; B ← {A, C}; C ← {A, B, E, F}; D ← {A}). Blank boxes stand for the print’s unlabelled grey aggregation squares. Lost: node shading, and the dotted line drawn from D in the print.
Figure 5.1: Overview of how a single node aggregates messages from its local neighborhood. The model aggregates messages from A’s local graph neighbors (i.e., B, C, and D), and in turn, the messages coming from these neighbors are based on information aggregated from their respective neighborhoods, and so on. This visualization shows a two-layer version of a message-passing model. Notice that the computation graph of the GNN forms a tree structure by unfolding the neighborhood around the target node.
Node features Note that unlike the shallow embedding methods discussed in Part I of this book, the GNN framework requires that we have node features as input to the model. In many graphs, we will have rich node features to use (e.g., gene expression features in biological networks or text features in social networks). However, in cases where no node features are available, there are still several options. One option is to use node statistics—such as those introduced in Section 2.1—to define features. Another popular approach is to use identity features, where we associate each node with a one-hot indicator feature, which uniquely identifies that node.2
5.1.2 Motivations and Intuitions
Section titled “5.1.2 Motivations and Intuitions”The basic intuition behind the GNN message-passing framework is straightforward: at each iteration, every node aggregates information from its local neighborhood, and as these iterations progress each node embedding contains more and more information from further reaches of the graph. To be precise: after the first iteration (), every node embedding contains information from its 1-hop neighborhood, i.e., every node embedding contains information about the features of its immediate graph neighbors, which can be reached by a path of length 1 in the graph; after the second iteration () every node embedding contains information from its 2-hop neighborhood; and, in general, after iterations every node embedding contains information about its -hop neighborhood.
But what kind of “information” do these node embeddings actually encode? Generally, this information comes in two forms. On the one hand, there is structural information about the graph. For example, after iterations of GNN message passing, the embedding of node might encode information about the degrees of all the nodes in ’s -hop neighborhood. This structural information can be useful for many tasks. For instance, when analyzing molecular graphs, we can use degree information to infer atom types and different structural motifs, such as benzene rings.
In addition to structural information, the other key kind of information captured by GNN node embedding is feature-based. After iterations of GNN message passing, the embeddings for each node also encode information about all the features in their -hop neighborhood. This local feature-aggregation behavior of GNNs is analogous to the behavior of the convolutional kernels in CNNs. However, whereas CNNs aggregate feature information from spatially-defined patches in an image, GNNs aggregate information based on local graph neighborhoods. We will explore the connection between GNNs and convolutions in more detail in Chapter 7.
5.1.3 The Basic GNN
Section titled “5.1.3 The Basic GNN”So far, we have discussed the GNN framework in a relatively abstract fashion as a series of message-passing iterations using and functions (Equation (5.4)). In order to translate the abstract GNN framework defined in Equation (5.4) into something we can implement, we must give concrete instantiations to these and functions. We begin here with the most basic GNN framework, which is a simplification of the original GNN models proposed by Merkwirth and Lengauer [2005] and Scarselli et al. [2009].
The basic GNN message passing is defined as
where are trainable parameter matrices and denotes an element-wise nonlinearity (e.g., a tanh or ReLU). The bias term is often omitted for notational simplicity, but including the bias term can be important to achieve strong performance. In this equation—and throughout the remainder of the book—we use superscripts to differentiate parameters, embeddings, and dimensionalities in different layers of the GNN.
The message passing in the basic GNN framework is analogous to a standard multi-layer perceptron (MLP) or Elman-style recurrent neural network, i.e., Elman RNN [Elman, 1990], as it relies on linear operations followed by a single elementwise nonlinearity. We first sum the messages incoming from the neighbors; then, we combine the neighborhood information with the node’s previous embedding using a linear combination; and finally, we apply an elementwise nonlinearity.
We can equivalently define the basic GNN through the and functions:
where we recall that we use
as a shorthand to denote the message that has been aggregated from ’s graph neighborhood. Note also that we ommitted the superscript denoting the iteration in the above equations, which we will often do for notational brevity.3
Node vs. graph-level equations In the description of the basic GNN model above, we defined the core message-passing operations at the node level. We will use this convention for the bulk of this chapter and this book as a whole. However, it is important to note that many GNNs can also be succinctly defined using graph-level equations. In the case of a basic GNN, we can write the graph-level definition of the model as follows:
where denotes the matrix of node representations at layer in the GNN (with each node corresponding to a row in the matrix), is the graph adjacency matrix, and we have omitted the bias term for notational simplicity. While this graph-level representation is not easily applicable to all GNN models—such as the attention-based models we discuss below—it is often more succinct and also highlights how many GNNs can be efficiently implemented using a small number of sparse matrix operations.
5.1.4 Message Passing with Self-Loops
Section titled “5.1.4 Message Passing with Self-Loops”As a simplification of the neural message passing approach, it is common to add self-loops to the input graph and omit the explicit update step. In this approach we define the message passing simply as
where now the aggregation is taken over the set , i.e., the node’s neighbors as well as the node itself. The benefit of this approach is that we no longer need to define an explicit update function, as the update is implicitly defined through the aggregation method. Simplifying the message passing in this way can often alleviate overfitting, but it also severely limits the expressivity of the GNN, as the information coming the node’s neighbors cannot be differentiated from the information from the node itself.
In the case of the basic GNN, adding self-loops is equivalent to sharing parameters between the and matrices, which gives the following graph-level update:
In the following chapters we will refer to this as the self-loop GNN approach.
5.2 Generalized Neighborhood Aggregation
Section titled “5.2 Generalized Neighborhood Aggregation”The basic GNN model outlined in Equation (5.7) can achieve strong performance, and its theoretical capacity is well-understood (see Chapter 7). However, just like a simple MLP or Elman RNN, the basic GNN can be improved upon and generalized in many ways. Here, we discuss how the operator can be generalized and improved upon, with the following section (Section 5.3) providing an analogous discussion for the operation.
5.2.1 Neighborhood Normalization
Section titled “5.2.1 Neighborhood Normalization”The most basic neighborhood aggregation operation (Equation (5.8)) simply takes the sum of the neighbor embeddings. One issue with this approach is that it can be unstable and highly sensitive to node degrees. For instance, suppose node has as many neighbors as node (i.e., a much higher degree), then we would reasonably expect that (for any reasonable vector norm ). This drastic difference in magnitude can lead to numerical instabilities as well as difficulties for optimization.
One solution to this problem is to simply normalize the aggregation operation based upon the degrees of the nodes involved. The simplest approach is to just take an average rather than sum:
but researchers have also found success with other normalization factors, such as the following symmetric normalization employed by Kipf and Welling [2016a]:
For example, in a citation graph—the kind of data that Kipf and Welling [2016a] analyzed—information from very high-degree nodes (i.e., papers that are cited many times) may not be very useful for inferring community membership in the graph, since these papers can be cited thousands of times across diverse subfields. Symmetric normalization can also be motivated based on spectral graph theory. In particular, combining the symmetric-normalized aggregation (Equation (5.15)) along with the basic GNN update function (Equation (5.9)) results in a first-order approximation of a spectral graph convolution, and we expand on this connection in Chapter 7.
Graph Convolutional Networks (GCNs)
One of the most popular baseline graph neural network models—the graph convolutional network (GCN)—employs the symmetric-normalized aggregation as well as the self-loop update approach. The GCN model thus defines the message passing function as
This approach was first outlined by Kipf and Welling [2016a] and has proved to be one of the most popular and effective baseline GNN architectures.
To normalize or not to normalize? Proper normalization can be essential to achieve stable and strong performance when using a GNN. It is important to note, however, that normalization can also lead to a loss of information. For example, after normalization, it can be hard (or even impossible) to use the learned embeddings to distinguish between nodes of different degrees, and various other structural graph features can be obscured by normalization. In fact, a basic GNN using the normalized aggregation operator in Equation (5.14) is provably less powerful than the basic sum aggregator in Equation (5.8) (see Chapter 7). The use of normalization is thus an application-specific question. Usually, normalization is most helpful in tasks where node feature information is far more useful than structural information, or where there is a very wide range of node degrees that can lead to instabilities during optimization.
5.2.2 Set Aggregators
Section titled “5.2.2 Set Aggregators”Neighborhood normalization can be a useful tool to improve GNN performance, but can we do more to improve the operator? Is there perhaps something more sophisticated than just summing over the neighbor embeddings?
The neighborhood aggregation operation is fundamentally a set function. We are given a set of neighbor embeddings and must map this set to a single vector . The fact that is a set is in fact quite important: there is no natural ordering of a nodes’ neighbors, and any aggregation function we define must thus be permutation invariant.
Set Pooling
One principled approach to define an aggregation function is based on the theory of permutation invariant neural networks. For example, Zaheer et al. [2017] show that an aggregation function with the following form is a universal set function approximator:
where as usual we use to denote an arbitrarily deep multi-layer perceptron parameterized by some trainable parameters . In other words, the theoretical results in Zaheer et al. [2017] show that any permutation-invariant function that maps a set of embeddings to a single embedding can be approximated to an arbitrary accuracy by a model following Equation (5.17).
Note that the theory presented in Zaheer et al. [2017] employs a sum of the embeddings after applying the first MLP (as in Equation (5.17)). However, it is possible to replace the sum with an alternative reduction function, such as an element-wise maximum or minimum, as in Qi et al. [2017], and it is also common to combine models based on Equation (5.17) with the normalization approaches discussed in Section 5.2.1, as in the GraphSAGE-pool approach [Hamilton et al., 2017b].
Set pooling approaches based on Equation (5.17) often lead to small increases in performance, though they also introduce an increased risk of overfitting, depending on the depth of the MLPs used. If set pooling is used, it is common to use MLPs that have only a single hidden layer, since these models are sufficient to satisfy the theory, but are not so overparameterized so as to risk catastrophic overfitting.
Janossy Pooling
Set pooling approaches to neighborhood aggregation essentially just add extra layers of MLPs on top of the more basic aggregation architectures discussed in Section 5.1.3. This idea is simple, but is known to increase the theoretical capacity of GNNs. However, there is another alternative approach, termed Janossy pooling, that is also provably more powerful than simply taking a sum or mean of the neighbor embeddings [Murphy et al., 2018].
Recall that the challenge of neighborhood aggregation is that we must use a permutation-invariant function, since there is no natural ordering of a node’s neighbors. In the set pooling approach (Equation (5.17)), we achieved this permutation invariance by relying on a sum, mean, or element-wise max to reduce the set of embeddings to a single vector. We made the model more powerful by combining this reduction with feed-forward neural networks (i.e., MLPs). Janossy pooling employs a different approach entirely: instead of using a permutation-invariant reduction (e.g., a sum or mean), we apply a permutation-sensitive function and average the result over many possible permutations.
Let denote a permutation function that maps the set to a specific sequence . In other words, takes the unordered set of neighbor embeddings and places these embeddings in a sequence based on some arbitrary ordering. The Janossy pooling approach then performs neighborhood aggregation by
where denotes a set of permutations and is a permutation-sensitive function, e.g., a neural network that operates on sequences. In practice, is usually defined to be an LSTM [Hochreiter and Schmidhuber, 1997], since LSTMs are known to be a powerful neural network architecture for sequences.
If the set of permutations in Equation (5.18) is equal to all possible permutations, then the aggregator in Equation (5.18) is also a universal function approximator for sets, like Equation (5.17). However, summing over all possible permutations is generally intractable. Thus, in practice, Janossy pooling employs one of two approaches:
-
Sample a random subset of possible permutations during each application of the aggregator, and only sum over that random subset.
-
Employ a canonical ordering of the nodes in the neighborhood set, e.g., order the nodes in descending order according to their degree, with ties broken randomly.
Murphy et al. [2018] include a detailed discussion and empirical comparison of these two approaches, as well as other approximation techniques (e.g., truncating the length of sequence), and their results indicate that Janossy-style pooling can improve upon set pooling in a number of synthetic evaluation setups.
5.2.3 Neighborhood Attention
Section titled “5.2.3 Neighborhood Attention”In addition to more general forms of set aggregation, a popular strategy for improving the aggregation layer in GNNs is to apply attention [Bahdanau et al., 2015]. The basic idea is to assign an attention weight or importance to each neighbor, which is used to weigh this neighbor’s influence during the aggregation step. The first GNN model to apply this style of attention was Veličković et al. [2018]’s Graph Attention Network (GAT), which uses attention weights to define a weighted sum of the neighbors:
where denotes the attention on neighbor when we are aggregating information at node . In the original GAT paper, the attention weights are defined as
where is a trainable attention vector, is a trainable matrix, and denotes the concatenation operation.
The GAT-style attention computation is known to work well with graph data. However, in principle any standard attention model from the deep learning literature at large can be used [Bahdanau et al., 2015]. Popular variants of attention include the bilinear attention model
as well as variations of attention layers using MLPs, e.g.,
where the MLP is restricted to a scalar output.
In addition, while it is less common in the GNN literature, it is also possible to add multiple attention “heads,” in the style of the popular transformer architecture [Vaswani et al., 2017]. In this approach, one computes distinct attention weights , using independently parameterized attention layers. The messages aggregated using the different attention weights are then transformed and combined in the aggregation step, usually with a linear projection followed by a concatenation operation, e.g.,
where the attention weights for each of the attention heads can be computed using any of the above attention mechanisms.
Graph attention and transformers GNN models with multi-headed attention (Equation (5.23)) are closely related to the transformer architecture [Vaswani et al., 2017]. Transformers are a popular architecture for both natural language processing (NLP) and computer vision, and—in the case of NLP—they have been an important driver behind large state-of-the-art NLP systems, such as BERT [Devlin et al., 2018] and XLNet [Yang et al., 2019]. The basic idea behind transformers is to define neural network layers entirely based on the attention operation. At each layer in a transformer, a new hidden representation is generated for every position in the input data (e.g., every word in a sentence) by using multiple attention heads to compute attention weights between all pairs of positions in the input, which are then aggregated with weighted sums based on these attention weights (in a manner analogous to Equation (5.23)). In fact, the basic transformer layer is exactly equivalent to a GNN layer using multi-headed attention (i.e., Equation (5.23)) if we assume that the GNN receives a fully connected graph as input.
This connection between GNNs and transformers has been exploited in numerous works. For example, one implementation strategy for designing GNNs is to simply start with a transformer model and then apply a binary adjacency mask on the attention layer to ensure that information is only aggregated between nodes that are actually connected in the graph. This style of GNN implementation can benefit from the numerous well-engineered libraries for transformer architectures that exist. However, a downside of this approach is that transformers must compute the pairwise attention between all positions/nodes in the input, which leads to a quadratic time complexity to aggregate messages for all nodes in the graph, compared to a time complexity for a more standard GNN implementation.
Adding attention is a useful strategy for increasing the representational capacity of a GNN model, especially in cases where you have prior knowledge to indicate that some neighbors might be more informative than others. For example, consider the case of classifying papers into topical categories based on citation networks. Often there are papers that span topical boundaries, or that are highly cited across various different fields. Ideally, an attention-based GNN would learn to ignore these papers in the neural message passing, as such promiscuous neighbors would likely be uninformative when trying to identify the topical category of a particular node. In Chapter 7, we will discuss how attention can influence the inductive bias of GNNs from a signal processing perspective.
5.3 Generalized Update Methods
Section titled “5.3 Generalized Update Methods”The operator in GNN models has generally received the most attention from researchers—in terms of proposing novel architectures and variations. This was especially the case after the introduction of the GraphSAGE framework, which introduced the idea of generalized neighborhood aggregation [Hamilton et al., 2017b]. However, GNN message passing involves two key steps: aggregation and updating, and in many ways the operator plays an equally important role in defining the power and inductive bias of the GNN model.
So far, we have seen the basic GNN approach—where the update operation involves a linear combination of the node’s current embedding with the message from its neighbors—as well as the self-loop approach, which simply involves adding a self-loop to the graph before performing neighborhood aggregation. In this section, we turn our attention to more diverse generalizations of the operator.
Over-smoothing and neighborhood influence One common issue with GNNs—which generalized update methods can help to address—is known as over-smoothing. The essential idea of over-smoothing is that after several iterations of GNN message passing, the representations for all the nodes in the graph can become very similar to one another. This tendency is especially common in basic GNN models and models that employ the self-loop update approach. Over-smoothing is problematic because it makes it impossible to build deeper GNN models—which leverage longer-term dependencies in the graph—since these deep GNN models tend to just generate over-smoothed embeddings.
This issue of over-smoothing in GNNs can be formalized by defining the influence of each node’s input feature on the final layer embedding of all the other nodes in the graph, i.e, , . In particular, for any pair of nodes and we can quantify the influence of node on node in the GNN by examining the magnitude of the corresponding Jacobian matrix [Xu et al., 2018]:
where is a vector of all ones. The value uses the sum of the entries in the Jacobian matrix as a measure of how much the initial embedding of node influences the final embedding of node in the GNN.
Given this definition of influence, Xu et al. [2018] prove the following:
Theorem 5.1 For any GNN model using a self-loop update approach and an aggregation function of the form
where is an arbitrary differentiable normalization function, we have that
where denotes the probability of visiting node on a length- random walk starting from node .
This theorem is a direct consequence of Theorem 1 in Xu et al. [2018]. It states that when we are using a -layer GCN-style model, the influence of node and node is proportional the probability of reaching node on a -step random walk starting from node . An important consequence of this, however, is that as the influence of every node approaches the stationary distribution of random walks over the graph, meaning that local neighborhood information is lost. Moreover, in many real-world graphs—which contain high-degree nodes and resemble so-called “expander” graphs—it only takes steps for the random walk starting from any node to converge to an almost-uniform distribution [Hoory et al., 2006].
Theorem 5.1 applies directly to models using a self-loop update approach, but the result can also be extended in asympotic sense for the basic GNN update (i.e., Equation (5.9)) as long as at each layer . Thus, when using simple GNN models—and especially those with the self-loop update approach—building deeper models can actually hurt performance. As more layers are added we lose information about local neighborhood structures and our learned embeddings become over-smoothed, approaching an almost-uniform distribution.
5.3.1 Concatenation and Skip-Connections
Section titled “5.3.1 Concatenation and Skip-Connections”As discussed above, over-smoothing is a core issue in GNNs. Over-smoothing occurs when node-specific information becomes “washed out” or “lost” after several iterations of GNN message passing. Intuitively, we can expect over-smoothing in cases where the information being aggregated from the node neighbors during message passing begins to dominate the updated node representations. In these cases, the updated node representations (i.e., the vectors) will depend too strongly on the incoming message aggregated from the neighbors (i.e., the vectors) at the expense of the node representations from the previous layers (i.e., the vectors). A natural way to alleviate this issue is to use vector concatenations or skip connections, which try to directly preserve information from previous rounds of message passing during the update step.
These concatenation and skip-connection methods can be used in conjunction with most other GNN update approaches. Thus, for the sake of generality, we will use to denote the base update function that we are building upon (e.g., we can assume that is given by Equation (5.9)), and we will define various skip-connection updates on top of this base function.
One of the simplest skip connection updates employs a concatenation to preserve more node-level information during message passing:
where we simply concatenate the output of the base update function with the node’s previous-layer representation. Again, the key intuition here is that we encourage the model to disentangle information during message passing—separating the information coming from the neighbors (i.e., ) from the current representation of each node (i.e., ).
The concatenation-based skip connection was proposed in the GraphSAGE framework, which was one of the first works to highlight the possible benefits of these kinds of modifications to the update function [Hamilton et al., 2017a]. However, in addition to concatenation, we can also employ other forms of skip-connections, such as the linear interpolation method proposed by Pham et al. [2017]:
where are gating vectors with and denotes elementwise multiplication. In this approach, the final updated representation is a linear interpolation between the previous representation and the representation that was updated based on the neighborhood information. The gating parameters can be learned jointly with the model in a variety of ways. For example, Pham et al. [2017] generate as the output of a separate single-layer GNN, which takes the current hidden-layer representations as features. However, other simpler approaches could also be employed, such as simply directly learning parameters for each message passing layer or using an MLP on the current node representations to generate these gating parameters.
In general, these concatenation and residual connections are simple strategies that can help to alleviate the over-smoothing issue in GNNs, while also improving the numerical stability of optimization. Indeed, similar to the utility of residual connections in CNNs [He et al., 2016], applying these approaches to GNNs can facilitate the training of much deeper models. In practice, these techniques tend to be most useful for node classification tasks with moderately deep GNNs (e.g., 2–5 layers), and they excel on tasks that exhibit homophily, i.e., where the prediction for each node is strongly related to the features of its local neighborhood.
5.3.2 Gated Updates
Section titled “5.3.2 Gated Updates”In the previous section we discussed skip-connection and residual connection approaches that bear strong analogy to techniques used in computer vision to build deeper CNN architectures. In a parallel line of work, researchers have also drawn inspiration from the gating methods used to improve the stability and learning ability of RNNs. In particular, one way to view the GNN message passing algorithm is that the aggregation function is receiving an observation from the neighbors, which is then used to update the hidden state of each node. In this view, we can directly apply methods used to update the hidden state of RNN architectures based on observations. For instance, one of the earliest GNN architectures [Li et al., 2015] defines the update function as
where GRU denotes the update equation of the GRU cell [Cho et al., 2014]. Other approaches have employed updates based on the LSTM architecture [Selsam et al., 2019].
In general, any update function defined for RNNs can be employed in the context of GNNs. We simply replace the hidden state argument of the RNN update function (usually denoted ) with the node’s hidden state, and we replace the observation vector (usually denoted ) with the message aggregated from the local neighborhood. Importantly, the parameters of this RNN-style update are always shared across nodes (i.e., we use the same LSTM or GRU cell to update each node). In practice, researchers usually share the parameters of the update function across the message-passing layers of the GNN as well.
These gated updates are very effective at facilitating deep GNN architectures (e.g., more than 10 layers) and preventing over-smoothing. Generally, they are most useful for GNN applications where the prediction task requires complex reasoning over the global structure of the graph, such as applications for program analysis [Li et al., 2015] or combinatorial optimization [Selsam et al., 2019].
5.3.3 Jumping Knowledge Connections
Section titled “5.3.3 Jumping Knowledge Connections”In the preceding sections, we have been implicitly assuming that we are using the output of the final layer of the GNN. In other words, we have been assuming that the node representations that we use in a downstream task are equal to final layer node embeddings in the GNN:
This assumption is made by many GNN approaches, and the limitations of this strategy motivated much of the need for residual and gated updates to limit over-smoothing.
However, a complimentary strategy to improve the quality of the final node representations is to simply leverage the representations at each layer of message passing, rather than only using the final layer output. In this approach we define the final node representations as
where is an arbitrary differentiable function. This strategy is known as adding jumping knowledge (JK) connections and was first proposed and analyzed by Xu et al. [2018]. In many applications the function can simply be defined as the identity function, meaning that we just concatenate the node embeddings from each layer, but Xu et al. [2018] also explore other options such as max-pooling approaches and LSTM attention layers. This approach often leads to consistent improvements across a wide variety of tasks and is a generally useful strategy to employ.
5.4 Edge Features and Multi-Relational GNNs
Section titled “5.4 Edge Features and Multi-Relational GNNs”So far our discussion of GNNs and neural message passing has implicitly assumed that we have simple graphs. However, there are many applications where the graphs in question are multi-relational or otherwise heterogenous (e.g., knowledge graphs). In this section, we review some of the most popular strategies that have been developed to accommodate such data.
5.4.1 Relational Graph Neural Networks
Section titled “5.4.1 Relational Graph Neural Networks”The first approach proposed to address this problem is commonly known as the Relational Graph Convolutional Network (RGCN) approach [Schlichtkrull et al., 2017]. In this approach we augment the aggregation function to accommodate multiple relation types by specifying a separate transformation matrix per relation type:
where is a normalization function that can depend on both the neighborhood of the node as well as the neighbor being aggregated over. Schlichtkrull et al. [2017] discuss several normalization strategies to define that are analagous to those discussed in Section 5.2.1. Overall, the multi-relational aggregation in RGCN is thus analagous to the basic a GNN approach with normalization, but we separately aggregate information across different edge types.
Parameter Sharing
One drawback of the naive RGCN approach is the drastic increase in the number of parameters, as now we have one trainable matrix per relation type. In certain applications—such as applications on knowledge graphs with many distinct relations—this increase in parameters can lead to overfitting and slow learning. Schlichtkrull et al. [2017] propose a scheme to combat this issue by parameter sharing with basis matrices, where
In this basis matrix approach, all the relation matrices are defined as linear combinations of basis matrices , and the only relation-specific parameters are the combination weights for each relation . In this basis sharing approach, we can thus rewrite the full aggregation function as
where is a tensor formed by stacking the basis matrices, is a vector containing the basis combination weights for relation , and denotes a tensor product along mode . Thus, an alternative view of the parameter sharing RGCN approach is that we are learning an embedding for each relation, as well a tensor that is shared across all relations.
Extensions and Variations
The RGCN architecture can be extended in many ways, and in general, we refer to approaches that define separate aggregation matrices per relation as relational graph neural networks. For example, a variation of this approach without parameter sharing is deployed by Zitnik et al. [2018] to model a multi-relational dataset relating drugs, diseases and proteins, and a similar strategy is leveraged by Marcheggiani and Titov [2017] to analyze linguistic dependency graphs. Other works have found success combining the RGCN-style aggregation with attention [Teru et al., 2020].
5.4.2 Attention and Feature Concatenation
Section titled “5.4.2 Attention and Feature Concatenation”The relational GNN approach, where we define a separate aggregation parameter per relation, is applicable for multi-relational graphs and cases where we have discrete edge features. To accommodate cases where we have more general forms of edge features, we can leverage these features in attention or by concatenating this information with the neighbor embeddings during message passing. For example, given any base aggregation approach one simple strategy to leverage edge features is to define a new aggregation function as
where denotes an arbitrary vector-valued feature for the edge . This approach is simple and general, and has seen recent success with attention-based approaches as the base aggregation function [Sinha et al., 2019].
5.5 Graph Pooling
Section titled “5.5 Graph Pooling”The neural message passing approach produces a set of node embeddings, but what if we want to make predictions at the graph level? In other words, we have been assuming that the goal is to learn node representations , but what if we to learn an embedding for the entire graph ? This task is often referred to as graph pooling, since our goal is to pool together the node embeddings in order to learn an embedding of the entire graph.
Set Pooling Approaches
Similar to the operator, the task of graph pooling can be viewed as a problem of learning over sets. We want to design a pooling function , which maps a set of node embeddings to an embedding that represents the full graph. Indeed, any of the approaches discussed in Section 5.2.2 for learning over sets of neighbor embeddings can also be employed for pooling at the graph level.
In practice, there are two approaches that are most commonly applied for learning graph-level embeddings via set pooling. The first approach is simply to take a sum (or mean) of the node embeddings:
where is some normalizing function (e.g., the identity function). While quite simple, pooling based on the sum or mean of the node embeddings is often sufficient for applications involving small graphs.
The second popular set-based approach uses a combination of LSTMs and attention to pool the node embeddings, in a manner inspired by the work of Vinyals et al. [2015]. In this pooling approach, we iterate a series of attention-based aggregations defined by the following set of equations, which are iterated for steps:
In the above equations, the vector represents a query vector for the attention at each iteration . In Equation (5.39), the query vector is used to compute an attention score over each node using an attention function (e.g., a dot product), and this attention score is then normalized in Equation (5.40). Finally, in Equation (5.41) a weighted sum of the node embeddings is computed based on the attention weights, and this weighted sum is used to update the query vector using an LSTM update (Equation (5.38)). Generally, the and vectors are initialized with all-zero values, and after iterating Equations (5.38)–(5.41) for iterations, an embedding for the full graph is computed as
This approach represents a sophisticated architecture for attention-based pooling over a set, and it has become a popular pooling method in many graph-level classification tasks.
Graph Coarsening Approaches
One limitation of the set pooling approaches is that they do not exploit the structure of the graph. While it is reasonable to consider the task of graph pooling as simply a set learning problem, there can also be benefits from exploiting the graph topology at the pooling stage. One popular strategy to accomplish this is to perform graph clustering or coarsening as a means to pool the node representations.
In these style of approaches, we assume that we have some clustering function
which maps all the nodes in the graph to an assignment over clusters. In particular, we presume that this function outputs an assignment matrix , where denotes the strength of the association between node and cluster . One simple example of an function would be spectral clustering approach described in Chapter 1, where the cluster assignment is based on the spectral decomposition of the graph adjacency matrix. In a more complex definition of , one can actually employ another GNN to predict cluster assignments [Ying et al., 2018b].
Regardless of the approach used to generate the cluster assignment matrix , the key idea of graph coarsening approaches is that we then use this matrix to coarsen the graph. In particular, we use the assignment matrix to compute a new coarsened adjacency matrix
and a new set of node features
Thus, this new adjacency matrix now represents the strength of association (i.e., the edges) between the clusters in the graph, and the new feature matrix represents the aggregated embeddings for all the nodes assigned to each cluster. We can then run a GNN on this coarsened graph and repeat the entire coarsening process for a number of iterations, where the size of the graph is decreased at each step. The final representation of the graph is then computed by a set pooling over the embeddings of the nodes in a sufficiently coarsened graph.
This coarsening based approach is inspired by the pooling approaches used in CNNs, and it relies on the intuition that we can build hierarchical GNNs that operate on different granularities of the input graph. In practice, these coarsening approaches can lead to strong performance, but they can also be unstable and difficult to train. For example, in order to have the entire learning process be end-to-end differentiable the clustering functions must be differentiable, which rules out most off-the-shelf clustering algorithms such as spectral clustering. There are also approaches that coarsen the graph by selecting a set of nodes to remove rather than pooling all nodes into clusters, which can lead to benefits in terms of computational complexity, speed, and downstream performance [Cangea et al., 2018, Gao and Ji, 2019].
5.6 Generalized Message Passing
Section titled “5.6 Generalized Message Passing”The presentation in this chapter so far has focused on the most popular style of GNN message passing, which operates largely at the node level. However, the GNN message passing approach can also be generalized to leverage edge and graph-level information at each stage of message passing. For example, in the more general approach proposed by Battaglia et al. [2018], we define each iteration of message passing according to the following equations:
The important innovation in this generalized message passing framework is that, during message passing, we generate hidden embeddings for each edge in the graph, as well as an embedding corresponding to the entire graph. This allows the message passing model to easily integrate edge and graph-level features, and recent work has also shown this generalized message passing approach to have benefits compared to a standard GNN in terms of logical expressiveness [Barceló et al., 2020]. Generating embeddings for edges and the entire graph during message passing also makes it trivial to define loss functions based on graph or edge-level classification tasks.
In terms of the message-passing operations in this generalized message-passing framework, we first update the edge embeddings based on the embeddings of their incident nodes (Equation (5.46)). Next, we update the node embeddings by aggregating the edge embeddings for all their incident edges (Equations (5.47) and (5.48)). The graph embedding is used in the update equation for both node and edge representations, and the graph-level embedding itself is updated by aggregating over all the node and edge embeddings at the end of each iteration (Equation (5.49)). All of the individual update and aggregation operations in such a generalized message-passing framework can be implemented using the techniques discussed in this chapter (e.g., using a pooling method to compute the graph-level update).
Footnotes
Section titled “Footnotes”-
The different iterations of message passing are also sometimes known as the different “layers” of the GNN. ↩
-
Note, however, that the using identity features makes the model transductive and incapable of generalizing to unseen nodes. ↩
-
In general, the parameters , , and can be shared across the GNN message passing iterations or trained separately for each layer. ↩