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

Explain text predictions of Keras classifiers #325

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

Conversation

teabolt
Copy link
Contributor

@teabolt teabolt commented Jul 17, 2019

Based on #315 and #329, we use Grad-CAM to highlight parts of text that contribute to a prediction of a Keras classifier.

For example, we can use a call similar to this:

eli5.show_prediction(model, doc, 
        tokens=doc_tokens,
        pad_x=word_index['<PAD>'],
        padding='post',
        relu=False,
)

To roughly highlight positive and negative parts of a text (explaining the score given in sentiment analysis):
Screenshot from 2019-07-17 18-13-25

This PR also makes refactorings (including changes to the public API) to the code at the linked PR's.

WIP items:

  • Tutorial.
  • Pass CI and coverage.
  • Tests (manual and automated).
  • Docs.
  • Mypy.

teabolt and others added 30 commits July 1, 2019 16:19
@teabolt
Copy link
Contributor Author

teabolt commented Sep 10, 2019

@lopuhin Do you think there is anything major left to do in this PR? (besides making the CI pass)

@lopuhin
Copy link
Contributor

lopuhin commented Sep 17, 2019

@teabolt I don't recall anything significant, and from a quick glance it looks like all review feedback is addressed so I think it's almost ready.

@codecov-commenter
Copy link

codecov-commenter commented Jun 6, 2020

Codecov Report

Merging #325 into master will increase coverage by 0.02%.
The diff coverage is 98.20%.

@@            Coverage Diff             @@
##           master     #325      +/-   ##
==========================================
+ Coverage   97.32%   97.34%   +0.02%     
==========================================
  Files          49       52       +3     
  Lines        3142     3320     +178     
  Branches      585      623      +38     
==========================================
+ Hits         3058     3232     +174     
- Misses         44       46       +2     
- Partials       40       42       +2     
Impacted Files Coverage Δ
eli5/ipython.py 100.00% <ø> (ø)
eli5/keras/__init__.py 100.00% <ø> (ø)
eli5/formatters/image.py 98.71% <93.33%> (-1.29%) ⬇️
eli5/nn/text.py 96.00% <96.00%> (ø)
eli5/base.py 100.00% <100.00%> (ø)
eli5/keras/explain_prediction.py 98.37% <100.00%> (+1.98%) ⬆️
eli5/keras/gradcam.py 100.00% <100.00%> (ø)
eli5/nn/__init__.py 100.00% <100.00%> (ø)
eli5/nn/gradcam.py 100.00% <100.00%> (ø)
... and 4 more

@teabolt teabolt force-pushed the keras-gradcam-text branch from ec0f51c to 6e960ff Compare June 6, 2020 13:53
Copy link
Contributor

@lopuhin lopuhin left a comment

Choose a reason for hiding this comment

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

thanks @teabolt I hope I can finish review in a week, looks really solid, left a few minor comments

.travis.yml Show resolved Hide resolved
docs/source/libraries/keras.rst Outdated Show resolved Hide resolved
@Hellisotherpeople
Copy link

Is this ever going to be merged? I'm super interested in seeing this get added to ELI5 ASAP!!!

@teabolt
Copy link
Contributor Author

teabolt commented Jan 11, 2021

Is this ever going to be merged? I'm super interested in seeing this get added to ELI5 ASAP!!!

Hey @Hellisotherpeople . Sorry for the late reply. If you are still interested you can try installing the PR branch directly with pip:

  1. If you are using virtualenv or a similar environment manager, make a clone of your environment.
  2. Install the PR branch with pip install -U git+https://github.com/teabolt/eli5.git@keras-gradcam-text

To test that it worked run:

import eli5.keras
eli5.keras.explain_prediction_keras_text()

The output should be TypeError: explain_prediction_keras_text() missing 2 required positional arguments: 'model' and 'doc'

Tested this with Python 3.7 and Ubuntu 20.04.

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.

5 participants