• Stars
    star
    215
  • Rank 180,125 (Top 4 %)
  • Language
    Jupyter Notebook
  • License
    MIT License
  • Created about 7 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python/Keras implementation of integrated gradients presented in "Axiomatic Attribution for Deep Networks" for explaining any model defined in Keras framework.

Integrated Gradients

Python implementation of integrated gradients [1]. The algorithm "explains" a prediction of a Keras-based deep learning model by approximating Aumannโ€“Shapley values for the input features. These values allocate the difference between the model prediction for a reference value (all zeros by default) and the prediction for the current sample among the input features. TensorFlow version is implemented now!

Usage

Using Integrated_Gradients is very easy. There is no need to modify your Keras model.
Here is a minimal working example on UCI Iris data.

  1. Build your own Keras model and train it. Make sure to complie it!
from IntegratedGradients import *
from keras.layers import Dense
from keras.layers.core import Activation

X = np.array([[float(j) for j in i.rstrip().split(",")[:-1]] for i in open("iris.data").readlines()][:-1])
Y = np.array([0 for i in range(100)] + [1 for i in range(50)])

model = Sequential([
    Dense(1, input_dim=4),
    Activation('sigmoid'),
])
model.compile(optimizer='sgd', loss='binary_crossentropy')
model.fit(X, Y, epochs=300, batch_size=10, validation_split=0.2, verbose=0)
  1. Wrap it with an integrated_gradients instance.
ig = integrated_gradients(model)
  1. Call explain() with a sample to explain.
ig.explain(X[0])
==> array([-0.25757075, -0.24014562,  0.12732635,  0.00960122])

Features

  • supports both Sequential() and Model() instances.
  • supports both TensorFlow and Theano backends.
  • works on models with multiple outputs.
  • works on models with mulitple input branches.

Example notebooks

  • More thorough example can be found here.
  • There is also an example of running this on VGG16 model.
  • If your network has multiple input sources (branches), you can take a look at this.

MNIST example

We trained a simple CNN model (1 conv layer and 1 dense layer) on the MNIST imagesets. Here are some results of running integrated_gradients on the trained model and explaining some samples.

alt text alt text alt text alt text alt text alt text alt text

References

  1. Sundararajan, Mukund, Ankur Taly, and Qiqi Yan. "Axiomatic Attribution for Deep Networks." arXiv preprint arXiv:1703.01365 (2017).

Email me at hiranumn at cs dot washington dot edu for questions.

More Repositories

1

DeepAccNet

Pytorch/Python3 implementation of DeepAccNet, protein model accuracy evaluator.
Python
73
star
2

DeepATACseq

Repository for the code for DeepATAC project presented at WCB workshop in ICML2017
Jupyter Notebook
21
star
3

IntegratedGradientsTF

Tensorflow implementation of integrated gradients presented in "Axiomatic Attribution for Deep Networks". It explains connections between two tensors.
Jupyter Notebook
16
star
4

DLmodels

Personal experiments and implementation examples of deep learning papers.
Jupyter Notebook
11
star
5

DeepAccNet-TF

Python/TF1 implementation of DeepAccNet (https://www.biorxiv.org/content/10.1101/2020.07.17.209643v1)
Python
10
star
6

ATAC_peak

Deep learning framework to predict TF binding from DNA-sequence and ATAC-seq signals.
Jupyter Notebook
6
star
7

LocalAccuracyPredictor

Tensorflow/Python implementation of local accuracy predictor for proteins
Jupyter Notebook
5
star
8

BackpropDemonstration

Demonstration of back-propagation for the undergrad ML class that I TAed [Archived]
Python
3
star
9

PyProtein

An easy interface to extract data from pdbs using the rosetta framework
Python
3
star
10

jlVCF

A simple VCF file parser for Julia 3.0
Julia
3
star
11

GraphConv

Implementation of graph convolution layers
Jupyter Notebook
1
star
12

ChipSeqUtil.jl

Utility files for analyzing ChIP-Seq data.
Julia
1
star
13

jlBAM

A simple bam file reader for Julia 5.0
Julia
1
star
14

BackboneEstimator.py

Estimates backbone quality based on C beta (or C alpha) distance maps.
Jupyter Notebook
1
star
15

AminoAcids2BackboneAngles

Sample deep-learning notebooks for presentation given at BakerLab @ UW
Jupyter Notebook
1
star