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.
Link prediction completes knowledge graphs, recommends items and connections, and flags unexpected links in communication or power networks. Graph autoencoders do it without labels.
- 1. A graph autoencoder reconstructs…
- 2. Two nodes are predicted linked when their codes…
- 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.
- 1. σ(z_iᵀz_j) for orthogonal codes:
- 2. Positive weight for 4 nodes with 2 directed edge entries:
- 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
GAEandVGAEwrappers withrecon_loss(negative sampling) andtest(AUC, average precision), plusRandomLinkSplitfor 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)- 1. PyG utility for edge splits:
- 2. On large graphs, train with…
- 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.
- 1. The inner-product decoder models a…
- 2. Hidden edges during training count as…
- 3. Inner products struggle with…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How well can a GAE predict hidden links, and when does it overfit?
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.
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
- T. N. Kipf and M. Welling (2016). “Variational graph auto-encoders.” NeurIPS Workshop on Bayesian Deep Learning.
- M. Zhang and Y. Chen (2018). “Link prediction based on graph neural networks.” NeurIPS.
- D. Liben-Nowell and J. Kleinberg (2007). “The link-prediction problem for social networks.” JASIST 58.