# Session 10 — Python demos

Small, self-contained scripts that illustrate ideas from `10_gnn.html`
and the GNN slide deck.

## Setup

```bash
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
```

## Demos

### `demo_d1_gcn_node_classification.py`  /  `.ipynb`
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 you can compare them directly:

| | DeepWalk (sess. 08) | GCN (this demo) |
|---|---|---|
| Supervision | Unsupervised (walks) | Semi-supervised (CE) |
| Uses node features? | No | Yes |
| Inductive on new nodes? | No | Yes |
| Forward pass | Embedding lookup | Message passing |

The script trains a featureless GCN (`X = I`) with **only 4 labels per
community** (12 of 60 nodes), snapshots the hidden-layer state every
few epochs, and projects it to 2D with PCA so the class can watch the
representation form. Caps off with a held-out community-prediction
accuracy of ~92%.

```bash
python demo_d1_gcn_node_classification.py
# → fig_gcn_evolution.png
```

The notebook version adds:

- a deeper walk-through of why $\hat A = D^{-1/2}(A+I)D^{-1/2}$ looks
  the way it does (self-loops, symmetric normalisation),
- a label-sweep experiment showing held-out accuracy as a function of
  labels-per-community (1 label/community → ~82%, 7 → ~96%),
- a discussion of message passing as graph convolution, oversmoothing,
  and the GAT / GraphSAGE / heterogeneous-GNN extensions.
