Session 10
Graph Neural Networks
DRAFT: This content is under development. Check back closer to the course start date.
Learning Objectives
- Understand node embeddings and message passing in graph neural networks
- Compare GNN architectures: GCN, GraphSAGE, GAT and their tradeoffs
- Know when GNNs help and when simpler methods suffice
- Build a simple GNN for node classification using PyTorch Geometric
Topics
- Graph Neural Networks
- Message passing framework
- GCN, GraphSAGE, GAT
- Applications and tradeoffs
Hands-on demos
A Python demo that matches this lecture — runnable on a laptop in seconds. Code lives in docs/10_gnn/demos/.
D1 · A 2-layer GCN, from scratch
A 2-layer Graph Convolutional Network (Kipf & Welling 2017) trained from scratch on the same 3-community stochastic block model used in the session 08 DeepWalk demo, so the two methods can be compared directly. Featureless setup (X = I), only 4 labels per community (12 of 60 nodes), held-out test accuracy ~92%. Visualises the hidden-layer state via PCA so the class can watch message-passing build community structure.
- Notebook (.ipynb) — narrated, with a labels-sweep experiment (1 label/community → ~82%, 7 → ~96%) and discussion of message passing, oversmoothing, and the GAT / GraphSAGE / heterogeneous-GNN extensions
- Script (.py) — same code, saves
fig_gcn_evolution.png - README
How to run
One-time setup (creates a virtual environment in this folder):
cd docs/10_gnn/demos
python -m venv .venv
source .venv/bin/activate # on macOS / Linux
pip install -r requirements.txt
Open the notebook:
jupyter lab demo_d1_gcn_node_classification.ipynb
Or run the script directly to regenerate the figure:
python demo_d1_gcn_node_classification.py