Skip to content

Repository files navigation

XAI Mini Project — Explaining R-GCN Predictions on AIFB

Trains an R-GCN on the AIFB RDF graph to predict a person's research group, then explains the predictions with GNNExplainer.

Requirements

  • Python 3.12
  • Dependencies in requirements.txt

Setup

conda create -n xai26-mini python=3.12
conda activate xai26-mini
pip install -r requirements.txt

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

Run

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.

Output

Running the notebook downloads aifb-hetero.zip and saves three figures: explanation_subgraph.png, ablation_results.png, class_distribution.png.

Notebook sections

  • 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 Person nodes, maps each to its research group via the affiliation predicate, 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 Data object 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.

Report

Read the full report (PDF)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages