Trains an R-GCN on the AIFB RDF graph to predict a person's research group, then explains the predictions with GNNExplainer.
- Python 3.12
- Dependencies in
requirements.txt
conda create -n xai26-mini python=3.12
conda activate xai26-mini
pip install -r requirements.txtThe notebook also installs torch-geometric and downloads the dataset in its first cells, so it
runs on a fresh Google Colab session without local setup.
Open MiniProject.ipynb and run Kernel → Restart & Run All. Cells must run top to bottom, as
later cells reuse variables from earlier ones. No GPU needed; a full run takes a few minutes on CPU.
Running the notebook downloads aifb-hetero.zip and saves three figures:
explanation_subgraph.png, ablation_results.png, class_distribution.png.
- Setup — installs
torch-geometric, downloads and unzips the AIFB dataset, and consolidates all imports into one cell. - Data loading — loads the AIFB RDF graph into an
rdflib.Graph. - Data analysis — basic statistics (subjects, predicates, objects, most frequent predicates), the class distribution over the five research groups, and the node-type distribution.
- Label extraction — finds all
Personnodes, maps each to its research group via theaffiliationpredicate, and builds the label tensor plus a mask of labeled nodes. - Graph construction — extracts the relevant relations, builds a single unified node index,
rebuilds the edge index and edge types, assembles the PyG
Dataobject with identity node features, and creates a reproducible 80/20 train/test split. - Model definition and training — a two-layer R-GCN (
FastRGCNConv) trained for 500 epochs. - Model evaluation — Accuracy, Precision, Recall and F1 on the training and test set.
- Class-imbalance analysis — quantifies the 73:1 imbalance and reports per-class test
performance; saves
class_distribution.png. - Explanation (GNNExplainer) — explains one example person node (edge mask only) and maps the most important edges back to human-readable names, titles and relations.
- Fidelity evaluation — computes Fidelity+ and Fidelity− for the example node and averaged over several test nodes.
- Visualization — renders the explained subgraph with readable labels; saves
explanation_subgraph.png. - Relation-type ablation — re-trains the model with individual relations removed to measure their
contribution; saves
ablation_results.png. - Interpretation — markdown discussion of the fidelity and ablation results.