Open alimirgh75 opened 1 year ago
Hey @alimirgh75 , did you find a solution? I'm having the same issue
Not sure if its relevant but I got it working with LayerIntegratedGradients
. Posting here if people come across the issue
Heres a basic example
import torch
from transformers import BertTokenizer, BertForSequenceClassification
from captum.attr import IntegratedGradients, LayerIntegratedGradients
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
model = BertForSequenceClassification.from_pretrained('bert-base-uncased')
model.eval()
text = "hello world"
encoded = tokenizer(text, return_tensors="pt")
def predict(inputs, attention_mask=None):
return model(inputs, attention_mask=attention_mask).logits
lig = LayerIntegratedGradients(predict, model.bert.embeddings)
attributions_start, delta_start = lig.attribute(
inputs=encoded['input_ids'],
target=torch.tensor([0]),
additional_forward_args=encoded['attention_mask'],
return_convergence_delta=True
)
print(attributions_start, delta_start)
Hi all, I have an issue regarding inputs to attribute method of integrated gradient algorithm. I am using the GIT model for image captioning and defined the forward function to return one token_id of the caption at a time. The input of the model is the (processed_image , processed_caption) where "processed_caption" is the sequence of previously generated token_ids.
I am getting this error on
ig.attribute