This is the code for our ICML 2023 paper Rethinking Explaining Graph Neural Networks via Non-parametric Subgraph Matching [arXiv][ICML]. We propose a novel non-parametric subgraph matching framework, dubbed MatchExplainer, to explore explanatory subgraphs. It couples the target graph with other counterpart instances and identifies the most crucial joint substructure by minimizing the node corresponding-based distance.
We rely on DIG to run the experiments. Before that, you need to install Pytorch and torch_geometric first. Please note that torch_geometric requires Pytorch >= 1.10
# CUDA 10.2
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.2 -c pytorch
# CUDA=cu102 TORCH=1.7.1
pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-geometric==1.7.0
# the latest version e.g., 0.1.18 does not support ConstraintBasedEstimator
pip install pgmpy==0.1.10Four datasets have been utilized in our experiments. The processed raw data for BA-3Motif is available at ReFine-BA3. The other two datasets MNIST and Mutagenicity will be automatically downloaded when training models. The last dataset VG-5 is generated by ReFine [1] and can be downloaded from Google Drive. Please make sure that the dictionary is arranged as follows, and cite the Visual Genome [2] if using VG-5.
data ---BA3
|------VG
|---raw
Before explaining GNNs, it is necessary to first train them. We have already provided trained GNNs in param/gnns for those four different tasks.
However, you can also retrain the model by calling:
cd gnns/
python ba3motif_gnn.py # change the name of the script for different datasetsIn order to call the MatchExplainer, you can directly run the following command. Notably, unlike PGExplainer [3] or ReFine [1],
MatchExplainer requires no additional training. You can set --dataset to ['vg', 'ba3', 'mutag', 'mnist'] to
evaluate on different tasks. You can also define different subgraph sizes by controlling the --ratio argument.
python main.py --dataset=xxxAfter that, you can also run visual.py to envision the results produced by MatchExplainer.
When implementing the code, you may encounter the following error as OSError: libcusparse.so.11: Cannot open shared object file.
Here we offer a potential solution to debug.
sudo apt update
sudo apt install mlocatelocate libcusparse.so.11
export PATH=/opt/conda/lib:$PATH
export LD_LIBRARY_PATH=/opt/conda/pkgs/cudatoolkit-11.1.1-h6406543_8/lib:$LD_LIBRARY_PATH
# for jupyter notebook
%env PATH=/opt/conda/lib:$PATH
%env LD_LIBRARY_PATH=/opt/conda/pkgs/cudatoolkit-11.1.1-h6406543_8/lib:$LD_LIBRARY_PATHExcept OSError, you might find undefined symbol (e.g., _ZN2at6detail20DynamicCUDAInterface10set_deviceE).
Just clear the pip cache and reinstall the respective package. You can refer to Frequently Asked Questions for more help.
If you find our paper helpful and interesting, please consider citing our paper. Thank you! :) Any kind of question is welcome, and you can directly pull an issue or email Fang WU. This work is highly supported by MindRank AI, a start-up AI drug discovery company in Hangzhou, and was done when Fang Wu was an intern there. We build our code based on ReFine and would like to thank Yuxin Wu for her open-source spirit.
@inproceedings{wu2023rethinking,
title={Rethinking explaining graph neural networks via non-parametric subgraph matching},
author={Wu, Fang and Li, Siyuan and Jin, Xurui and Jiang, Yinghui and Radev, Dragomir and Niu, Zhangming and Li, Stan Z},
booktitle={International conference on machine learning},
pages={37511--37523},
year={2023},
organization={PMLR}
}[2] Krishna, Ranjay, et al. "Visual genome: Connecting language and vision using crowdsourced dense image annotations." International journal of computer vision 123 (2017): 32-73.
[3] Luo, Dongsheng, et al. "Parameterized explainer for graph neural network." Advances in neural information processing systems 33 (2020): 19620-19631.
