dgl icon indicating copy to clipboard operation
dgl copied to clipboard

[Model] Heterogeneous graph support for GNNExplainer

Open moeinfinityx opened this issue 3 years ago • 71 comments

Description

Add Heterogeneous Graph support for GNNExplainer

Checklist

Please feel free to remove inapplicable items for your PR.

  • [x] The PR title starts with [$CATEGORY] (such as [NN], [Model], [Doc], [Feature]])
  • [x] Changes are complete (i.e. I finished coding on this PR)
  • [x] All changes have test coverage
  • [x] Code is well-documented
  • [x] To the best of my knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change
  • [ ] Related issue is referred in this PR
  • [x] If the PR is for a new model/paper, I've updated the example index here.

Changes

Added a new class HeteroGNNExplainer for Heterogeneous graph explanation.

The output of the model has been manually verified on MUTAG dataset. Unfortunately there's no ground truth for the explanation, so we cannot quantify the model's performance. Instead, we manually investigated the results and confirms that it aligns well with human intuition.

Link to the MUTAG Hetero GNNExplainer notebook

The code has also been verified on several datasets DGL officially provides, see this repo for details.

Inline documentation is added following the original style, and an example of using the module is included in the documentation.

moeinfinityx avatar Aug 16 '22 00:08 moeinfinityx

To trigger regression tests:

  • @dgl-bot run [instance-type] [which tests] [compare-with-branch]; For example: @dgl-bot run g4dn.4xlarge all dmlc/master or @dgl-bot run c5.9xlarge kernel,api dmlc/master

dgl-bot avatar Aug 16 '22 00:08 dgl-bot

Commit ID: 164530c55e71ab430ac4cbbc1a0145e978167665

Build ID: 1

Status: ❌ CI test failed in Stage [Lint Check].

Report path: link

Full logs path: link

dgl-bot avatar Aug 16 '22 00:08 dgl-bot

Commit ID: fdc364824307143dba8d46165a4b619600276b2f

Build ID: 2

Status: ❌ CI test failed in Stage [Lint Check].

Report path: link

Full logs path: link

dgl-bot avatar Aug 16 '22 12:08 dgl-bot

provng: DGL PR#4401 README

In this PR, we created a new class HeteroGNNExplainer which is the heterogeneous version of the GNNExplainer class. HeteroGNNExplainer takes a Heterogeneous GNN classification model and its input graph as parameters and generates an explanation in a similar form to GNNExplainer.

The main difference between a homogenous graph and a heterogeneous graph is that a heterogeneous graph can have multiple edge types and node types. Therefore, we changed the input data structure from a tensor of values to a dictionary mapping a type to a tensor of values. To enable compatibility with heterogeneous graphs, we changed every instance that the explainer assumes the graph data is a tensor to instead assume that it is a dictionary of tensors.

The HeteroGNNExplainer is implemented similarly in structure to the homogenous implementation. We had to adjust each function in the explainer framework that used input data to ensure compatibility with the new input format. Additionally, changes had to be made to the masks’ initializations to ensure they were also initialized as dictionaries. For instance, from __init_masks() method, you can see the following code.

# Simplifed version of edge mask initalization
edge_mask = {}
for canonical_etype in graph.canonical_etypes:
    num_edges = graph.number_of_edges(canonical_etype)
    edge_mask[canonical_etype] = torch.randn(num_edges)

The GNNExplainer requires the model being explained to accept an eweight parameter in the forward function. For HeteroGNNExplainer, this parameter also becomes a dictionary (of canonical_etypes). An example is provided in the inline documentation following the same style of the original GNNExplainer class.

In summary, the HeteroGNNExplainer is similar in structure to the homogenous GNNExplainer. Our main contribution is to accomodate the input data format of a heterogeneous graph.


tags: provng,dgl,ahad

atmaranto avatar Aug 18 '22 01:08 atmaranto

Commit ID: d4b33dfe2fd8f15e2562af50d7447ccda17e0871

Build ID: 3

Status: ❌ CI test failed in Stage [Lint Check].

Report path: link

Full logs path: link

dgl-bot avatar Aug 19 '22 16:08 dgl-bot

You will need to fix "This branch is out-of-date with the base branch"

mufeili avatar Aug 25 '22 04:08 mufeili

Missing unit test in https://github.com/dmlc/dgl/blob/master/tests/pytorch/test_nn.py

mufeili avatar Aug 25 '22 04:08 mufeili

Missing doc indexing here https://github.com/dmlc/dgl/blob/master/docs/source/api/python/nn-pytorch.rst for documentation rendering

mufeili avatar Aug 25 '22 04:08 mufeili

Commit ID: 458db9b538731fd30eb2d4cd201478fd4e8d52ba

Build ID: 4

Status: ❌ CI test failed in Stage [Lint Check].

Report path: link

Full logs path: link

dgl-bot avatar Aug 26 '22 18:08 dgl-bot

Commit ID: None

Build ID: 6

Status: ✅ CI test succeeded

Report path: link

Full logs path: link

dgl-bot avatar Sep 06 '22 02:09 dgl-bot

Commit ID: 77811b4067395b930b3360d72492695402000333

Build ID: 7

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

dgl-bot avatar Sep 08 '22 20:09 dgl-bot

Commit ID: 8ee055c88952b489d25b5613bd1b8dd843039782

Build ID: 8

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

dgl-bot avatar Sep 08 '22 21:09 dgl-bot

Commit ID: 373ad9d5d835371120181c2995c73c6730de4a65

Build ID: 9

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

dgl-bot avatar Sep 08 '22 21:09 dgl-bot

@Rhett-Ying Is it no longer allowed for community contributors to trigger the CI test? What will be alternatives?

mufeili avatar Sep 12 '22 10:09 mufeili

@Rhett-Ying Is it no longer allowed for community contributors to trigger the CI test? What will be alternatives?

Yes, only the core developers are allowed. You could help trigger via making below comments here: @dgl-bot.

Rhett-Ying avatar Sep 13 '22 02:09 Rhett-Ying

@dgl-bot

Rhett-Ying avatar Sep 13 '22 02:09 Rhett-Ying

@Rhett-Ying Is it no longer allowed for community contributors to trigger the CI test? What will be alternatives?

Yes, only the core developers are allowed. You could help trigger via making below comments here: @dgl-bot.

Got it. Thanks! Perhaps then we should disable the auto trigger of CI as the community contributors can be confused with Authentication.

mufeili avatar Sep 13 '22 03:09 mufeili

Commit ID: None

Build ID: 11

Status: ✅ CI test succeeded

Report path: link

Full logs path: link

dgl-bot avatar Sep 14 '22 01:09 dgl-bot

Commit ID: None

Build ID: 12

Status: ✅ CI test succeeded

Report path: link

Full logs path: link

dgl-bot avatar Sep 14 '22 01:09 dgl-bot

Commit ID: 373ad9d5d835371120181c2995c73c6730de4a65

Build ID: 10

Status: ❌ CI test failed in Stage [Regression Test].

Report path: link

Full logs path: link

dgl-bot avatar Sep 14 '22 01:09 dgl-bot

Commit ID: fd01972707d8165092575b01b90992cf69b8fee4

Build ID: 13

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

dgl-bot avatar Sep 14 '22 01:09 dgl-bot

Commit ID: c9e25603b118ec7cb3a2c9fe18672baa24f440d6

Build ID: 14

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

dgl-bot avatar Sep 14 '22 01:09 dgl-bot

Commit ID: 5a8bd8427776f55df0cd3b1afeb124979c8d71ee

Build ID: 15

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

dgl-bot avatar Sep 14 '22 01:09 dgl-bot

Commit ID: None

Build ID: 16

Status: ✅ CI test succeeded

Report path: link

Full logs path: link

dgl-bot avatar Sep 14 '22 01:09 dgl-bot

Commit ID: None

Build ID: 17

Status: ✅ CI test succeeded

Report path: link

Full logs path: link

dgl-bot avatar Sep 14 '22 01:09 dgl-bot

Commit ID: None

Build ID: 18

Status: ✅ CI test succeeded

Report path: link

Full logs path: link

dgl-bot avatar Sep 14 '22 01:09 dgl-bot

Commit ID: None

Build ID: 19

Status: ✅ CI test succeeded

Report path: link

Full logs path: link

dgl-bot avatar Sep 14 '22 01:09 dgl-bot

Commit ID: None

Build ID: 20

Status: ✅ CI test succeeded

Report path: link

Full logs path: link

dgl-bot avatar Sep 14 '22 01:09 dgl-bot

Commit ID: None

Build ID: 21

Status: ✅ CI test succeeded

Report path: link

Full logs path: link

dgl-bot avatar Sep 14 '22 01:09 dgl-bot

Commit ID: 70095dd68252e39ee7e356b301a025950f599764

Build ID: 22

Status: ❌ CI test failed in Stage [Authentication].

Report path: link

Full logs path: link

dgl-bot avatar Sep 14 '22 01:09 dgl-bot