enjakokalj / TransSHAP

MIT License
45 stars 3 forks source link

'BaseModelOutputWithPoolingAndCrossAttentions' object has no attribute 'detach' #4

Open renhao1998 opened 2 years ago

renhao1998 commented 2 years ago

When i run the code follow README.md , if report error like this , can you explain what happened ? thanks a lot !

BERT_meets_Shapley/Code/TransSHAP_master/explainers/LIME_for_text.py in predict(self, data) 47 outputs = self.model(input_ids=tokens_tensor) 48 # logits = outputs[0] ---> 49 predictions = outputs.detach().cpu().numpy() 50 final = [self.softmax(x) for x in predictions] 51 return np.array(final)

AttributeError: 'BaseModelOutputWithPoolingAndCrossAttentions' object has no attribute 'detach'

0010SS commented 1 year ago

I faced the same issue and the code runs when I change predictions = outputs.detach().cpu().numpy() to predictions = outputs.logits.detach().cpu().numpy()