Node Classification Lab

Node Classification Lab

Actually train GCN, GraphSAGE, GAT or GIN in your browser on the real karate network or a synthetic graph, with a training, validation and test split, the confusion matrix, accuracy, precision, recall and F1, and a comparison of runs.

Node classification is usually a transductive, semi-supervised task: we know the class of some nodes and want the class of the rest. The loss is computed on the training nodes only, the best epoch is chosen by validation accuracy, and the test set is touched only once at the end. Try the number of labelled nodes, the layers, dropout and the learning rate, and compare with an MLP that does not see the graph to learn what the structure added.

Equations

\hat{y}_i=\arg\max_c\ \mathrm{softmax}\!\left(f_\theta(X,A)\right)_{ic}
The predicted class of each node.
\mathrm{Acc}=\frac{1}{|T|}\sum_{i\in T}\mathbb{1}[\hat{y}_i=y_i],\quad F_1=\frac{2PR}{P+R}
Accuracy on the test set T, and F1, the harmonic mean of precision P and recall R (we show the macro average).

Loading the interactive lab…

Ready-made experiments

Real training (Actual Model Training)Beginner

GCN on the real karate network

Actually train a GCN on small real data with few labelled nodes, then read the accuracy and the confusion matrix honestly.

Data: Zachary Karate Club (34 nodes, two classes)

Run the experiment
Real training (Actual Model Training)Intermediate

What does overfitting look like?

To see the gap between training accuracy and test accuracy when there are very few labelled nodes and the model is large and unregularised.

Data: A declared synthetic citation graph (SBM)

Run the experiment
Real training (Actual Model Training)Advanced

Network depth and oversmoothing

To measure the effect of adding GCN layers on accuracy and on the similarity of node representations.

Data: A declared synthetic citation graph (SBM)

Run the experiment
Real training (Actual Model Training)Intermediate

What does GAT look at?

Train a GAT, then show the attention coefficients of a chosen node as the thickness of the edges.

Data: A declared synthetic citation graph (SBM)

Run the experiment
Real training (Actual Model Training)Advanced

R-GCN on an academic knowledge graph

Compare a model that distinguishes relation types (R-GCN) with a model that treats them all the same (GCN) on a small knowledge graph.

Data: A synthetic academic knowledge graph: papers, authors and conferences with three relations

Run the experiment

Concepts in this module

Frequently asked questions

What does semi-supervised node classification mean?

We know the labels of a few nodes and want the labels of the rest. The whole graph (including the unlabelled nodes) is used in message passing, but the loss is computed on the labelled nodes only. This is the setup of Kipf & Welling (2017) on Cora.

How do I avoid data leakage in node classification?

Do not use the labels of the validation or test nodes in the loss or in feature selection, choose the hyperparameters on validation, not on test, and do not normalise the features with statistics computed from the test set. Having the test nodes in the graph during training is acceptable in the transductive setup, because their labels are hidden.

Why does accuracy change so much from one run to another?

Because the test set is small: the karate network has about 20 test nodes, so each error changes the accuracy by about 5 points. Always report the mean and the standard deviation over several seeds, and do not conclude from a single run.

How do I read the confusion matrix?

The row is the true class and the column is the predicted class. The diagonal holds the correct predictions. A cell (i,j) off the diagonal means that nodes of class i were wrongly classified as j. Precision, recall and F1 for each class are computed from it.

Why do I use Macro-F1 together with accuracy?

Overall accuracy hides the model's weakness on small classes. Macro-F1 computes the F1 of each class and then averages them equally, so it reveals whether the model ignores a rare class.

How do I know the model is overfitting?

When training accuracy reaches nearly 100% while validation accuracy stalls or drops, and the training loss falls while the validation loss rises. Remedies: dropout, L2 regularisation, a smaller hidden size, and early stopping on validation.

What is the difference between transductive and inductive learning?

Transductive: the whole graph, including the test nodes, is available during training, with their labels hidden (the standard Cora). Inductive: the model must work on nodes or graphs it has never seen, as with GraphSAGE on new graphs.

What do I do if the nodes have no features?

You can use the identity matrix (a one-hot vector for each node), as in the karate experiment, but it does not generalise to new nodes. Alternatives: the degree, structural measures, Node2Vec embeddings, or the same constant vector for all nodes.

Implementation limits

Real training with backpropagation in the browser, up to 400 nodes. On small graphs the results change a lot with the seed and the split; run several seeds before drawing any conclusion. Cora and others run through the optional Python server.

References

  1. Kipf, T. N., & Welling, M. (2017). Semi-Supervised Classification with Graph Convolutional Networks. International Conference on Learning Representations (ICLR). arXiv: 1609.02907The original GCN paper and the source of symmetric matrix normalisation.
  2. Hamilton, W. L., Ying, R., & Leskovec, J. (2017). Inductive Representation Learning on Large Graphs. Advances in Neural Information Processing Systems (NeurIPS). arXiv: 1706.02216The original GraphSAGE paper, on inductive learning with neighbourhood sampling.
  3. Veličković, P., Cucurull, G., Casanova, A., Romero, A., Liò, P., & Bengio, Y. (2018). Graph Attention Networks. International Conference on Learning Representations (ICLR). arXiv: 1710.10903The original GAT paper, on multi-head attention over neighbours.
  4. Zachary, W. W. (1977). An Information Flow Model for Conflict and Fission in Small Groups. Journal of Anthropological Research. DOI: 10.1086/jar.33.4.3629752The source of the karate club network (34 members).
  5. Yang, Z., Cohen, W. W., & Salakhutdinov, R. (2016). Revisiting Semi-Supervised Learning with Graph Embeddings. International Conference on Machine Learning (ICML). arXiv: 1603.08861The source of the public (Planetoid) split for Cora, CiteSeer and PubMed.
  6. Shchur, O., Mumme, M., Bojchevski, A., & Günnemann, S. (2018). Pitfalls of Graph Neural Network Evaluation. NeurIPS 2018 Workshop on Relational Representation Learning. arXiv: 1811.05868Shows that the ranking of models changes when the split changes, and recommends multiple splits and seeds.
  7. Kingma, D. P., & Ba, J. (2015). Adam: A Method for Stochastic Optimization. International Conference on Learning Representations (ICLR). arXiv: 1412.6980The optimiser used in all the lab's training experiments.
  8. Huang, Q., He, H., Singh, A., Lim, S.-N., & Benson, A. R. (2021). Combining Label Propagation and Simple Models Out-performs Graph Neural Networks. International Conference on Learning Representations (ICLR). arXiv: 2010.13993C&S: strong simple baselines that should always be compared against.