How GNNs learn node representations that reveal community structure in citation networks.
This project trains GCN, GAT, and GraphSAGE on the Cora citation network and demonstrates that GNN-learned embeddings capture community structure 4.5x better than raw features (NMI: 0.13 → 0.59).
| Model | Test Accuracy | Macro F1 | Cluster NMI | Parameters |
|---|---|---|---|---|
| GAT | 81.8% | 80.2% | 0.59 | 92K |
| GCN | 78.5% | 77.4% | 0.57 | 188K |
| GraphSAGE | 72.6% | 72.7% | 0.58 | 192K |
| Raw Features | — | — | 0.13 | — |
- Message passing works: GNNs exploit the 81% homophily in citation networks — papers cite papers in the same field
- Attention matters: GAT outperforms by learning which neighbors are most informative
- Embeddings cluster cleanly: GNN representations form tight, well-separated clusters useful for downstream tasks like link prediction and recommendation
The interactive website features:
- Force-directed network visualization with hover interactions
- Switchable t-SNE embedding views (Raw Features → GCN → GAT → GraphSAGE)
- Training dynamics charts
- Community detection comparison
- Per-class confusion matrices
Full training pipeline with Plotly visualizations — runs on free T4 GPU.
pip install -r requirements.txt
python3 train_gnn.py
# Open docs/index.html in your browser├── train_gnn.py # Training script — GCN, GAT, GraphSAGE
├── GNN_Social_Network_Analysis.ipynb # Google Colab notebook
├── docs/
│ ├── index.html # Interactive visualization website
│ └── results.json # Training results & embeddings
├── requirements.txt
└── README.md
The Cora citation network contains 2,708 scientific papers classified into 7 research areas (Neural Networks, Genetic Algorithms, etc.), connected by 5,278 undirected citation links (5,429 directed citations). Each paper has a 1,433-dimensional bag-of-words feature vector.
GCN (Graph Convolutional Network) — Spectral convolution that averages neighbor features with skip connections for gradient flow.
GAT (Graph Attention Network) — Learns attention weights per neighbor, so important citations contribute more than tangential ones. Uses 8 attention heads.
GraphSAGE — Inductive learning through sampling and aggregation. Can generalize to unseen nodes without retraining.
Raw bag-of-words features don't capture who cites whom. GNNs propagate information through the graph via message passing — each layer aggregates 1-hop neighborhood information, so a 2-layer GNN sees 2-hop context. Since 81% of citations connect same-class papers, this neighborhood signal is extremely informative.
MIT