Search

Search papers and lessons

Graph Convolutional Network

Level 4 · 11 min read

A graph convolutional network updates each node's features by averaging its neighbours' features, applying a learned linear map and a ReLU, and repeating, so the output reflects the graph's structure.

On this page

  • Colour = topic mix
  • Linear algebra
  • Discrete math
  • Neural network basics
  • Architectures
  • Sign in to see your progress

TL;DR

A graph convolutional network, or GCN, is a neural network for data that lives on a graph: people in a social network, papers in a citation network, atoms in a molecule. Each layer replaces every node's feature vector with a weighted average of its own features and its neighbours' features, multiplies by a learned weight matrix, and applies a nonlinearity. Stacking layers lets information travel one edge further per layer.

Where you'll see it: semi-supervised node classification on citation networks, molecular property prediction, recommendation over user-item graphs, and as a building block in many graph neural network architectures.

Intuition

Averaging over neighbours

Suppose each node in a citation network has a bag-of-words vector describing its paper. A paper's topic is hard to guess from its own words alone, but its citations say a lot. Papers that cite each other often share a topic. So a sensible first step is to replace each paper's vector with the average of its own vector and the vectors of the papers it cites or is cited by. Then let a neural network learn what to do with the averaged vector.

That is the whole idea. A GCN layer does one round of neighbourhood averaging, then one ordinary neural-network layer. Two layers mean each node sees its neighbours' neighbours. Three layers reach three hops out.

Why a plain network does not work here

An image convolution works because every pixel has the same grid of neighbours in the same positions, so one small filter can be slid across the whole image. A graph has no such grid. One node may have two neighbours and another two hundred, and there is no fixed left or right or up. A convolutional network cannot be applied directly.

A feedforward network fails differently. If you feed in each node's features alone, it ignores the edges entirely. If you feed in the whole adjacency matrix as input, the number of inputs grows with the square of the number of nodes and the model cannot be reused on a different graph.

A GCN takes the middle path. It uses one weight matrix shared by all nodes, and it mixes in neighbours through a fixed, graph-dependent averaging matrix. The same weights work on any graph, and the cost of a layer grows with the number of edges rather than the square of the number of nodes.

flowchart LR
  A[Node features X] --> B[Average over neighbours and self]
  G[Graph structure A] --> B
  B --> C[Linear map W]
  C --> D[ReLU]
  D --> E[Hidden features]
  E --> F[Repeat for more hops]
  F --> H[Output: class per node]

The math

Setup

Start with an undirected graph on NN nodes. Its adjacency matrix AA is an N×NN \times N matrix with Aij=1A_{ij} = 1 when nodes ii and jj share an edge and 00 otherwise. Each node has a feature vector, and we stack them as the rows of a matrix X∈RN×CX \in \mathbb{R}^{N \times C}, where CC is the number of input features.

Two modifications to AA come first. The first adds self-loops, so each node also counts itself:

A~=A+IN,\tilde{A} = A + I_N,

where INI_N is the identity matrix. The second is the degree matrix of A~\tilde{A}, a diagonal matrix whose entries are row sums:

D~ii=∑jA~ij.\tilde{D}_{ii} = \sum_j \tilde{A}_{ij}.

The degree of a node is how many neighbours it has, counting itself. Without normalisation, a node with many neighbours would get a large sum and a node with few would get a small one. Dividing by degrees fixes that scale problem.

From spectral filters to a layer

The original motivation comes from signal processing on graphs. Let DD be the degree matrix of AA itself (no self-loops). Define the normalised graph Laplacian L=IN−D−1/2AD−1/2L = I_N - D^{-1/2} A D^{-1/2} (see graph Laplacian). Its eigenvectors play the role that sines and cosines play for ordinary signals, and filtering a signal means reweighting its components by a function of the eigenvalues. Computing those eigenvectors is expensive on large graphs, so Hammond et al. approximated the filter by a truncated Chebyshev polynomial in LL of order KK. That makes the filter KK-localised: it only touches nodes at most KK edges away.

Kipf and Welling set K=1K = 1 and simplify further. They approximate the largest eigenvalue of LL by 22, which leaves a filter of the form θ0x+θ1(L−IN)x\theta_0 x + \theta_1 (L - I_N) x. They then tie the two parameters to a single parameter θ\theta, giving

gθ⋆x≈θ(IN+D−1/2AD−1/2)x.g_\theta \star x \approx \theta \left(I_N + D^{-1/2} A D^{-1/2}\right) x.

The operator in brackets has eigenvalues in [0,2][0, 2]. Applied many times, that range makes activations and gradients explode or vanish. The fix is the renormalisation trick: replace IN+D−1/2AD−1/2I_N + D^{-1/2} A D^{-1/2} by the single matrix

A^=D~−1/2A~D~−1/2.\hat{A} = \tilde{D}^{-1/2} \tilde{A} \tilde{D}^{-1/2}.

Its eigenvalues lie in (−1,1](-1, 1], which keeps repeated application stable. Each entry is

A^ij=A~ijD~ii D~jj,\hat{A}_{ij} = \frac{\tilde{A}_{ij}}{\sqrt{\tilde{D}_{ii}\,\tilde{D}_{jj}}},

so a neighbour's contribution is scaled down when either node has many neighbours.

The layer rule

A GCN layer maps the features at layer ll to layer l+1l+1:

H(l+1)=σ(A^ H(l)W(l)).H^{(l+1)} = \sigma\left(\hat{A}\, H^{(l)} W^{(l)}\right).

Here H(0)=XH^{(0)} = X, W(l)W^{(l)} is a learned weight matrix, and σ\sigma is an activation such as ReLU(z)=max⁡(0,z)\mathrm{ReLU}(z) = \max(0, z). Read it from right to left: multiply by weights to change the features, multiply by A^\hat{A} to mix each node with its neighbours, apply the activation. Some presentations swap the order of the two multiplications. The result is the same up to the placement of the weights.

A two-layer node classifier

For semi-supervised classification the paper uses two layers and a softmax output:

Z=softmax(A^ ReLU(A^XW(0))W(1)).Z = \mathrm{softmax}\left(\hat{A}\, \mathrm{ReLU}\left(\hat{A} X W^{(0)}\right) W^{(1)}\right).

Row ii of ZZ is a probability distribution over classes for node ii. Only some nodes have labels. The loss is the cross-entropy summed over labelled nodes only:

L=−∑l∈YL∑fYlfln⁡Zlf,\mathcal{L} = -\sum_{l \in \mathcal{Y}_L} \sum_{f} Y_{lf} \ln Z_{lf},

where YL\mathcal{Y}_L is the set of labelled node indices and YlfY_{lf} is 1 when node ll has class ff. Unlabelled nodes still influence training, because their features pass through A^\hat{A} into the hidden layer that labelled nodes use. That is how the model learns from the structure of the whole graph with few labels.

The cost of one propagation step is proportional to the number of edges, since A^\hat{A} is sparse and the product with a dense feature matrix touches only the nonzero entries. The paper reports a complexity of O(∣E∣CHF)\mathcal{O}(|\mathcal{E}| C H F) for the full two-layer model, with HH hidden units and FF output classes.

Worked examples

Example
One layer on a three-node path

Take a path of three nodes, 1−2−31 - 2 - 3. Its adjacency matrix and self-loop version are

A=(010101010),A~=(110111011).A = \begin{pmatrix} 0 & 1 & 0 \\ 1 & 0 & 1 \\ 0 & 1 & 0 \end{pmatrix}, \qquad \tilde{A} = \begin{pmatrix} 1 & 1 & 0 \\ 1 & 1 & 1 \\ 0 & 1 & 1 \end{pmatrix}.
  1. Row sums of A~\tilde{A} give the degrees: D~=diag(2,3,2)\tilde{D} = \mathrm{diag}(2, 3, 2).
  2. Each entry of A^\hat{A} is A~ij/D~iiD~jj\tilde{A}_{ij} / \sqrt{\tilde{D}_{ii} \tilde{D}_{jj}}. The diagonal gives A^11=1/2=0.5\hat{A}_{11} = 1/2 = 0.5, A^22=1/3≈0.333\hat{A}_{22} = 1/3 \approx 0.333, and A^33=0.5\hat{A}_{33} = 0.5.
  3. The off-diagonal entries are A^12=A^23=1/2⋅3≈0.408\hat{A}_{12} = \hat{A}_{23} = 1/\sqrt{2 \cdot 3} \approx 0.408, and A^13=0\hat{A}_{13} = 0 because nodes 1 and 3 are not adjacent.
  4. Give each node one scalar feature: X=(1,2,3)⊤X = (1, 2, 3)^\top. Use one weight, W=1W = 1, and skip the activation to isolate the averaging.
  5. Node 1: 0.5⋅1+0.408⋅2+0⋅3≈1.3170.5 \cdot 1 + 0.408 \cdot 2 + 0 \cdot 3 \approx 1.317.
  6. Node 2: 0.408⋅1+0.333⋅2+0.408⋅3≈2.3000.408 \cdot 1 + 0.333 \cdot 2 + 0.408 \cdot 3 \approx 2.300.
  7. Node 3: 0⋅1+0.408⋅2+0.5⋅3≈2.3170 \cdot 1 + 0.408 \cdot 2 + 0.5 \cdot 3 \approx 2.317.

Interpretation: node 1 started at 1 and has moved toward its only neighbour, node 2, which had value 2. Node 2 sits in the middle and its value is pulled toward both ends. Node 3 is pulled toward node 2 but keeps most of its own value, because its degree is small. The rule does exactly what a smoothing filter should: it mixes values along edges, and it does so with weights that depend on degree.

Example
Size of a two-layer model on Cora

Cora is a citation network with N=2,708N = 2{,}708 papers, 1,433 word features per paper and 7 topics. A two-layer GCN with H=16H = 16 hidden units has these weight matrices:

  1. W(0)W^{(0)} is 1,433×161{,}433 \times 16, which is 22,92822{,}928 weights.
  2. W(1)W^{(1)} is 16×716 \times 7, which is 112112 weights.
  3. The total is 23,04023{,}040 weights, independent of NN.

The same weights apply to any graph with 1,433 input features. The graph enters only through A^\hat{A}, which is computed once in preprocessing. A model with separate weights per node would grow with NN, and nothing in it would tie one node's computation to its neighbours.

The paper's reported accuracy on Cora, using 140 labelled papers (20 per class) and 1,000 test papers, is 81.5 percent. Its results table lists 75.1 percent for the ICA baseline and 75.7 percent for Planetoid. These are the authors' numbers, under their split and hyperparameters.

Tradeoffs and failure modes

SituationWhat goes wrongBetter choice
Graph is dense, or very large with high-degree hubsAveraging washes out node identity; a hub's neighbourhood dominatesSampling-based methods such as GraphSAGE, which sample a fixed number of neighbours
Deep stacks (more than 3 or 4 layers)Node features converge to the same vector (oversmoothing) and accuracy fallsKeep the model shallow, add residual connections, or use jumping-knowledge style skip connections
Edges carry direction, type or weightThe symmetric normalisation ignores direction and relation typeDirected or relational GCNs, or attention-based models
The graph is noisy or edges are wrongErrors propagate to every neighbourLearn edge weights, or prune edges before training
The task depends on distant nodesEach layer reaches only one more hopGlobal pooling or transformer-style attention over all nodes
Graphs with no shared node set (inductive setting, new nodes at test time)Transductive GCN assumes the whole graph is known in advanceInductive variants such as GraphSAGE

The key tradeoff is simplicity against expressiveness. The layer is a single matrix product and a nonlinearity, which makes it fast and easy to train, but it can only do smoothing with learned weights. Models that need sharper, edge-specific behaviour give up some of that speed.

History

Bruna and colleagues proposed spectral graph convolutions in 2013, using the eigenvectors of the graph Laplacian as a Fourier basis. The method was general but needed a full eigendecomposition, which does not scale. Defferrard, Bresson and Vandergheynst (2016) replaced it with Chebyshev polynomial filters that are localised and cheap, which is the approximation the GCN paper starts from.

Thomas Kipf and Max Welling simplified this to the single-layer rule above and showed it works well for semi-supervised node classification. Their paper, posted to arXiv in 2016 and published at ICLR in 2017, made GCNs the default baseline for graph learning. Their experiments on the Cora, Citeseer and Pubmed citation networks and on the NELL knowledge graph helped make the citation networks standard benchmarks for later work. The paper is in the graph as the GCN paper.

Since then the same message-passing pattern has been generalised into a large family of graph neural networks, which is why the GCN is often taught as the simplest member of that family.

Check yourself

QuestionRecall: what does the self-loop term I_N in the tilde-A = A + I_N definition add to each node's update?Show answer

Each node includes its own features in the average, not only its neighbours'. Without it, a node's new value would depend only on its neighbours, and an isolated node would have a zero row in A, so it would lose its own features entirely.

QuestionComputation: a node has degree 3 in the self-loop graph and a neighbour has degree 8. Their edge is present (A-tilde entry 1). What is the weight of that neighbour in A-hat?Show answer

The weight is 1 divided by the square root of 3 times 8, which is 1 over the square root of 24. That is about 0.204. The neighbour contributes less than it would if both degrees were equal, because a high-degree neighbour spreads its influence over many nodes.

QuestionWhy: why does the GCN use one shared weight matrix per layer instead of a separate weight matrix for each node?Show answer

A separate matrix per node would have parameters tied to specific nodes, so the model could not be applied to a new graph and would need more data than a sparsely labelled graph provides. A shared matrix keeps the parameter count fixed as the graph grows, and the graph structure enters through A-hat, so the same weights adapt to any neighbourhood.

QuestionApplied: you train a GCN with four layers on a social network and every node ends up with almost the same predicted class. What is the likely cause and one fix?Show answer

The likely cause is oversmoothing: four rounds of neighbourhood averaging make node features converge, so they stop carrying node-specific information. A fix is to reduce the depth to two or three layers, or to add residual or skip connections that let each node keep its own earlier features.

Sources