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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
8196243
WeightedSpan commment
teabolt Jul 1, 2019
ef63e5a
End-to-end simple text (breaks image)
teabolt Jul 2, 2019
1774ac8
Merge branch 'keras-gradcam-img' of https://github.com/teabolt/eli5 i…
teabolt Jul 4, 2019
ccdba2b
Fix image explanations ('regression')
teabolt Jul 4, 2019
d94f553
Merge branch 'keras-gradcam-img' of https://github.com/teabolt/eli5 i…
teabolt Jul 5, 2019
a7c7e74
New args for text explanations (mypy and docstring)
teabolt Jul 5, 2019
efb417b
Move span builder code to function. Add construct_document function
teabolt Jul 5, 2019
a2d18d5
Refactor and generalize _validate_doc
teabolt Jul 5, 2019
8dd2579
Refactor _get_activation_layer. Add layer condition for text
teabolt Jul 5, 2019
774b812
Comment about WeightedSpan
teabolt Jul 5, 2019
633dc4c
Disable validation of retrieved activation_layer
teabolt Jul 5, 2019
3dabdd3
Add comment about counterfactual explanations
teabolt Jul 8, 2019
d37016c
Add compute_weights to keras package
teabolt Jul 8, 2019
b8c979e
Merge branch 'keras-gradcam-img' of https://github.com/teabolt/eli5 i…
teabolt Jul 8, 2019
a781e66
Add post-padding removal
teabolt Jul 8, 2019
723e98d
Put text and image explanation code into separate functions
teabolt Jul 9, 2019
3bb13db
Add function to upsize 1D arrays
teabolt Jul 9, 2019
d6a23bd
Comment about scipy resample, K.gradients
teabolt Jul 9, 2019
4024be0
Add relu and counterexplanation args
teabolt Jul 9, 2019
30ed0c8
Update lib docs, docstring (heatmap and explanation details)
teabolt Jul 10, 2019
b89b65a
Update tests/utils_image.py (use count_nonzero instead of sum)
teabolt Jul 10, 2019
37bfb47
Hardcoding to explain RNN's (with rank 1 activations)
teabolt Jul 11, 2019
049aaca
Merge branch 'keras-gradcam-img' of https://github.com/teabolt/eli5 i…
teabolt Jul 14, 2019
6a4e1ae
Fix failing tests for image explanations
teabolt Jul 15, 2019
74cb56d
Fix mypy for image explanations
teabolt Jul 15, 2019
28c2ac2
Comments
teabolt Jul 15, 2019
1e0bbba
Fix image docs. Run tutorial notebook in update script
teabolt Jul 16, 2019
3beb7ca
Comment about running sections of notebook script
teabolt Jul 16, 2019
58f0108
Make image arg required for image-based explanations
teabolt Jul 16, 2019
379abfc
Update image tutorial to use image arg
teabolt Jul 17, 2019
453b0da
Organise repeated explain_prediction* params
teabolt Jul 17, 2019
37e0337
Remove target_names mentions (moved to GitHub issue)
teabolt Jul 17, 2019
d648a80
Update comments and docstring
teabolt Jul 17, 2019
e3da435
Rename arg 'estimator' to 'model'
teabolt Jul 17, 2019
5ae57ec
Explanation modifier args. Move heatmap normalization to formatters
teabolt Jul 17, 2019
a5baf33
Comments
teabolt Jul 17, 2019
9934265
Support for character-based highlighting
teabolt Jul 17, 2019
597c56f
Fix mypy, add asserts (CI fail)
teabolt Jul 17, 2019
2bce4d4
Refactor lmap calculation. Non-2D layer image formatting.
teabolt Jul 18, 2019
077e2cf
Decouple layer getter and layer search
teabolt Jul 18, 2019
99952c7
Handle pre-padding
teabolt Jul 18, 2019
ca345b2
Make span builder use document
teabolt Jul 18, 2019
bacb437
Move text methods into keras.text module
teabolt Jul 18, 2019
09df1fc
Fix image tests. Reduce required area percent in test
teabolt Jul 18, 2019
1abca65
Move reusable GradCAM code to a top level gradcam module
teabolt Jul 23, 2019
773c36e
Create neural nets package. Move text and gradcam explanation code to…
teabolt Jul 23, 2019
e0e81b3
Fix broken local imports
teabolt Jul 24, 2019
e8def57
Add mypy if TYPE_CHECKING comment
teabolt Jul 24, 2019
d72491f
Move DESCRIPTION to nn.gradcam
teabolt Jul 24, 2019
f3c2be0
Formatting. Separate target prediction auto getter
teabolt Jul 24, 2019
77a2d84
Move tests. Comment TODO's for tests.
teabolt Jul 24, 2019
ae9686c
Add integration test setup for text
teabolt Jul 25, 2019
6b8d24c
Take tokens as list or numpy array. Validate
teabolt Jul 25, 2019
f900985
Take padding character/value as str or int
teabolt Jul 25, 2019
fbd5b3d
Unit tests for nn.text
teabolt Jul 26, 2019
c446d85
Improve 1D array resizing method\asdfa
teabolt Jul 26, 2019
508e5f3
Mypy for nn.text. Fix CI
teabolt Jul 26, 2019
121c703
Forgot to rename pad_x to pad_value (ci fix)
teabolt Jul 26, 2019
cb354fb
Apply Grad-CAM to layers with single dimension (dense, final rnn, etc)
teabolt Jul 30, 2019
bafdc6b
Add mypy annotations
teabolt Jul 30, 2019
d7a3e3d
Add text to keras library docs
teabolt Jul 30, 2019
05efdab
Add nn package to docs
teabolt Jul 30, 2019
e4530bc
Add integration test for keras binary text classification
teabolt Jul 31, 2019
9bf4ea1
Update docstrings of nn and keras packages
teabolt Jul 31, 2019
d2a8724
CI fix: ignore deps, mypy, batching error
teabolt Aug 1, 2019
3fcb46d
Add notebook used to train keras text model
teabolt Aug 1, 2019
59ce1a7
Add tutorial file for keras text
teabolt Aug 1, 2019
3760267
Clean up keras comments, targets validation
teabolt Aug 1, 2019
e1f18d6
Move targets validation to nn package
teabolt Aug 2, 2019
e2b1928
Add multiclass model in a keras test
teabolt Aug 2, 2019
f260e63
Ignore estimator files for nodeps tox envs
teabolt Aug 2, 2019
46214a3
Mypy (fix CI)
teabolt Aug 2, 2019
b5e9989
Merge branch 'keras-gradcam-img-v2' of https://github.com/teabolt/eli…
teabolt Aug 6, 2019
af4144e
Merge branch 'keras-gradcam-img-v2' of https://github.com/teabolt/eli…
teabolt Aug 6, 2019
61e7f83
Remove _validate_heatmap
teabolt Aug 6, 2019
65736af
Merge branch 'keras-gradcam-img-v2' of https://github.com/teabolt/eli…
teabolt Aug 6, 2019
f56697c
Add tokens validation tests
teabolt Aug 6, 2019
6eec249
Explain sentiment classifier in keras text tutorial
teabolt Aug 6, 2019
a579cd7
Add multiclass model to tutorial. Add tutorial to docs
teabolt Aug 7, 2019
832490b
Merge branch 'keras-gradcam-img-v2' of https://github.com/teabolt/eli…
teabolt Aug 8, 2019
54b120b
Ignore keras estimator .py files in no deps tests (CI fix)
teabolt Aug 9, 2019
85dc89b
Text tutorial: multiclass explanations, explain_prediction
teabolt Aug 9, 2019
7fa17f3
Improve automatic layer search. Add tests
teabolt Aug 9, 2019
6ccb8cf
Clean up nn.text comments, rename arg.
teabolt Aug 9, 2019
3fa3b01
Explain Grad-CAM formula in keras lib docs
teabolt Aug 9, 2019
2a78ab9
Document interpolation_kind in single docstring, reference in others
teabolt Aug 9, 2019
acebfff
Merge branch 'keras-gradcam-img-v2' of https://github.com/teabolt/eli…
teabolt Aug 9, 2019
d8d41dc
Merge branch 'keras-gradcam-img-v2' of https://github.com/teabolt/eli…
teabolt Aug 10, 2019
42f8aa0
Add 'return None' statement for mypy (CI fix)
teabolt Aug 10, 2019
843812b
Blank line between :: and code block in docs (CI fix)
teabolt Aug 10, 2019
ab6447d
Merge branch 'master' of https://github.com/teabolt/eli5 into keras-g…
teabolt Aug 12, 2019
5d15a49
Test that can take dense/final RNN layers
teabolt Aug 12, 2019
a9a9ef3
Add targets validation tests
teabolt Aug 12, 2019
1c123f7
Remove _get_temporal_length. Pass tokens to nn.text without batch
teabolt Aug 12, 2019
9d5370a
Test invalid 'padding' argument
teabolt Aug 12, 2019
d545c90
Test invalid heatmap for format_as_image
teabolt Aug 12, 2019
d176d0a
Change formatters.image public API (simplify underlying functions). T…
teabolt Aug 12, 2019
49f1a10
Update image tutorial with image API changes and counterfactual/relu …
teabolt Aug 12, 2019
fccd266
Add relu and counterfactual integration tests
teabolt Aug 12, 2019
9bd82f1
Mypy updates to image code
teabolt Aug 12, 2019
0dd88ea
Restructure and add to text tutorial
teabolt Aug 12, 2019
0451996
Split parts of _validate_doc() into _validate_doc_shape() (CI fix)
teabolt Aug 13, 2019
30f9708
Add descriptions to text tutorial
teabolt Aug 13, 2019
f60a32c
Indentation for long import
teabolt Aug 14, 2019
8599ad9
Wording: accuracy -> score.
teabolt Aug 14, 2019
5930ca4
Apply co-authored commits to .ipynb
teabolt Aug 14, 2019
9ded322
Print python and package versions at runtime for tutorial
teabolt Aug 14, 2019
28a179c
Replace os.getcwd with a working way to reference files in a module
teabolt Aug 14, 2019
71e3d9d
Link to training notebooks in tutorial
teabolt Aug 14, 2019
8c9ae79
Print accuracy clearly for text models
teabolt Aug 14, 2019
c1e9cdc
More details on relu and counterfactual in tutorial
teabolt Aug 14, 2019
fecaa58
Show padding for dense layer explanation
teabolt Aug 14, 2019
686d810
Remove section on interpolation_kind from tutorial
teabolt Aug 14, 2019
8cd5af9
Add .layer attribute to Explanation
teabolt Aug 15, 2019
a32f6ed
Remove own input shape validation and let Keras do it
teabolt Aug 15, 2019
96b07b3
Search for layer backwards by default. Refactor image layer autogetter.
teabolt Aug 15, 2019
2571dc7
Separate pad_value arg into pad_value (number) and pad_token (str)
teabolt Aug 15, 2019
8939929
Remove padding argument and cut pre and post padding automatically
teabolt Aug 15, 2019
e188bc6
Update tutorial and tests (not working)
teabolt Aug 15, 2019
8106b27
Fix integration tests by hard-coding to pick embedded layer
teabolt Aug 17, 2019
154333f
Clean up. CI fixes (improve text layer chooser)
teabolt Aug 17, 2019
c4a5668
Update tutorial, docs
teabolt Aug 17, 2019
8d5bed0
Add tests, validation (coverage)
teabolt Aug 17, 2019
e0d2beb
Misplaced argument (CI fix)
teabolt Aug 17, 2019
0b1e806
Clarify comment for index_from in text model files
teabolt Aug 17, 2019
42ef263
Generalise check for space in tokens
teabolt Aug 17, 2019
6b1c6ed
Update comments, remove TODO's
teabolt Aug 17, 2019
86e7780
Update pad_value docstring
teabolt Aug 19, 2019
3ae37bb
Make layer pickers for text and image raise error if can not find layer
teabolt Aug 19, 2019
e705e09
Merge branch 'keras-gradcam-text' of https://github.com/teabolt/eli5 …
teabolt Aug 19, 2019
01c595a
Update docs. Remove _forward_layers
teabolt Aug 19, 2019
f1e56da
Mention about spans list in WeightedSpan
teabolt Aug 19, 2019
48f2679
Fix doc type
teabolt Aug 19, 2019
bb1ba1e
Update old doc comment
teabolt Aug 19, 2019
af821c2
Update text tutorial
teabolt Aug 19, 2019
b9a8ca8
Make layer attr take any type. Pass layer instance
teabolt Aug 19, 2019
50b4f6d
Update index docs with text changes
teabolt Aug 19, 2019
7616a4e
Add gradcam test utils. Move tests from integration to unit in Keras
teabolt Aug 19, 2019
69fe751
Rename function. Add tests for package imports
teabolt Sep 7, 2019
9788c22
Move argument validation to relevant modules
teabolt Sep 7, 2019
18980b7
Separate out classification-specific code into a function
teabolt Sep 9, 2019
6cfd526
Replace mypy annotation K.variable with Any
teabolt Sep 9, 2019
c94eb52
Add validation for public function arguments
teabolt Oct 13, 2019
6e960ff
Merge branch 'master' of github.com:teabolt/eli5 into keras-gradcam-text
teabolt Jun 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ It provides support for the following machine learning frameworks and packages:
It also allows to debug scikit-learn pipelines which contain
HashingVectorizer, by undoing hashing.

* Keras_ - explain predictions of image classifiers via Grad-CAM visualizations.
* Keras_ - explain predictions of image and text classifiers via Grad-CAM visualizations.

* xgboost_ - show feature importances and explain predictions of XGBClassifier,
XGBRegressor and xgboost.Booster.
Expand Down Expand Up @@ -81,7 +81,7 @@ and formatting on a client.
.. _xgboost: https://github.com/dmlc/xgboost
.. _LightGBM: https://github.com/Microsoft/LightGBM
.. _Catboost: https://github.com/catboost/catboost
.. _Keras: https://keras.io/
.. _Keras: https://github.com/keras-team/keras
.. _Permutation importance: https://eli5.readthedocs.io/en/latest/blackbox/permutation_importance.html
.. _Inspecting Black-Box Estimators: https://eli5.readthedocs.io/en/latest/blackbox/index.html

Expand Down
3 changes: 3 additions & 0 deletions _ci/runtests_default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ py.test --doctest-modules \
--ignore eli5/keras \
--ignore eli5/formatters/image.py \
--ignore tests/utils_image.py \
--ignore tests/utils_gradcam.py \
--ignore tests/estimators/keras_sentiment_classifier/keras_sentiment_classifier.py \
--ignore tests/estimators/keras_multiclass_text_classifier/keras_multiclass_text_classifier.py \
--cov=eli5 --cov-report=html --cov-report=term "$@"
3 changes: 3 additions & 0 deletions _ci/runtests_nodeps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ py.test --doctest-modules \
--ignore eli5/formatters/as_dataframe.py \
--ignore eli5/formatters/image.py \
--ignore tests/utils_image.py \
--ignore tests/utils_gradcam.py \
--ignore tests/estimators/keras_sentiment_classifier/keras_sentiment_classifier.py \
--ignore tests/estimators/keras_multiclass_text_classifier/keras_multiclass_text_classifier.py \
--cov=eli5 --cov-report=html --cov-report=term "$@"
Loading