The question sounds silly at first, so I'll elaborate:
I'm finetuning this model
ConvBertModel.from_pretrained("sarnikowski/convbert-medium-small-da-cased")
on a multilabel sentiment classification task. After having trained the model on my data, I load my fine-tuned model like this:
#Loading the best version (according to the validation loss) of the model:
trained_model = Tagger.load_from_checkpoint(
trainer.checkpoint_callback.best_model_path,
n_classes=3
)
trained_model.eval()
trained_model.freeze()
This trained_model should according to my understanding be equal to the architecture of the model before fine-tuning it (of course the weights have changed). But still I'm getting errors whenever I try to use my trained_model for other tasks. One of these tasks are getting the SHAP values for the predictions using the transformers-interpret library:
from transformers_interpret import MultiLabelClassificationExplainer
model = trained_model # my fine-tuned model
tokenizer = ConvBertTokenizer.from_pretrained("sarnikowski/convbert-medium-small-da-cased")
cls_explainer = MultiLabelClassificationExplainer(model, tokenizer)
word_attributions = cls_explainer("There were many aspects of the film I liked, but it was frightening and gross in parts. My parents hated it.")
Outputs the error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-40-0000c765e477> in <module>
2 cls_explainer = MultiLabelClassificationExplainer(
3 trained_model,
----> 4 tokenizer
5 )
6
3 frames
/usr/local/lib/python3.7/dist-packages/transformers_interpret/explainers/multilabel_classification.py in __init__(self, model, tokenizer, attribution_type, custom_labels)
35 custom_labels: Optional[List[str]] = None,
36 ):
---> 37 super().__init__(model, tokenizer, attribution_type, custom_labels)
38 self.labels = []
39
/usr/local/lib/python3.7/dist-packages/transformers_interpret/explainers/sequence_classification.py in __init__(self, model, tokenizer, attribution_type, custom_labels)
51 AttributionTypeNotSupportedError:
52 """
---> 53 super().__init__(model, tokenizer)
54 if attribution_type not in SUPPORTED_ATTRIBUTION_TYPES:
55 raise AttributionTypeNotSupportedError(
/usr/local/lib/python3.7/dist-packages/transformers_interpret/explainer.py in __init__(self, model, tokenizer)
17 self.tokenizer = tokenizer
18
---> 19 if self.model.config.model_type == "gpt2":
20 self.ref_token_id = self.tokenizer.eos_token_id
21 else:
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in __getattr__(self, name)
1206 return modules[name]
1207 raise AttributeError("'{}' object has no attribute '{}'".format(
-> 1208 type(self).__name__, name))
1209
1210 def __setattr__(self, name: str, value: Union[Tensor, 'Module']) -> None:
AttributeError: 'Tagger' object has no attribute 'config'
Here is a link to the whole notebook: https://colab.research.google.com/drive/1dH-rkZKslnBoRFvpsVvt9fj67NgMfLP0?usp=sharing
Am I wrong in thinking that the fine-tuned model do not behave in the same way as the original model?