I have one model training and testing on XLMRobertaModelSequenceClassification. I used two labels (class 1 and 0) for classifying.Now I would like to use this model (called model_08 on script) for LIME. But I have one error TypeError: 'collections.OrderedDict' object is not callable
I put below the script
from transformers import XLMRobertaForSequenceClassification, AdamW, BertConfig
tokenizer = AutoTokenizer.from_pretrained('m-polignano-uniba/bert_uncased_L-12_H-768_A-12_italian_alb3rt0', do_lower_case=True)
model = XLMRobertaForSequenceClassification.from_pretrained(
"xlm-roberta-base",
num_labels = 2,
output_attentions = False,
output_hidden_states = False,
)
# Tell pytorch to run this model on the GPU.
device = torch.device("cpu")
model.to(device)
Application fine-tuned model to generate predictions on the test set.
model.load_state_dict(torch.load("/content/model_08.pt", map_location=torch.device('cpu')))
class_names = ['0','1']
def predictor(texts):
outputs = model(**tokenizer(texts, return_tensors="pt",
padding=True)).to(device)
tensor_logits = outputs[0]
probas = F.softmax(tensor_logits).detach().numpy()
return probas
text = 'Building more bypasses will help the environment by reducing pollution and traffic jams in towns and cities.'
print(tokenizer(text, return_tensors='pt', padding=True))
explainer = LimeTextExplainer(class_names=class_names)
exp = explainer.explain_instance(text, predictor, num_features=20, num_samples=2000)
exp.show_in_notebook(text=text)