Integrated Gradients with Captum in a sequential model

key_crusher: <p>Hi, I am using Integrated Gradients with a NN model that has both sequential (LSTM) and non sequential layers (MLP). I was following the basic steps as given in the examples and ran into a weird error.<br>
Code snippet:<br>
test_tens.requires_grad_()<br>
attr = ig.attribute(test_tens, target=1, return_convergence_delta=False)<br>
attr = attr.detach().numpy()</p>
<p>error:<br>
in line 2 of the above snippet:<br>
" index 1 is out of bounds for dimension 1 with size 1 "</p>
<p>Probably some problem around the target thing, but not sure what to do</p>

Narine_Kokhlikyan: <p>Thank you for posting the issue, <a class="mention" href="/u/key_crusher">@key_crusher</a>! What are the shapes of the output of your model and <code>test_tens</code>?</p>

key_crusher: <p>Thank you for the reply <a class="mention" href="/u/narine_kokhlikyan">@Narine_Kokhlikyan</a>. The output dimensions = [batch_size, 1]. The shape of the test_tens = [batch_size, 103], here 103 is the feature count.</p>

Narine_Kokhlikyan: <p>I see! If the output dim is: output dimensions = [batch_size, 1]. then you might want to use <code>target=0</code>. Try that and let me know if you see the same error.</p>

key_crusher: <p>Thank you <a class="mention" href="/u/narine_kokhlikyan">@Narine_Kokhlikyan</a>. This worked but I still don’t understand this. Doesn’t the target value mean the value to which we want to check the contribution of the corresponding features ?</p>

Narine_Kokhlikyan: <p>Target value is basically the index to your output. In a specific case it could be predicted class index.<br>
It looks like you have only one dimensional output per example that’s why it can only be 0 or you don’t even need to specify it and leave <code>None</code></p>
<p>Here you can find a definition of it: <a href="https://christophm.github.io/interpretable-ml-book/terminology.html" rel="nofollow noopener">https://christophm.github.io/interpretable-ml-book/terminology.html</a></p>

key_crusher: <p>So, if I understand this correctly, had I used SoftMax instead of Sigmoid, then my output dimensions would have been [ batch_size, num_classes ] and then the target value would have been used to determine the contribution to the specific class and it could take values from 0 to num_classes - 1</p>
<p>Is this correct ? <a class="mention" href="/u/narine_kokhlikyan">@Narine_Kokhlikyan</a></p>

Narine_Kokhlikyan: <p>Yes, that sounds right!</p>

Saida2020: <p><span class="mention">@key_crushe</span> Hello , I have question for you related to this if it is possible.<br>
Why you did not specify baselines.<br>
I have some code same, takes sequence of 341 and give one classes from {1,2,3} the model take batch of data tensor of shape  [16,341] and return vector of length 16. I am new o capium but the following code did not work</p>
<p>ig = IntegratedGradients(model)<br>
test_input_tensor, targets = next(iter(testloader))<br>
test_input_tensor =test_input_tensor.requires_grad_()<br>
attr = ig.attribute(test_input_tensor,  target = 0 , return_convergence_delta=False)<br>
attr = attr.detach().numpy()</p>
<p>the error is related to baseline i tried to specify basline of the same shape of input but it doest work<br>
did i wrote somethong wrong here ?<br>
any suggestion?<br>
I</p>