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

[WIP] Explain PyTorch neural nets with Grad-CAM #327

Open
wants to merge 144 commits into
base: master
Choose a base branch
from

Conversation

teabolt
Copy link
Contributor

@teabolt teabolt commented Jul 29, 2019

This PR explains image and text classifiers built in PyTorch using the Grad-CAM method, building on #315 and #325.

Images example:
Using the pretrained mobilenet_v2 network from torchvision and calling eli5.show_prediction(model, doc, image=img)

We get the classical explanation for 'dog':
Screenshot from 2019-07-29 22-12-23

Text example:
Using an example model from https://www.kaggle.com/ziliwang/pytorch-text-cnn for an insincere question classification task (https://www.kaggle.com/c/quora-insincere-questions-classification/overview), we can write eli5.show_prediction(model, doc, tokens=tokens, layer=layer, relu=False).

To get an explanation like this (green = 'insincere', red = 'neutral'):
Screenshot from 2019-07-29 21-52-42

This PR only provides basic PyTorch support.

TODO items:

  • Consistency with Keras support and features.
  • Image tutorial.
  • Text tutorial (need to scale model down).
  • Image integration tests.
  • Text integration tests.
  • Unit tests.
  • Docstrings and docs.
  • CI and coverage.
  • Reviews.

teabolt and others added 30 commits July 1, 2019 16:19
Co-Authored-By: Mikhail Korobov <kmike84@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented Jun 6, 2020

Codecov Report

Merging #327 into master will decrease coverage by 3.20%.
The diff coverage is 71.95%.

@@            Coverage Diff             @@
##           master     #327      +/-   ##
==========================================
- Coverage   97.32%   94.12%   -3.21%     
==========================================
  Files          49       56       +7     
  Lines        3142     3472     +330     
  Branches      585      645      +60     
==========================================
+ Hits         3058     3268     +210     
- Misses         44      162     +118     
- Partials       40       42       +2     
Impacted Files Coverage Δ
eli5/keras/__init__.py 100.00% <ø> (ø)
eli5/pytorch/gradcam.py 24.13% <24.13%> (ø)
eli5/pytorch/explain_prediction.py 29.16% <29.16%> (ø)
eli5/pytorch/image.py 30.00% <30.00%> (ø)
eli5/formatters/image.py 98.75% <92.85%> (-1.25%) ⬇️
eli5/nn/gradcam.py 95.83% <95.83%> (ø)
eli5/__init__.py 84.61% <100.00%> (+1.28%) ⬆️
eli5/base.py 100.00% <100.00%> (ø)
eli5/keras/explain_prediction.py 98.70% <100.00%> (+2.31%) ⬆️
eli5/keras/gradcam.py 100.00% <100.00%> (ø)
... and 18 more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants