Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Graph Neural Networks for Social Network Analysis

PyTorch PyG License Demo Open In Colab

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).

Results

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

Key Findings

  • 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

Interactive Demo

Live Website →

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

Run in Google Colab

Open Notebook →

Full training pipeline with Plotly visualizations — runs on free T4 GPU.

Local Setup

pip install -r requirements.txt
python3 train_gnn.py
# Open docs/index.html in your browser

Project Structure

├── 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

How It Works

The Network

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.

GNN Architectures

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.

Why GNNs Beat Feature-Only Methods

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.

License

MIT

About

GCN, GAT and GraphSAGE on the Cora citation network, with an interactive embedding/clustering site

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages