Constructing reference/baseline for LSTM - Layer Integrated Gradients
See original GitHub issue`# compute attributions and approximation delta using layer integrated gradients
attributions_ig, delta = lig.attribute((input_indices,h), (reference_indices,h),
n_steps=500, return_convergence_delta=True)
`
When I run the above code, I get the following error.
AssertionError: baseline input argument must be either a torch.Tensor or a number however <class ‘tuple’> detected
But the documentation says that a tuple can be passed as baseline argument.
Am I doing this right?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Generating LSTM attributions with integrated gradients
We first learned about integrated gradients (IG) in Chapter 8, Visualizing Convolutional Neural Networks. Unlike the other gradient-based attribution methods ...
Read more >Understand What Drives Predictions in Deep NLP Models | by ...
We'll focus on a method called integrated gradients, and use a pre-trained review sentiment classifier coming from the well known fast.ai ...
Read more >Integrated Gradients - Captum
This section of the documentation shows how to apply integrated gradients on models with different types of parameters and inputs using Captum.
Read more >Characterizing the sequence and prior chromatin ... - bioRxiv
Specifically, our sequence-only network MS uses a convolutional layer followed by a long short-term memory (LSTM) layer and multiple dense layers (Fig. 1a)....
Read more >Model interpretability with Integrated Gradients - Keras
Identify the input and the output. · Compute which features are important to a neural network when making a prediction on a particular...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
A tuple can be passed as a baseline (the tuple represents multiple inputs to the model), but this tuple is should effectively be a
Tuple[Union[PythonScalar, Tensor], ...]
. Based off your error, it seems that yourh
is actually a tuple (it’s not clear from your comments but perhaps you’re doingout, h = model.lstm(x)
rather thanout, (h, c) = model.lstm(x)
).Note that the inputs to LayerIG will be fed to the model directly. So if you want to pass in the hidden state you’d have to handle that in your model’s forward function.
However, with LayerIntegratedGradients, if given the LSTM layer, it should patch the last hidden state for you (i.e. the output of the LSTM Layer; it will also patch the other outputs as well - specifically the last cell state and output of the lstm itself).
I am assuming the last hidden state is what you want to patch, since this is the most common use-case. Unless you need to set the hidden state(s) to something specific, you should be able to just use LayerIntegratedGradients in the same way the tutorial shows.
If the case is you want to set the hidden state(s) to something else (i.e. a hidden state that does not correspond to the reference indices), e.g. a random vector, then I think you have a couple of options:
I think (1) is likely your best/easiest option in this case.
Thank you very much for your reply. I’ll try these out as soon as possible and report back here to close the issue.