Comments (8)
Thanks @orionr! One thing to note about how I implemented support for this feature in my fork of the shap repository (which is linked to in the notebook above) is that I allow the user to optionally provide a custom function that takes as input the (multipliers, original input, references)
and returns the final scores - I think the equivalent in Captum would be allowing a user to provide a custom function that varies the logic in this line:
captum/captum/attr/_core/deep_lift.py
Line 207 in 2fea0d7
The main reason to provide some flexibility here (in terms of how the user might like to combine the multipliers with the inputs/references to give the final contribution scores) is that for one-hot encoded sequences, sometimes getting the contributions is not as simple as doing multiplier*difference-from-baseline
. Specifically, imagine you have a one-hot encoded sequence where only one character at each position can be a 1 (as is often done in character encodings in NLP, or sequence encodings in genomics). Say there are four characters, and the encoding at some position in the input sequence is [1,0,0,0]
while the reference at that position is [0,1,0,0]
. DeepLIFT will assign a contribution to the first character having a difference-from-reference of +1 and the second character having a difference-from-reference of -1. However, because of the one-hot encoding constraint that only one character at each position can have a 1, the difference-from-reference of -1 in the second character is in some sense "due to" the difference-from-reference of +1 in the first character. Thus, for ease of visualization, we add the contribution of the second character (the one that is absent from the input) to the contribution of the character that is actually present in the input, and then only visualize the total contribution on the character that is actually present in the input. If we did not do this, then at visualization time we would we get scores on more than one character at each position, which is extremely confusing given the one-hot encoding constraint!
Just something I thought I would highlight since @NarineK referenced this feature and I wasn't sure if you had decided to start working on it yet. Please let me know if you would like me to clarify more, or if anything I have said does not make sense!
Thank you again for the hard work!
Avanti
from captum.
Hi @AvantiShri, sure, that makes sense to me. We can take an additional custom function as an argument and in case it is not provided we can use our default logic. This shouldn't be a big change. I'm currently adding layer/neuron based support and will add this functionality as next.
from captum.
Hi Avanti, Thank you very much for the feedback! Happy to hear that you liked it.
I think that it shouldn't be an issue to return the multipliers.
Thank you very much for jupyter notebook. I'll check it out :)
from captum.
Not going to close this, since we can consider it as a feature request that we aren't working on yet. Thanks, @AvantiShri!
from captum.
Awesome, thank you!
from captum.
Hi @AvantiShri
Thanks for suggesting this. I have a question regarding the custom function and would really appreciate it if you could give some advice.
so I have used captum deeplift to calculate my attributions and followed the best recipe ( I basically run captum deep lift on my sequence with 10 different dinucleotides shuffled sequences and averaged over them).
Now I'm trying to get the hypothetical contributions and planning to use the same approach but this time input a custom function. I couldn't understand the example on the deepShap repo, and inputting it to the captum function is not working, would you be able to kindly suggest a simple formula to use the input, base and multiplier in a custom function? or if you already have a function that works for this matter, I would really appreciate it if you could share it.
from captum.
from captum.
@AvantiShri Thanks Avanti, I hope all is well now. The slides are really helpful I appreciate it.
from captum.
Related Issues (20)
- Layer Feature Attribution for RNN models HOT 2
- Example for LMGradientAttribution is missing. HOT 4
- AttributeError: 'NoneType' object has no attribute 'relevance_input' HOT 4
- Error using Integrated Gradients on MPS HOT 1
- ImportError for 'TextTemplateFeature' and 'TextTokenFeature' from 'captum.attr' HOT 2
- Addition of Important Direction Gradient Integration (IDGI) framework
- Explainability for embeddings
- Uninitialized target_tokens Variable in LLMGradientAttribution.attribute Method
- what is the meaning of contribution? HOT 1
- For sentence classification using BERT, PAD token is used in IG/Deeplift? HOT 1
- Integrated Gradients for Llama2
- BertForMultipleChoice works without captum, breaks with it?
- Possible to modify initial LRP score to compute CLRP(contrastive lrp)?
- Incorrect indexing for max pooling layers with DeepLIFT HOT 1
- Integrated gradient on a function of models
- NoiseTunnel on LayerIntegratedGradients Perturbs Input Instead of Attribution Target (RunetimeError)
- Integrated Gradients for Frame-Level Classification Tasks
- What is the proper shape of baselines for DeepLiftShap?
- Adding IDGI to Captum HOT 2
- TCAV score computation doesn't preserve experimental set order
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from captum.