the graph neural network model - mcgill university school

20
Chapter 4 The Graph Neural Network Model The first part of this book discussed approaches for learning low-dimensional em- beddings of the nodes in a graph. However, the approaches we discussed primar- ily used a shallow encoding approach to generate representations of nodes. We simply trained a unique embedding for each node using an embedding lookup, and our encoder function did not depend on the input graph structure. 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. To define a deep neural network over general graphs, we need to generalize both of these approaches and design a framework without such topological restrictions. Can we simply use the adjacency matrix as input to a deep neural network? 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: z G = MLP(A[1] A[2] ... A[|V|]), (4.1) where A[i] 2 R |V| denotes a row of the adjacency matrix and we use to denote vector concatenation. We saw some approaches using a variation 53

Upload: others

Post on 24-Apr-2022

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Graph Neural Network Model - McGill University School

Chapter 4

The Graph Neural NetworkModel

The first part of this book discussed approaches for learning low-dimensional em-beddings of the nodes in a graph. However, the approaches we discussed primar-ily used a shallow encoding approach to generate representations of nodes. Wesimply trained a unique embedding for each node using an embedding lookup,and our encoder function did not depend on the input graph structure.

In this chapter we turn our focus to more complex encoder models. Wewill introduce the graph neural network (GNN) formalism, which is a generalframework for defining deep neural networks on graph data. The key idea isthat we want to generate representations of nodes that actually depend on thestructure of the graph, as well as any feature information we might have.

The primary challenge in developing complex encoders for graph-structureddata is that our usual deep learning toolbox does not apply. For example,convolutional neural networks (CNNs) are well-defined only over grid-structuredinputs (e.g., images), while recurrent neural networks (RNNs) are well-definedonly over sequences. To define a deep neural network over general graphs, weneed to generalize both of these approaches and design a framework withoutsuch topological restrictions.

Can we simply use the adjacency matrix as input to a deep neuralnetwork? One reasonable idea for defining a deep neural network overgraphs would be to simply use the adjacency matrix as input to a deepneural network. For example, to generate an embedding of an entire graphwe could simply flatten the adjacency matrix and feed the result to a multi-layer perceptron:

zG = MLP(A[1] � A[2] � ... � A[|V|]), (4.1)

where A[i] 2 R|V| denotes a row of the adjacency matrix and we use � todenote vector concatenation. We saw some approaches using a variation

53

Page 2: The Graph Neural Network Model - McGill University School

54 CHAPTER 4. THE GRAPH NEURAL NETWORK MODEL

of this idea in Chapter 2 when we discussed the autoencoder approachesSDNE and DNGR.

The issue with such approaches is that they depend on the arbitrary

ordering of nodes that we used in the adjacency matrix. More formally, theissue is that such a model is not permutation equivariant with respect to thenode ordering, which means that the output changes when we permute therows/columns of the adjacency matrix. One key desideratum for designingneural networks over graphs is that they are permutation equivariant, andthis is another challenge of learning over graphs compared to objects suchas images or sequences.

4.1 Neural Message Passing

The basic graph neural network (GNN) model can be motivated in a variety ofways. The same fundamental GNN model has been derived as a generalizationof convolutions to non-Euclidean data [Bruna et al., 2014], as a di↵erentiablevariant of belief propagation [Dai et al., 2016], as well as by analogy to classicgraph 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 inwhich vector messages are exchanged between nodes in the graph and updatedusing neural networks.

In the rest of this chapter, we will detail the foundations of this neuralmessage passing framework. We will focus on the message passing frameworkitself and defer discussions of training and optimizing GNN models to Chapter 5.The bulk of this chapter will describe how we can take an input graph G = (V, E),along with a set of node features X 2 Rd⇥|V|, and use this information togenerate node embeddings zu. However, we will also discuss how the GNNframework can be used to generate embeddings for subgraphs and entire graphs.

4.1.1 Overview of the Message Passing Framework

During each message-passing iteration in a GNN, the embedding h(k)u corre-

sponding to each node u 2 V is updated according to information aggregatedfrom u’s graph neighborhood N (v) (Figure 4.1). This message-passing updatecan be expressed as follows:

h(k+1)

u = UPDATE(k)⇣h(k)

u , AGGREGATE(k)({h(k)v , 8v 2 N (u)})

⌘(4.2)

= UPDATE(k)⇣h(k)

u ,m(k)N (u)

⌘, (4.3)

where UPDATE and AGGREGATE are arbitrary di↵erentiable functions (i.e., neu-ral networks) and mN (u) is the “message” that is aggregated from u’s graphneighborhood N (u). We use superscripts to distinguish the embeddings and

Page 3: The Graph Neural Network Model - McGill University School

4.1. NEURAL MESSAGE PASSING 55

INPUT GRAPH

TARGET NODE B

DE

F

CA

A

A

A

C

F

B

E

A

D

B

Caggregate

Figure 4.1: Overview of how a single node aggregates messages from its localneighborhood. 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 arebased on information aggregated from their respective neighborhoods, and soon. This visualization shows a two-layer version of a message-passing model.

functions at di↵erent iterations of message passing.1

At each iteration of the GNN, the AGGREGATE function takes as input theset of embeddings of the nodes in u’s graph neighborhood N (u) and generates amessage mN (u) based on this aggregated neighborhood information. The updatefunction UPDATE then combines the message mN (u) with the previous embed-ding hu of node u to generate the updated embedding. The initial embeddings

at k = 0 are set to the input features for all the nodes, i.e., h(0)

u = xu, 8u 2 V.After running K iterations of the GNN message passing, we can use the outputof the final layer to define the embeddings for each node, i.e.,

zu = h(K)

u , 8u 2 V. (4.4)

Note that since the AGGREGATE function takes a set as input, GNNs defined inthis way are permutation equivariant by design.

4.1.2 Motivations and Intuitions

The basic intuition behind the GNN message-passing framework is straight-forward: at each iteration, every node aggregates information from its localneighborhood, and as these iterations progress each node embedding containsmore and more information from further reaches of the graph. To be precise:after the first iteration (k = 1), every node embedding contains informationfrom its 1-hop neighborhood, i.e., every node embedding contains informationabout the features of its immediate graph neighbors, which can be reached bya path of length 1 in the graph; after the second iteration (k = 2) every nodeembedding contains information from its 2-hop neighborhood; and in general,after k iterations every node embedding contains information about its k-hopneighborhood.

1The di↵erent iterations of message passing are also sometimes known as the di↵erent“layers” of the GNN.

Page 4: The Graph Neural Network Model - McGill University School

56 CHAPTER 4. THE GRAPH NEURAL NETWORK MODEL

But what kind of “information” do these node embeddings actually encode?Generally, this information comes in two forms. On the one hand there is struc-tural information about the graph. For example, after k iterations of GNN

message passing, the embedding h(k)u of node u might encode information about

the degrees of all the nodes in u’s k-hop neighborhood. This structural infor-mation can be useful for many tasks. For instance, when analyzing moleculargraphs, we can use degree information to infer atom types and di↵erent struc-

tural motifs such as benzene rings (Figure 1.5).In addition to structural information, the other key kind of information cap-

tured by GNN node embedding is feature-based. We generally assume that allthe nodes in our graph have features or attributes associated with them, whichwe use to initialize the GNN message passing. After t iterations of GNN mes-sage passing, the embeddings for each node thus also encode information aboutall the features in their t-hop neighborhood. This local feature-aggregation be-haviour of GNNs is analogous to the behavior of the convolutional kernels inconvolutional neural networks (CNNs). However, whereas CNNs aggregate fea-ture information from spatially-defined patches in an image, GNNs aggregateinformation based on local graph neighborhoods. We will explore the connectionbetween GNNs and convolutions in more detail in Chapter 6.

4.1.3 The Basic GNN

So far, we have discussed the GNN framework in a relatively abstract fashion asa series of message-passing iterations using UPDATE and AGGREGATE functions(Equation 4.2). In order to translate the abstract GNN framework defined inEquation 4.2 into something we can implement, we must give concrete instan-tiations to these UPDATE and AGGREGATE functions. We begin here with themost basic GNN framework, which is a simplification of the original GNN modelproposed by Scarselli et al. [2009].

The basic GNN message passing is defined as

h(k)u = �

0

@W(k)self

h(k�1)

u + W(k)neigh

X

v2N (u)

h(k�1)

v + b(k)

1

A , (4.5)

where W(k)self

,W(tkneigh

2 Rd(k)⇥d(k�1)

are trainable parameter matrices and �

denotes an elementwise non-linearity (e.g., a tanh or ReLU). The bias term

b 2 Rd(k)

is often ommitted for notational simplicity but can be important toachieve strong performance.

The message passing in the basic GNN framework is analgous to a stan-dard multi-layer perceptron (MLP) or Elman-style recurrent neural network(Elman RNN), as it relies on linear operations followed by a single elementwisenon-linearity. We first sum the messages incoming from the neighbors; then,we combine the neighborhood information with the node’s previous embeddingusing a linear combination; and finally, we apply an elementwise non-linearity.

Page 5: The Graph Neural Network Model - McGill University School

4.1. NEURAL MESSAGE PASSING 57

We can equivalently define the basic GNN through the UPDATE and AGGREGATEfunctions:

mN (u) =X

v2N (u)

hv, (4.6)

UPDATE(hu,mN (u)) = ��Wselfhu + WneighmN (u)

�, (4.7)

where we recall that we use

mN (u) = mN (u) (4.8)

as a shorthand to denote the message that has been aggregated from u’s graphneighborhood. Note also that we ommitted the superscript denoting the itera-tion in the above equations, which we will often do for notational brevity. Ingeneral, the parameters Wself,Wneigh and b can be shared across the GNNmessage passing iterations or trained separately.

Node vs. graph-level equations In the description of the basic GNNmodel above, we defined the core message-passing operations at the nodelevel. We will use this convention for the bulk of this Chapter and this bookas a whole. However, it is important to note that many GNNs can also besuccinctly defined using graph-level equations. In the case of a basic GNN,we can write the graph-level definition of the model as follows:

H(t) = �

⇣AH(t�1)W(t)

neigh+ H(t�1)W(t)

self

⌘, (4.9)

where H(t) 2 R|V |⇥d denotes the matrix of node representations at layer t

in the GNN (with each node corresponding to a row in the matrix), A is thegraph adjacency matrix, and we have omitted the bias term for notationalsimplicity. While this graph-level representation is not easily applicable toall GNN models—such as the attention-based models we discuss below—itis often more succinct and also highlights how many GNNs can be e�cientlyimplemented using a small number of sparse matrix operations.

4.1.4 Message Passing with Self-loops

As a simplification of the neural message passing approach it is common to addself-loops to the input graph and omit the explicit update step. In this approachwe define the message passing simply as

h(k)u = AGGREGATE({h(t�1)

v , 8v 2 N (u) [ {u}}), (4.10)

where now the aggregation is taken over the set N (u) [ {u}, i.e., the node’sneighbors as well as the node itself. The benefit of this approach is that we nolonger need to define an explicit update function, as the update is implicitlydefined through the aggregation method. Simplifying the message passing in

Page 6: The Graph Neural Network Model - McGill University School

58 CHAPTER 4. THE GRAPH NEURAL NETWORK MODEL

this way can often alleviate overfitting, but it also severely limits the expres-sivity of the GNN, as the information coming the node’s neighbours cannot bedi↵erentiated from the information from the node itself.

In the case of the basic GNN, adding self-loops is equivalent to sharingparameters between the Wself and Wneigh matrices, which gives the followinggraph-level update:

H(t) = �

⇣(A + I)H(t�1)W(t)

⌘. (4.11)

In the following chapters we will refer to this as the self-loop GNN approach.

4.2 Generalized Neighborhood Aggregation

The basic GNN model outlined in Equation (4.5) can achieve strong perfor-mance, and its theoretical capacity is well-understood (see Chapter 6). However,just like a simple MLP or Elman RNN, the basic GNN can be improved uponand generalized in many ways. Here, we discuss how the AGGREGATE operatorcan be generalized and improved upon, with the following section (Section 4.3)providing an analogous discussion for the UPDATE operation.

4.2.1 Neighborhood Normalization

The most basic neighborhood aggregation operation (Equation 4.6) simply takesthe sum of the neighbor embeddings. One issue with this approach is that it canbe unstable and highly sensitive to node degrees. For instance, suppose nodeu has 100⇥ as many neighbors as node u

0 (i.e., a much higher degree), thenwe would reasonably expect that k

Pv2N (u) hvk >> k

Pv02N (u0) hv0k (for any

reasonable vector norm k · k), and this drastic di↵erence in magnitude can leadto numerical instabilities as well as di�culties for optimization.

One simple solution to this problem is to simply normalize the aggregationoperation based upon the degrees of the nodes involved. The simplest approachis to just take an average rather than sum:

mN (u) =

Pv2N (u) hv

|N (u)| , (4.12)

but researchers have also found success with other normalization factors, suchas the following approach employed by Kipf and Welling [2016]:

mN (u) =X

v2N (u)

hvp|N (u)||N (v)|

. (4.13)

The intuition behind the Kipf normalization is that the model should down-weight messages coming from neighbors with very high degrees, since the “sig-nal” coming from these high-degree neighbors may be less precise and informa-tive. For example, in a citation graph—the kind of data that Kipf and Welling

Page 7: The Graph Neural Network Model - McGill University School

4.2. GENERALIZED NEIGHBORHOOD AGGREGATION 59

[2016] analyzed—information from very high-degree nodes (i.e., papers) may notbe very useful for inferring community membership in the graph, since these pa-pers can be cited thousands of times across diverse subfields. Kipf normalizationcan also be motivated based on spectral graph theory. In particular, combiningthe Kipf normalized aggregation (Equation 4.13) along with the basic GNN up-date function (Equation 4.7) results in a first-order approximation of a spectralgraph convolution, and we expand on this connection in Chapter 6.

Graph convolutional networks (GCNs)

One of the most popular baseline graph neural network models—the graphconvolutional network (GCN)—employs the Kipf normalized aggregation as wellas the self-loop update approach. The GCN model thus defines the messagepassing function as

h(k)v = �

0

@W(k)X

v2N (u)[{u}

hvp|N (u)||N (v)|

1

A . (4.14)

This approach was first outlined by Kipf and Welling [2016] and has proved tobe one of the most popular and e↵ective baseline GNN architectures.

To normalize or not to normalize? Proper normalization can be es-sential to achieve stable and strong performance when using a GNN. Itis important to note, however, that normalization can also lead to a lossof information. For example, after normalization, it can be hard (or evenimpossible) to use the learned embeddings to distinguish between nodesof di↵erent degrees, and various other structural graph features can beobscured by normalization. In fact, a basic GNN using the normalized ag-gregation operator in Equation (4.12) is provably less powerful than thebasic sum aggregator in Equation (4.6) (see Chapter 6). The use of nor-malization is thus an application-specific question. Usually, normalizationis most helpful in tasks where node feature information is far more usefulthan structural information, or where there is a very wide range of nodedegrees that can lead to instabilities during optimization.

4.2.2 Set Aggregators

Neighborhood normalization can be a useful tool to improve GNN performance,but can we do more to improve the AGGREGATE operator? Is there perhapssomething 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 {hv, 8v 2 N (u)} and must map thisset to a single vector mN (u). The fact that {hv, 8v 2 N (u)} is a set is in factquite important: there is no natural ordering of a nodes’ neighbors, and anyaggregation function we define must thus be permutation invariant.

Page 8: The Graph Neural Network Model - McGill University School

60 CHAPTER 4. THE GRAPH NEURAL NETWORK MODEL

Set pooling

One principled approach to define an aggregation function is based on the theoryof permutation invariant neural networks. For example, Zaheer et al. [2017]shows that an aggregation function with the following form is a universal set

function approximator:

mN (u) = MLP✓

0

@X

v2N(u)

MLP�(hv)

1

A , (4.15)

where as usual we use MLP✓ to denote an arbitrarily deep multi-layer perceptronparameterized by some trainable parameters ✓. In other words, the theoreticalresults in Zaheer et al. [2017] show that any permutation-invariant functionthat maps a set of embeddings to a single embedding can be approximated toan arbitrary accuracy by a model following Equation (4.15).

Note that the theory presented in Zaheer et al. [2017] employs a sum of theembeddings after applying the first MLP (as in Equation 4.15). However, it ispossible to replace the sum with an alternative reduction function, such as anelement-wise maximum or minimum, as in Qi et al. [2017], and it is also commonto combine models based on Equation (4.15) with the normalization approachesdiscussed in Section 4.2.1, as in the GraphSAGE-pool approach [Hamilton et al.,2017b].

Set pooling approaches based on Equation (4.15) often lead to small increasesin 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 commonto stick with MLPs that have only a single hidden layer, since these models aresu�cient to satisfy the theory, but are not so overparameterized so as to riskcatastrophic overfitting.

Janossy pooling

Set pooling approaches to neighborhood aggregation essentially just add extralayers of MLPs on top of the more basic aggregation architectures discussedin Section 4.1.3. This idea is simple, but is known to increase the theoreticalcapacity of GNNs. However, there is another alternative approach, termedJanossy pooling, that is also provably more powerful than simply taking a sumor mean of the neighbor embeddings [Murphy et al., 2018].

Recall that the challenge of neighborhood aggregation is that we must usea permutation-invariant function, since there is no natural ordering of a node’sneighbors. In the set pooling approach (Equation 4.15), we achieved this permu-tation invariance by relying on a sum, mean, or element-wise max to reduce theset of embeddings to a single vector. We made the model more powerful by com-bining this reduction with feed-forward neural networks (i.e., MLPs). Janossypooling employs a di↵erent 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.

Page 9: The Graph Neural Network Model - McGill University School

4.2. GENERALIZED NEIGHBORHOOD AGGREGATION 61

Let ⇡i 2 ⇧ denote a function (i.e., permutation) that maps the set {hv, 8v 2N (u)} to a specific sequence (hv1 ,hv2 , ...,hv|N(u)|)⇡i . In other words, ⇡i takesthe unordered set of neighbor embeddings and places these embeddings in asequence based on some arbitrary ordering. The Janossy pooling approach thenperforms neighborhood aggregation by

mN (u) = MLP✓

1

|⇧|X

⇡2⇧

⇢�

�hv1 ,hv2 ,hv|N(u)|)⇡i

�!

, (4.16)

where ⇧ denotes a set of permutations and ⇢� is a permutation-sensitive func-tion, e.g., a neural network that operates on sequences. In practice ⇢� is usuallydefined to be an LSTM, since LSTMs are known to be a powerful neural networkarchitecture for sequences.

If the set of permutations ⇧ in Equation (4.16) is equal to all possible per-mutations, then the aggregator in Equation (4.16) is also a universal functionapproximator for sets, like Equation (4.15). However, summing over all pos-sible permutations is generally intractable. Thus, in practice, Janossy poolingemploys one of two approaches:

1. Sample a random subset of possible permutations during each applicationof the aggregator, and only sum over that random subset.

2. Employ a canonical ordering of the nodes in the neighborhood set; e.g.,order the nodes in descending order according to their degree, with tiesbroken randomly.

Murphy et al. [2018] includes a detailed discussion and empirical comparison ofthese two approaches, as well as other approximation techniques (e.g., truncat-ing the length of sequence), and their results indicate that Janossy-style poolingcan improve upon set pooling in a number of synthetic evaluation setups.

4.2.3 Neighborhood Attention

In addition to more general forms of set aggregation, a popular strategy forimproving the aggregation layer in GNNs is to apply attention [Bahdanau et al.,2014]. The basic idea is to assign an attention weight or importance to eachneighbor, which is used to weigh this neighbor’s influence during the aggregationstep. The first GNN model to apply this style of attention was Velickovic et al.[2017]’s Graph Attention Network (GAT), which uses attention weights to definea weighted sum of the neighbors:

mN (u) =X

v2N (u)

↵u,vhv, (4.17)

where ↵u,v denotes the attention on neighbor v 2 N (u) when we are aggregatinginformation at node u. In the original GAT paper, the attention weights aredefined as

↵u,v =exp

�a>[Whu � Whv]

�P

v02N (u) exp (a>[Whu � Whv0 ]), (4.18)

Page 10: The Graph Neural Network Model - McGill University School

62 CHAPTER 4. THE GRAPH NEURAL NETWORK MODEL

where a is a trainable attention vector, W is a trainable matrix, and � denotesthe concatenation operation.

The GAT-style attention computation is known to work well with graphdata. However, in principle any standard attention model from the deep learningliterature at large can be used [Bahdanau et al., 2014]. Popular variants ofattention include the bilinear attention model

↵u,v =exp

�h>

u Whv

�P

v02N (u) exp (h>u Whv0)

, (4.19)

as well as variations of attention layers using MLPs, e.g.,

↵u,v =exp (MLP(hu,hv))P

v02N (u) exp (MLP(hu,hv0)), (4.20)

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 ar-chitecture [Vaswani et al., 2017]. In this approach, one computes K distinct at-tention weights ↵u,v,k, using independently parametrized attention layers. Themessages aggregated using the di↵erent attention weights are then transformedand combined in the aggregation step, usually with a linear projection followedby a concatenation operation, e.g.,

mN (u) = [a1 � a2 � ... � aK ] (4.21)

ak = Wi

X

v2N (u)

↵u,v,khv (4.22)

where the attention weights ↵u,v,k for each of the K attention heads can becomputed using any of the above attention mechanisms.

Graph attention and transformers GNN models with multi-headedattention (Equation 4.21) are closely related to the Transformer architec-ture [Vaswani et al., 2017]. Transformers are a popular architecture forboth natural language processing (NLP) and computer vision, and—in thecase 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 [Yanget al., 2019]. The basic idea behind Transformers is to define neural net-work layers entirely based on the attention operation. At each layer in aTransformer, a new hidden representation is generated for every positionin the input data (e.g., every word in a sentence) by using multiple atten-tion heads to compute attention weights between all pairs of positions inthe input, which are then aggregated with weighted sums based on theseattention weights (in a manner analogous to Equation 4.21). In fact, thebasic Transformer layer is exactly equivalent to a GNN layer using multi-headed attention (i.e., Equation 4.21) if we assume that the GNN receivesa fully-connected graph as input.

Page 11: The Graph Neural Network Model - McGill University School

4.3. GENERALIZED UPDATE METHODS 63

This connection between GNNs and Transformers has been exploited innumerous works. For example, one implementation strategy for designingGNNs is to simply start with a Transformer model and then apply a bi-nary adjacency mask on the attention layer to ensure that information isonly 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, adownside of this approach, is that Transformers must compute the pair-wise attention between all positions/nodes in the input, which leads to aquadratic O(|V|2) time complexity to aggregate messages for all nodes inthe graph, compared to a O(|V||E|) time complexity for a more standardGNN implementation.

Adding attention is a useful strategy for increasing the representational ca-pacity of a GNN model, especially in cases where you have prior knowledgeto indicate that some neighbors might be more informative than others. Forexample, consider the case of classifying papers into topical categories basedon citation networks. Often there are papers that span topical boundaries, orthat are highly cited across various di↵erent fields. Ideally, an attention-basedGNN would learn to ignore these papers in the neural message passing, as such“promiscuous” neighbors would likely be uninformative when trying to identifythe topical category of a particular node. In Chapter 6, we will discuss howattention can influence the inductive bias of GNNs from a signal processingperspective.

4.3 Generalized Update Methods

The AGGREGATE operator in GNN models has generally received the most atten-tion 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 neighbourhood aggregation. However,the core GNN message passing involves two key steps: aggregation and up-dating. In many ways the UPDATE operator plays an equally important role indefining the power and inductive bias of the GNN model, and in this section, weturn our attention to various di↵erent generalizations of the UPDATE operator.

In the basic GNN model, the updated hidden representation h(t)u of a node

u is computed at each step of the message passing via a linear combination ofthe aggregated message mN (u) coming from the node u’s neighbours as well as

the node’s previous hidden representation h(t�1)

u . While simple and e↵ective inmany settings, this basic update approach has serious drawbacks.

Most prominently, by linearly combining mN (u) with the h(t�1)

u , the in-formation from the various iterations of message passing becomes “entangled”after each round of message passing. When using this simple linear combinationthe GNN has no easy way to disentangle local information that is specific to

Page 12: The Graph Neural Network Model - McGill University School

64 CHAPTER 4. THE GRAPH NEURAL NETWORK MODEL

a particular round of message passing, from more non-local information beingreceived in later message passing iterations. This linear entanglement can leadto (among other things) an issue known as over-smoothing. After a large num-ber of iterations of message passing, the representations for all the nodes in thegraph become very similar to one another.

Lastly, the simple style of update used in the basic GNN approach canlead to numerical instabilities (e.g., exploding gradients) due to the repeatedapplication of matrix multiplications at each layer. This issue is analagous tothe numerical instabilities observed for basic recurrent neural network (RNN)models, such as the Elman RNN.

Over-smoothing and neighbourhood influence The issue of over-

smoothing in GNNs can be formalized by defining the influence of each

nodes input feature h(0)

u = xu on the final layer embedding of all the other

nodes in the graph, i.e, h(K)

v , 8v 2 V. In particular, for any pair of nodesu and v we can quantify the influence of node u on node v in the GNN byexamining the magnitude of the corresponding Jacobian matrix [Xu et al.,2018b]:

IK(u, v) = 1>

@h(K)

v

@h(0)

u

!1, (4.23)

where 1 is a vector of all ones. The IK(u, v) value uses the sum of the

entries in the Jacobian matrix @h(K)v

@h(0)u

as a measure of how much the initial

embedding of node u influences the final embedding of node v in the GNN.Given this definition of influence, Xu et al. [2018b] prove the following:

Theorem 3. For any GNN model using a self-loop update approach and

an aggregation function of the form

AGGREGATE({hv, 8v 2 N (u) [ {u}}) =1

fn(|N (u) [ {u}|)X

v2N (u)[{u}

hv,

(4.24)where f : R+ ! R+

is an arbitrary di↵erentiable normalization function,

we have that

IK(u, v) / pG,K(u|v), (4.25)

where pG,K(u|v) denotes the probability of visiting node v on a length-K

random walk starting from node u.

This theorem is a direct consequence of Theorem 1 in Xu et al. [2018b].It states that when using a K-layer GCN-style model, the influence of nodeu and node v is proportional the probability of reaching node v on a K-steprandom walk starting from node u. An important consequence of this, how-ever, is that as K ! 1 the influence of every node approaches the station-ary distribution of random walks over the graph, meaning that local neigh-borhood information is lost. Moreover, in many real-world graphs—whichcontain high-degree nodes and resemble so-called “expander” graphs—it

Page 13: The Graph Neural Network Model - McGill University School

4.3. GENERALIZED UPDATE METHODS 65

only takes k = O(log(|V|) steps for the random walk starting from anynode to converge to an almost-uniform distribution [Hoory et al., 2006].

Theorem 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 4.7) as long as kW(k)self

k < kW(k)neigh

k at each layerk. Thus, when using simple GNN models—and especially those with theself-loop update approach—building deeper models can actually hurt per-formance. As more layers are added we lose information about local neigh-borhood structures and our learned embeddings become over-smoothed,approaching an almost-uniform distribution.

4.3.1 Concatenation and Skip-Connections

The core issue with the basic GNN update function is that it uses a linear com-bination to update the hidden node representation at each iteration of messagepassing. A natural way to alleviate this issue is to introduce various di↵erentconcatenation or skip-connections, which try to directly preserve informationfrom previous rounds of message passing during the update step.

These concatenation and skip-connection methods can be used in conjunc-tion with most other GNN update approaches. Thus, for the sake of generality,we will use UPDATEbase to denote the base update function that we are buildingupon (e.g., we can assume that UPDATEbase is given by Equation 4.7), and wewill define various skip-connection updates on top of this base function.

One of the simplest skip connection updates employs a concatenation topreserve more node-level information during message passing:

UPDATEconcat(hu,mN (u)) = [UPDATEbase(hu,mN (u)) � hu], (4.26)

where we simply concatenate the output of the base update function withthe nodes previous-layer representation. Again, the key intuition here is thatwe encourage the model to disentangle information during message passing—separating the information coming from the neighbors (i.e., mN (u)) from thecurrent representation of each node (i.e., hu).

The concatenation based skip connection was proposed in the GraphSAGEframework and was the first work to highlight the possible benefits of these kindsof modifications to the update function [Hamilton et al., 2017a]. However, inaddition to concatenation, we can also employ other forms of skip-connections,such as the linear interpolation method proposed by Pham et al. [2017]:

UPDATEinterpolate(hu,mN (u)) = ↵1 � UPDATEbase(hu,mN (u))+↵2 �hu, (4.27)

where ↵1,↵2 2 [0, 1]d are gating vectors with ↵2 = 1 � ↵1 and � denoteselementwise multiplication. In this approach, the final updated representationis a linear interpolation between the previous representation and the represen-tation that was updated based on the neighborhood information. The gating

Page 14: The Graph Neural Network Model - McGill University School

66 CHAPTER 4. THE GRAPH NEURAL NETWORK MODEL

parameters ↵1 can be learned jointly with the model in a variety of ways. Forexample, Pham et al. [2017] generates ↵1 as the output of a separate single-layer GNN, which takes the current hidden-layer representations as features.But other simpler approaches could also be employed, such as simply directlylearning ↵1 parameters for each message passing layer or using an MLP on thecurrent node representations to generate these gating parameters.

In general, these concatenation and residual connections are simple strate-gies that can help to alleviate the over-smoothing issue in GNNs, while alsoimproving the numerical stability of optimization. Indeed, similar to the util-ity of residual connections in convolutional neural networks (CNNs) [He et al.,2016], applying these approaches to GNNs can facilitate the training of muchdeeper models. In practice these techniques tend to be most useful for nodeclassification tasks with moderately deep GNNs (e.g., 2-5 layers), and they ex-cel on tasks that exhibit homophily, i.e., where the prediction for each node isstrongly related to the features of its local neighborhood.

4.3.2 Gated Updates

In the previous section we discussed skip-connection and residual connectionapproaches that bear strong analogy to techniques used in computer vision tobuild deeper CNN architectures. In a parallel line of work, researchers have alsodrawn inspiration from the gating methods used to improve the stability andlearning ability of recurrent neural networks (RNNs). In particular, one wayto view the GNN message passing algorithm is that the aggregation functionis receiving an “observation” from the neighbors, which is then used to updatethe “hidden state’ of each node. In this view, we can directly apply methodsused to update the hidden state of RNN architectures based on observations.For instance, one of the earliest GNN architectures [Li et al., 2015] defines theupdate function as

h(k)u = GRU(h(k�1)

u ,m(k)N (u)), (4.28)

where GRU denotes the update equation of the gated recurrent unit (GRU)cell [Cho et al., 2014]. Other approaches have employed updates based on theLSTM architecture [Selsam et al., 2018].

In general, any update function defined for RNNs can be employed in thecontext of GNNs. We simply replace the hidden state argument of the RNN up-date function (usually denoted h(t) with the node’s hidden state, and we replacethe observation vector (usually denoted x(t)) with the message aggregated fromthe local neighborhood. Importantly, the parameters of this RNN-style updateare always shared across nodes (i.e., we use the same LSTM or GRU cell toupdate each node). In practice, researchers usually share the parameters of theupdate function across the message passing layers of the GNN as well.

These gated updates are very e↵ective at facilitating deep GNN architectures(e.g., more than 10 layers) and preventing over-smoothing. Generally, they aremost useful for GNN applications where the prediction task requires complex

Page 15: The Graph Neural Network Model - McGill University School

4.4. EDGE FEATURES AND MULTI-RELATIONAL GNNS 67

reasoning over the global structure of the graph, such as applications for programanalysis [Li et al., 2015] or combinatorial optimization [Selsam et al., 2018].

4.3.3 Jumping Knowledge Connections

In the preceding sections we have been implicitly assuming that we are usingthe output of the final layer of the GNN. In other words, we have been assumingthat the node representations zu that we use in a downstream task are equal tofinal layer node embeddings in the GNN:

zu = h(K)

u , 8u 2 V. (4.29)

This assumption is made by many GNN approaches, and the limitations of thisstrategy motivated much of the need for residual and gated updates to limitover-smoothing.

However, a complimentary strategy to improve the quality of the final noderepresentations is to simply leverage the representations at each layer of message

passing, rather than only using the final layer output. In this approach we definethe final node representations zu as

zu = fJK(h(0)

u � h(1)

u � ... � h(K)

u ), (4.30)

where fJK is an arbitrary di↵erentiable function. This strategy is known asadding jumping knowledge (JK) connections and was first proposed and ana-lyzed by [Xu et al., 2018b]. In many applications the function fJK can simplybe defined as the identity function, meaning that we just concatenate the nodeembeddings from each layer, but Xu et al. [2018b] also explore other optionssuch as max-pooling approaches and LSTM attention layers. While simple, thisapproach often leads to consistent improvements across a wide-variety of tasksand is a generally useful strategy to employ.

4.4 Edge Features and Multi-relational GNNs

So far our discussion of GNNs and neural message passing has implicitly assumedthat we have simple graphs. However, there are many applications where thegraphs in question are multi-relational or otherwise heterogenous (e.g., knowl-edge graphs). In this section, we review some of the most popular strategiesthat have been developed to accommodate such data.

4.4.1 Relational Graph Neural Networks

The first approach proposed to address this problem is commonly known asthe Relational Graph Convolutional Network (RGCN) approach [Schlichtkrullet al., 2017]. In this approach we augment the aggregation function to accom-modate multiple relation types by specifying a separate transformation matrix

Page 16: The Graph Neural Network Model - McGill University School

68 CHAPTER 4. THE GRAPH NEURAL NETWORK MODEL

per relation type:

mN (u) =X

⌧2R

X

v2N⌧ (u)

W⌧hv

fn(N (u), N (v)), (4.31)

where fn is a normalization function that can depend on both the neighborhoodof the node u as well as the neighbor v being aggregated over. Schlichtkrull et al.[2017] discuss several normalization strategies to define fn that are analagousto those discussed in Section 4.2.1. Overall, the multi-relational aggregation inRGCN is thus analagous to the basic a GNN approach with normalization, butwe separately aggregate information across di↵erent edge types.

Parameter sharing

One drawback of the naive RGCN approach is the drastic increase in the num-ber of parameters, as now we have one trainable matrix per relation. In cer-tain applications—such as applications on knowledge graphs with many distinctrelations—this increase in parameters can lead to overfitting and slow learning.Schlichtkrull et al. [2017] propose a scheme to combat this issue by parametersharing with basis matrices, where

W⌧ =bX

i=1

↵i,⌧Bi. (4.32)

In this basis matrix approach, all the relation matrices are defined as linearcombinations of b basis matrices B1, ...,Bb, and the only relation-specific pa-rameters are the b combination weights ↵1,⌧ , ..., ↵b,⌧ for each relation ⌧ . In thisbasis sharing approach, we can thus rewrite the full aggregation function as

mN (u) =X

⌧2R

X

v2N⌧ (u)

↵⌧ ⇥1 B ⇥2 hv

fn(N (u), N (v)), (4.33)

where B = (B1, ...,Bb) is a tensor formed by stacking the basis matrices, ↵⌧ =(↵1,⌧ , ..., ↵b,⌧ ) is a vector containing the basis combination weights for relation⌧ , and ⇥i denotes a tensor product along mode i. Thus, an alternative view ofthe parameter sharing RGCN approach is that we are learning an embeddingfor 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, werefer to approaches that define separate aggregation matrices per relation asrelational graph neural networks. For example, a variation of this approachwithout parameter sharing is deployed by Zitnik et al. [2018] to model a multi-relational dataset relating drugs, diseases and proteins, and a similar strategyis leveraged by Marcheggiani and Titov [2017] to analyze linguistic dependency

Page 17: The Graph Neural Network Model - McGill University School

4.5. GRAPH POOLING 69

graphs. Other works have found success combining the RGCN-style aggregationwith attention [Teru and Hamilton, 2019].

In a recent extension, Vashishth et al. [2019] also proposed to augment thisgeneral strategy by leveraging the multi-relational decoders discussed in Chapter3. In particular, they define the aggregation as

mN (u) =X

⌧2R

X

v2N⌧ (u)

W⌧ ⇥ dec(hv, ⌧, ·)fn(N (u), N (v))

, (4.34)

where we use dec(hv, ⌧, ·) : Rd ⇥ R ⇥ Rd ! Rd to denote a partial applicationof one of the multi-relational decoders defined in Chapter 3. For example, if wewere using the TransE decoder then

decTransE(hv, ⌧, ·) = hv + r⌧ . (4.35)

Similarly, with the RESCAL decoder we would have

decRESCAL(hv, ⌧, ·) = R⌧hv. (4.36)

In general, the partial application of these multi-relational decoders is defined asthe transformation that is (implicitly) applied to one of the input node embed-dings before computing the final score. Vashishth et al. [2019] discuss severalinstantiations of this approach and note performance improvements comparedto a basic RGCN.

4.4.2 Attention and Feature Concatenation

The relational GNN approach, where we define a separate aggregation param-eter per relation, is applicable for multi-relational graphs and cases where wehave discrete edge features. To accommodate cases where we have more generalforms of edge features, we can leverage these features in attention or by concate-nating this information with the neighbor embeddings during message passing.For example, given any base aggregation approach AGGREGATEbase one simplestrategy to leverage edge features is to define a new aggregation function as

mN (u) = AGGREGATEbase({hv � e(u,⌧,v), 8v 2 N (u)}), (4.37)

where e(u,⌧,v) denotes an arbitrary vector-valued feature for the edge (u, ⌧, v).This approach is simple and general, and has seen recent success with attention-based approaches as the base aggregation function [Sinha et al., 2019].

4.5 Graph Pooling

The neural message passing approach produces a set of node embeddings, butwhat if we want to make predictions at the graph level? In other words, wehave been assuming that the goal is to learn node representations zu, 8u 2 V ,but what if we to learn an embedding zG for the entire graph G? This task isoften referred to as graph pooling, since our goal is to pool together the nodeembeddings in order to learn an embedding of the entire graph.

Page 18: The Graph Neural Network Model - McGill University School

70 CHAPTER 4. THE GRAPH NEURAL NETWORK MODEL

Set pooling approaches

Similar to the AGGREGATE operator, the task of graph pooling can be viewedas a problem of learning over sets. We want to design a pooling function fp,which maps a set of node embeddings {z1, ..., z|V |} to an embedding zG thatrepresents the full graph. Indeed, any of the approaches discussed in Section4.2.2 for learning over sets of neighbor embeddings can also be employed forpooling at the graph level, and the theoretical analysis of Zaheer et al. [2017]on set-based learning still applies here.

In practice, there are two approaches that are most commonly applied forlearning graph-level embeddings via set pooling. The first approach is simplyto take a sum (or mean) of the node embeddings:

zG =

Pv2V zc

fn(|V|) , (4.38)

where fn is some normalizing function (e.g., the identity function). While quitesimple, pooling based on the sum or mean of the node embeddings is oftensu�cient for applications involving small graphs (e.g., predicting properties frommolecular graphs).

The second popular set-based approach uses a combination of LSTMs andattention to pool in a more complex manner, in a manner inspired by the workof 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 iteratedfor t = 1, ..., T steps:

qi = LSTM(ot�1,qt�1), (4.39)

ev,t = fa(zv,qt), 8v 2 V, (4.40)

av,t =exp(ev,i)P

u2V eu,t, 8v 2 V, (4.41)

ot =X

v2Vav,tzv. (4.42)

In the above equations, the qt vector represents a query vector for the attentionat each iteration t. In Equation (4.40), the query vector is used to compute anattention score over each node using an attention function fa : Rd⇥Rd ! R (e.g.,a dot product), and this attention score is then normalized in Equation (4.41).Finally, in Equation (4.42) a weighted sum of the node embeddings is computedbased on the attention weights, and this weighted sum is used to update thequery vector using an LSTM update (Equation 4.39). Generally the q0 and o0

vectors are initialized with all-zero values, and after iterating Equations 4.39-4.42 for T iterations, an embedding for the full graph is computed as

zG = o1 � o2 � ... � oT . (4.43)

This approach represents a sophisticated architecture for attention-based pool-ing over a set, and it has become a popular pooling method in many graph-levelclassification tasks.

Page 19: The Graph Neural Network Model - McGill University School

4.5. GRAPH POOLING 71

Figure 4.2: Illustration of the graph coarsening approach. At each hierarchicallevel, the nodes in the graph are assigned to di↵erent clusters based on theirlearned embeddings. A new graph is then formed based on these clusters, wherethe nodes in the graph at layer l correspond to clusters in layer l � 1. GNNsare used to process the graphs at the di↵erent hierarchical layers. Image takenfrom Ying et al. [2018b].

Graph coarsening approaches

One limitation of the set pooling approaches is that they do not exploit the struc-ture of the graph. While it is reasonable to consider the task of graph poolingas simply a set learning problem, there can also be benefits from exploitingthe graph topology at the pooling stage. One popular strategy to accomplishthis is to perform graph clustering or coarsening as a means to pool the noderepresentations.

In these style of approaches, we assume that we have some clustering function

fc ! G ⇥ R|V |⇥d ! R+|V |⇥c, (4.44)

which maps all the nodes in the graph to an assignment over c clusters. In partic-ular, we presume that this function outputs an assignment matrix S = fc(G,Z),where S[u, i] 2 R+ denotes the strength of the association between node u

and cluster i. One simple example of fc function would be spectral clusteringapproach described in Chapter 1, where the cluster assignment is based on thespectral decomposition of the graph adjacency matrix. Note that using a simplespectral clustering approach would ignore the node embedding (i.e., Z) inputto the cluster function fc(G,Z) and generate a hard cluster assignment with abinary assignment matrix S 2 Z|V |⇥c. However, as a more complex definitionof fc one can actually employ another GNN to learn the cluster assignments,where the node embeddings Z are used as input to the GNN [Ying et al., 2018b].In this GNN approach, one would generally apply a softmax function after thefinal GNN layer to output probabilistic cluster assignments.

Regardless of the approach used to generate the cluster assignment matrixS, the key idea of graph coarsening approaches is that we then use this matrixto coarsen the graph. In particular, we use the assignment matrix to computea new coarsened adjacency matrix

Anew = S>AS 2 R+c⇥c (4.45)

Page 20: The Graph Neural Network Model - McGill University School

72 CHAPTER 4. THE GRAPH NEURAL NETWORK MODEL

and a new set of node features

Xnew = S>X 2 Rc⇥d. (4.46)

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 matrixrepresents 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 coarseningprocess for a number of iterations, where the size of the graph is decreased ateach step. The final representation of the graph is then computed by a setpooling over the embeddings of the nodes in a su�ciently coarsened graph.Figure 4.2 illustrates this idea.

This coarsening based approach is inspired by the pooling approaches usedin convolutional neural networks (CNNs), and it relies on the intuition that wecan build hierarchical GNNs that operate on di↵erent granularities of the inputgraph. In practice, these coarsening approaches can lead to strong performance,but they can also be unstable and di�cult to train. For example, in orderto have the entire learning process be end-to-end di↵erentiable the clusteringfunctions fc must be di↵erentiable, which rules out most o↵-the-shelf clusteringalgorithms such as spectral clustering. Cangea et al. [2018] provides an insightfulcomparison and discussion of di↵erent approaches in this domain, highlightingthe benefits of learning sparse cluster assignments and some of the challengesin implementing these coarsening approaches.