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

Make models compatible to Captum #3990

Merged
merged 22 commits into from
Feb 9, 2022
Merged

Conversation

RBendias
Copy link
Contributor

@RBendias RBendias commented Feb 2, 2022

As discussed in issue #3858, we can add a to_captum method for simple use of Captum. The method adjusts the forward function of a model. I have added an example of edge explainability for node classification.

I have tested several Captum methods (IntegratedGradients, Saliency, InputXGradient, GuidedBackprop, Deconvolution, ShapleyValueSampling, Kernelshap, FeatureAblation), all of which work appropriately with the Captum example given here.

@rusty1s I have implemented a CaptumModel class, the to_captum method seems redundant. Alternatively, I could just overwrite the forward function instead of creating a new model. Do you have a preference and do you see an advantage in not creating a new model?

Copy link
Member

@rusty1s rusty1s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you :) This looks great. Left a few but minor comments :)

torch_geometric/nn/models/explainer.py Outdated Show resolved Hide resolved
data = dataset[0]


class Net(torch.nn.Module):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we use torch_geometric.nn.models.GCN here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the exact same model as in examples/gnn_explainer.py. Should I change it nevertheless?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it is better to directly use pre-defined models.

examples/captum_explainability.py Outdated Show resolved Hide resolved
examples/captum_explainability.py Outdated Show resolved Hide resolved
examples/captum_explainability.py Outdated Show resolved Hide resolved
torch_geometric/nn/models/explainer.py Show resolved Hide resolved
test/nn/models/test_explainer.py Outdated Show resolved Hide resolved
examples/captum_explainability.py Outdated Show resolved Hide resolved
examples/captum_explainability.py Outdated Show resolved Hide resolved
examples/captum_explainability.py Outdated Show resolved Hide resolved
Copy link
Member

@rusty1s rusty1s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update. After adding a Captum test, I think this PR is ready to get merged.

x = F.relu(self.conv1(x, edge_index))
x = F.dropout(x, training=self.training)
x = self.conv2(x, edge_index)
return F.log_softmax(x, dim=1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, what does that mean in particular? Is the usage of log_softmax correct?

examples/captum_explainability.py Outdated Show resolved Hide resolved
test/nn/models/test_explainer.py Show resolved Hide resolved
torch_geometric/nn/models/explainer.py Outdated Show resolved Hide resolved
torch_geometric/nn/models/explainer.py Outdated Show resolved Hide resolved
torch_geometric/nn/models/explainer.py Outdated Show resolved Hide resolved
torch_geometric/nn/models/explainer.py Outdated Show resolved Hide resolved
torch_geometric/nn/models/explainer.py Outdated Show resolved Hide resolved
torch_geometric/nn/models/explainer.py Outdated Show resolved Hide resolved
torch_geometric/nn/models/explainer.py Outdated Show resolved Hide resolved
RBendias and others added 5 commits February 4, 2022 17:41
Co-authored-by: Matthias Fey <matthias.fey@tu-dortmund.de>
Co-authored-by: Matthias Fey <matthias.fey@tu-dortmund.de>
Co-authored-by: Matthias Fey <matthias.fey@tu-dortmund.de>
Co-authored-by: Matthias Fey <matthias.fey@tu-dortmund.de>
@RBendias RBendias changed the title [WIP] Make models compatible to Captum Make models compatible to Captum Feb 8, 2022
@rusty1s rusty1s merged commit 6002170 into pyg-team:master Feb 9, 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.

None yet

2 participants