Foundations to Frontier
Tests
E. Deep Learning › E14 Graph Neural Networks

Graph autoencoders (GAE, VGAE)

Graph autoencoders (Kipf and Welling, 2016) learn node embeddings without labels by reconstructing the graph. A GCN encoder maps nodes to vectors z_i, and an inner-product decoder scores every pair as σ(z_iᵀz_j). The variational version (VGAE) makes the encoder output a Gaussian per node and adds a KL term, as in a VAE. Trained on the visible edges, they predict missing links, a core task in recommendation, knowledge graphs and network monitoring. This page covers the encoder–decoder design, the weighted reconstruction loss, AUC evaluation and the VGAE. In the exercises you implement the decoder and AUC, then hide 15% of the edges of a 4-community graph and predict them without node features. Common neighbours scored AUC 0.57, a GAE 0.79, and knowing the true communities 0.81. A 16-dimensional GAE trained too long memorised the training graph and fell back to 0.57.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Rebuild the graph from compact codes

A graph autoencoder gives every node a short vector by running a GNN over the graph. It then tries to rebuild the graph: two nodes should be linked if their vectors point the same way. Trained on the links we can see, it can then guess the links we cannot see, such as a missing friendship, an unrecorded interaction or a failing connection. The demo shows how a node’s information spreads through the GNN encoder.

Graph neural network lab
01234567891011
After 2 rounds, node 0 has received information from 6 of 12 nodes: its 2-hop neighbourhood. A GNN with k layers cannot see further.
Why engineers care

Link prediction completes knowledge graphs, recommends items and connections, and flags unexpected links in communication or power networks. Graph autoencoders do it without labels.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A graph autoencoder reconstructs…
  2. 2. Two nodes are predicted linked when their codes…
  3. 3. A main use is…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Encoder: Z = GCN(A, X), for example  ReLU(ÂXW₁)W₂.
  • Decoder: P(A_ij = 1) = σ(z_iᵀ z_j). Orthogonal codes give σ(0) = 0.5.
  • Loss: binary cross-entropy over all pairs.
    • Edges are rare, so positives are up-weighted by (n² − |E|)/|E|.
    • With 4 nodes and one edge (2 directed entries), the weight is (16 − 2)/2 = 7.
  • VGAE: the encoder outputs μ_i and log σ_i², samples z_i = μ_i + σ_i ε, and adds the KL term to N(0, I).
  • Evaluation:
    • hide a fraction of edges (here 15%: 91 of 608), plus an equal number of random non-edges;
    • report AUC, the probability that a hidden edge outscores a non-edge. Scores (0.9, 0.4) against (0.5, 0.1) give AUC 3/4.
📝 Quick check (Level 1)
0/3 answered
  1. 1. σ(z_iᵀz_j) for orthogonal codes:
  2. 2. Positive weight for 4 nodes with 2 directed edge entries:
  3. 3. AUC of 0.5 means…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Graph autoencoders in code

Exercise 1.

  • The inner-product decoder, the positive-pair weight and AUC were implemented and checked on small cases.

Practice.

  • PyTorch Geometric provides GAE and VGAE wrappers with recon_loss (negative sampling) and test (AUC, average precision), plus RandomLinkSplit for edge splits.
  • Use negative sampling instead of all n² pairs on large graphs.
  • Keep codes small or stop early: test edges are absent from the training graph, so an over-flexible model learns to predict them as non-edges.
from torch_geometric.nn import GAE, GCNConv
class Enc(nn.Module):
    def __init__(self, d_in, d):
        super().__init__(); self.c1 = GCNConv(d_in, 2 * d); self.c2 = GCNConv(2 * d, d)
    def forward(self, x, ei): return self.c2(F.relu(self.c1(x, ei)), ei)
model = GAE(Enc(d_in, 16))
z = model.encode(x, train_pos_edge_index); loss = model.recon_loss(z, train_pos_edge_index)
🐍 Exercise 1: decoder and evaluation
Implement the inner-product decoder, the positive-pair weight and AUC.
📝 Quick check (Level 2)
0/3 answered
  1. 1. PyG utility for edge splits:
  2. 2. On large graphs, train with…
  3. 3. Over-flexible GAEs tend to…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

What the inner product can represent.

  • σ(z_iᵀz_j) models a low-rank, symmetric edge probability matrix.
  • It captures community structure (similar codes within a community) and degree-like effects, but it cannot naturally express “opposites attract” (bipartite, heterophilous graphs) without extra structure.

Hidden edges as negatives.

  • During training, held-out edges appear as non-edges. A model with enough capacity (a large code, per-node features, long training) can fit the training graph exactly and push hidden edges toward zero, the same overfitting seen in matrix completion.
  • A low-dimensional code or early stopping forces it to generalise from structure instead.

Ceilings. If edges depend only on community membership, no method can rank within-community non-edges below hidden within-community edges. Perfect community knowledge sets the maximum achievable AUC.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The inner-product decoder models a…
  2. 2. Hidden edges during training count as…
  3. 3. Inner products struggle with…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

History.

  • T. N. Kipf and M. Welling, “Variational graph auto-encoders” (NeurIPS Bayesian Deep Learning workshop, 2016), with AUC around 0.91 on citation graphs.
  • Later: ARGA (adversarially regularised, 2018), SEAL (subgraph-based link prediction, 2018).

Exercise 2.

  • Graph: 4 communities, 200 nodes, 608 edges. 15% of the edges (91) are hidden, plus 91 random non-edges.
  • Models: no node features (identity input). Compared:
    • common neighbours;
    • a GAE with a 16-dimensional code trained for 50 or 400 steps;
    • a GAE with a 2-dimensional code trained for 200 steps;
    • an oracle that knows the true communities.
method test AUC
common neighbours 0.571
GAE, 16-D code, 50 steps 0.788
GAE, 16-D code, 400 steps 0.571
GAE, 2-D code, 200 steps 0.791
community oracle (ceiling) 0.813
  • The GAE nearly reaches the ceiling: 0.79 against the 0.81 achievable from perfect community knowledge, far above common neighbours (0.57). The graph is sparse (average degree about 6), so most node pairs share no neighbours at all, and the common-neighbours count is uninformative.
  • Wide codes memorise: with 16 dimensions, 400 steps of training drove AUC back down to 0.57. The model learned the training graph exactly, and the hidden edges, which were non-edges during training, were predicted as non-edges.
  • A 2-dimensional code cannot memorise, so it stays near the ceiling however long it trains.
  • Seeds: seeds 1 and 2 gave common neighbours 0.55 and 0.55, GAE 2-D 0.79 and 0.73, 16-D long 0.66 and 0.66, oracle 0.79 and 0.77.
🐍 Exercise 2 (research): how well can a GAE predict hidden links, and when does it overfit?
Hide edges of a community graph, train GAEs with different code sizes and training lengths, and compare with common neighbours and a community oracle.

Graph autoencoders in AI, robotics and aerospace

  • Knowledge graphs: completing missing relations between components, failures and causes in maintenance records.
  • Network monitoring: links that the model finds very unlikely flag misconfigurations or intrusions.
  • Design lesson: in link prediction, held-out edges are disguised as negatives during training. Control capacity, use a validation split, and compare against simple heuristics and achievable ceilings.

References

  1. T. N. Kipf and M. Welling (2016). “Variational graph auto-encoders.” NeurIPS Workshop on Bayesian Deep Learning.
  2. M. Zhang and Y. Chen (2018). “Link prediction based on graph neural networks.” NeurIPS.
  3. D. Liben-Nowell and J. Kleinberg (2007). “The link-prediction problem for social networks.” JASIST 58.