README.md 2.12 KB
Newer Older
1
# DGL Implementation of GNNExplainer
KounianhuaDu's avatar
KounianhuaDu committed
2

3
4
This is a DGL example for [GNNExplainer: Generating Explanations for Graph Neural Networks](https://arxiv.org/abs/1903.03894). For the authors' original implementation,
see [here](https://github.com/RexYing/gnn-model-explainer).
KounianhuaDu's avatar
KounianhuaDu committed
5

6
7
8
9
Contributors:
- [Jian Zhang](https://github.com/zhjwy9343)
- [Kounianhua Du](https://github.com/KounianhuaDu)
- [Yanjun Zhao](https://github.com/zyj-111)
KounianhuaDu's avatar
KounianhuaDu committed
10

11
Datasets
KounianhuaDu's avatar
KounianhuaDu committed
12
13
----------------------

14
Four built-in synthetic datasets are used in this example.
KounianhuaDu's avatar
KounianhuaDu committed
15

16
17
18
19
20
21
- [BA-SHAPES](https://docs.dgl.ai/generated/dgl.data.BAShapeDataset.html#dgl.data.BAShapeDataset)
- [BA-COMMUNITY](https://docs.dgl.ai/generated/dgl.data.BACommunityDataset.html#dgl.data.BACommunityDataset)
- [TREE-CYCLE](https://docs.dgl.ai/generated/dgl.data.TreeCycleDataset.html#dgl.data.TreeCycleDataset)
- [TREE-GRID](https://docs.dgl.ai/generated/dgl.data.TreeGridDataset.html#dgl.data.TreeGridDataset)

Usage
KounianhuaDu's avatar
KounianhuaDu committed
22
23
----------------------

24
**First**, train a GNN model on a dataset.
KounianhuaDu's avatar
KounianhuaDu committed
25

26
27
```bash
python train_main.py  --dataset $DATASET
KounianhuaDu's avatar
KounianhuaDu committed
28
29
```

30
Valid options for `$DATASET`: `BAShape`, `BACommunity`, `TreeCycle`, `TreeGrid`
KounianhuaDu's avatar
KounianhuaDu committed
31

32
The trained model weights will be saved to `model_{dataset}.pth`
KounianhuaDu's avatar
KounianhuaDu committed
33

34
**Second**, install [GNNLens2](https://github.com/dmlc/GNNLens2) with
KounianhuaDu's avatar
KounianhuaDu committed
35

36
37
38
39
40
```bash
pip install -U flask-cors
pip install Flask==2.0.3
pip install gnnlens
```
KounianhuaDu's avatar
KounianhuaDu committed
41

42
**Third**, explain the trained model with the same dataset
KounianhuaDu's avatar
KounianhuaDu committed
43

44
45
46
```bash
python explain_main.py --dataset $DATASET
```
KounianhuaDu's avatar
KounianhuaDu committed
47

48
**Finally**, launch `GNNLens2` to visualize the explanations
KounianhuaDu's avatar
KounianhuaDu committed
49

50
51
52
```bash
gnnlens --logdir gnn_subgraph
```
KounianhuaDu's avatar
KounianhuaDu committed
53

54
By entering `localhost:7777` in your web browser address bar, you can see the GNNLens2 interface. `7777` is the default port GNNLens2 uses. You can specify an alternative one by adding `--port xxxx` after the command line and change the address in the web browser accordingly.
KounianhuaDu's avatar
KounianhuaDu committed
55

56
A sample visualization is available below. For more details of using `GNNLens2`, check its [tutorials](https://github.com/dmlc/GNNLens2#tutorials).
KounianhuaDu's avatar
KounianhuaDu committed
57
58

<p align="center">
59
  <img src="https://data.dgl.ai/asset/image/explain_BAShape.png"  width="600">
KounianhuaDu's avatar
KounianhuaDu committed
60
  <br>
61
  <b>Figure</b>: Explanation for node 41 of BAShape
KounianhuaDu's avatar
KounianhuaDu committed
62
</p>