Comments (1)
The default reference in IG is a zero scalar corresponding to each input tensor (effectively PAD for BERT). It can be customized by setting the 'baselines' parameter when calling the attribute function. For example (setting UNK as reference, assuming seq_len are the number of tokens in your input):
# Custom token for IG
from transformers import AutoTokenizer
from captum.attr import TokenReferenceBase
tokenizer = AutoTokenizer.from_pretrained('all-MiniLM-L6-v2') # Load your model's tokenizer
ref_token_id = tokenizer.unk_token_id # Choose the id of your desired token, you can call tokenizer.all_special_tokens for a list of all special tokens supported by your model
token_reference = TokenReferenceBase(reference_token_idx=ref_token_id) # Use Captum to generate a reference based on the number of tokens in your input
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
ref = token_reference.generate_reference(seq_len,device=device).unsqueeze(0)
Then when you call attribute set baselines=ref
. You can follow this guide as well: https://captum.ai/tutorials/IMDB_TorchText_Interpret
from captum.
Related Issues (20)
- What is the proper shape of baselines for DeepLiftShap?
- Adding IDGI to Captum HOT 4
- TCAV score computation doesn't preserve experimental set order
- Getting target dimension is not valid even though the output shape is shape in GRAD CAM .
- Deconvoltion and KernelSHAP methods create uninformative attribution maps
- TypeError: 'Concept' object is not iterable HOT 1
- Integrated Gradient without edge attribute
- Integrated Gradients for Llama2 May Produce Unstable Explanations for Long Contexts
- Negative Scores in Feature Ablation and Choosing Baselines for Non-Image Data
- Using IntegratedGradients to explain LSTM model HOT 1
- Captum TCAV train.py sgd_train_linear_model() Where do the weights come from?
- captum.concept.TCAV() custom classifier
- tcav diabetic retinopathy
- LayerConductance not working with llama2
- when there are many input features ,how to use the IntegratedGradients? HOT 1
- visualizer.render not working in jupyter notebook (javascript error) HOT 1
- Canβt create tensors as shown in first Captum Titanic tutorial?!
- Add support for Tuples of Modules in LayerLRP
- Integrated Gradients - Higher Convergence Delta with more Steps?
- Retain Gradients for Input Samples During Explainability Methods
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.