Closed neeraj1909 closed 2 years ago
Hi @neeraj1909, thanks for your interest! I was unable to reproduce the issue your are describing, but it seems like maybe your versions are not up to date with our requirements. I updated our colab due to another issue, please try to run it now and see if it works.
Best, Hila.
Hi @hila-chefer, i still get the same error though i have updated your requirement.
@hila-chefer @leeeenammmmm I am also getting the same error :(
@hila-chefer @leeeenammmmm @neeraj1909
Fixed it. Add the following to the top of BertForSequenceClassification.py:
from transformers.modeling_outputs import SequenceClassifierOutput
While trying to run the file BERT_explainability.ipynb, I am getting this error.
Generated Error
NameError Traceback (most recent call last)
/home/cvpr/Transformer-Explainability/BERT_explainability.ipynb Cell 15' in <cell line: 11>() 8 true_class = 1 10 # generate an explanation for the input ---> 11 expl = explanations.generate_LRP(input_ids=input_ids, attention_mask=attention_mask, start_layer=0)[0] 12 # normalize scores 13 expl = (expl - expl.min()) / (expl.max() - expl.min())
File ~/Transformer-Explainability/BERT_explainability/modules/BERT/ExplanationGenerator.py:30, in Generator.generate_LRP(self, input_ids, attention_mask, index, start_layer) 28 def generate_LRP(self, input_ids, attention_mask, 29 index=None, start_layer=11): ---> 30 output = self.model(input_ids=input_ids, attention_mask=attention_mask)[0] 31 kwargs = {"alpha": 1} 33 if index == None:
File ~/miniconda3/envs/maskrcnn/lib/python3.8/site-packages/torch/nn/modules/module.py:1110, in Module._call_impl(self, *input, *kwargs) 1106 # If we don't have any hooks, we want to skip the rest of the logic in 1107 # this function, and just call forward. 1108 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks 1109 or _global_forward_hooks or _global_forward_pre_hooks): -> 1110 return forward_call(input, **kwargs) 1111 # Do not call functions when jit is used 1112 full_backward_hooks, non_full_backward_hooks = [], []
File ~/Transformer-Explainability/BERT_explainability/modules/BERT/BertForSequenceClassification.py:76, in BertForSequenceClassification.forward(self, input_ids, attention_mask, token_type_ids, position_ids, head_mask, inputs_embeds, labels, output_attentions, output_hidden_states, return_dict) 73 output = (logits,) + outputs[2:] 74 return ((loss,) + output) if loss is not None else output ---> 76 return SequenceClassifierOutput( 77 loss=loss, 78 logits=logits, 79 hidden_states=outputs.hidden_states, 80 attentions=outputs.attentions, 81 )
NameError: name 'SequenceClassifierOutput' is not defined
@hila-chefer @shirgur Please look into this issue.