This repository was archived by the owner on Apr 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
This repository was archived by the owner on Apr 8, 2025. It is now read-only.
Converting FARM classification model to hugging face model #553
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
I'm not able to save a trained farm-classification model to hugging face format since I want to move to the other framework for more specific operations.
Error message
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-83-b2a730b6ac24> in <module>
----> 1 convert_to_transformers()
<ipython-input-82-8ab35f02f804> in convert_to_transformers()
12
13 # convert to transformers
---> 14 transformer_model = model.convert_to_transformers()
15
16 # save it (note: transformers use str instead of Path objects)
555 setattr(transformers_model, transformers_model.base_model_prefix, self.language_model.model)
556 transformers_model.classifier.load_state_dict(
--> 557 self.prediction_heads[0].feed_forward.feed_forward[0].state_dict())
558 elif self.prediction_heads[0].model_type == "token_classification":
559 # add more info to config
1043 if len(error_msgs) > 0:
1044 raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
-> 1045 self.__class__.__name__, "\n\t".join(error_msgs)))
1046 return _IncompatibleKeys(missing_keys, unexpected_keys)
1047
RuntimeError: Error(s) in loading state_dict for Linear:
size mismatch for weight: copying a param with shape torch.Size([2, 768]) from checkpoint, the shape in current model is torch.Size([2, 4096]).
To Reproduce
- Load language model "distilbert-base-german-cased"
- Add prediction head (TextClassificationHead)
- Save model
- Convert to huggingface using https://github.com/deepset-ai/FARM/blob/master/examples/conversion_huggingface_models.py
System:
- OS: Ubuntu 18.04
- GPU/CPU: i7
- FARM version: 0.4.8
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working