Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some usability updates to Explanation #6054

Merged
merged 10 commits into from
Nov 28, 2022

Conversation

BlazStojanovic
Copy link
Contributor

Motivation

When evaluating and visualizing explanations it will be very convenient to obtain the explanation and explanation complement subgraphs directly from the Explanation objects. Given that the class holds information of the original graph being explained this shouldn’t be difficult to achieve. I propose we add two methods to the Explanation class:

  1. get_explanation_subgraph returns the explanation subgraph $G_S$,
  2. get_complement_subgraph returns the complement of the explanation subgraph $G_{C \backslash S}$

I’ve submitted this draft PR to get opinions on this, both implementation-wise and if we should do this in the first place.

Alternatives

  1. Delegate this to other parts of code, I.e. whenewer this is needed (e.g. when evaluation explanations or visualizing them)
  2. Implement the logic in util.py for general Data object, e.g. a mask_graph method, which can then be reused here or elsewhere.

@codecov
Copy link

codecov bot commented Nov 24, 2022

Codecov Report

Merging #6054 (a9856f0) into master (6aa454a) will increase coverage by 0.02%.
The diff coverage is 100.00%.

❗ Current head a9856f0 differs from pull request most recent head 7320580. Consider uploading reports for the commit 7320580 to get more accurate results

@@            Coverage Diff             @@
##           master    #6054      +/-   ##
==========================================
+ Coverage   84.27%   84.29%   +0.02%     
==========================================
  Files         362      362              
  Lines       20456    20488      +32     
==========================================
+ Hits        17239    17271      +32     
  Misses       3217     3217              
Impacted Files Coverage Δ
torch_geometric/explain/explanations.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@BlazStojanovic
Copy link
Contributor Author

@rusty1s and @dufourc1, while working on this PR, I’ve encountered the following behaviour. If you create a partially empty Explanation, e.g.

node_mask = torch.tensor([False, True])
explanation = Explanation(node_mask=node_mask)

then trying to acces either of the other masks results in the following AttributeError :

explanation.edge_mask (or node_feat_mask, edge_feat_mask)
...
AttributeError: 'GlobalStorage' object has no attribute 'edge_mask'

Is this intended behaviour?

@rusty1s
Copy link
Member

rusty1s commented Nov 28, 2022

I guess it is. You can access them via data.get('edge_feat_mask') if you want to access potentially non-existing attributes. Would that work for you?

@dufourc1
Copy link
Member

dufourc1 commented Nov 28, 2022

I would have expected that to return None, even if it does not change a lot given the workaround rusty1s just gave 👍.

@BlazStojanovic BlazStojanovic marked this pull request as ready for review November 28, 2022 09:02
@rusty1s rusty1s merged commit 0fdf935 into pyg-team:master Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants