'simpletransformers: size mismatch for classifier.weight and classifier.bias even after providing correct arguments with simpletransformers library
I'm using simpletransformers library for fine-tuning a BERT model for Named Entity Recognition (NER) on a custom dataset which is having 13 distinct entities.
Even after providing model_args.labels_list, the NERModel() produce the following error.
RuntimeError: Error(s) in loading state_dict for BertForTokenClassification:
size mismatch for classifier.weight: copying a param with shape torch.Size([9, 768]) from checkpoint, the shape in current model is torch.Size([13, 768]).
size mismatch for classifier.bias: copying a param with shape torch.Size([9]) from checkpoint, the shape in current model is torch.Size([13]).
Sample code:
from simpletransformers.ner import NERModel, NERArgs
model_args = NERArgs()
model_args.labels_list = ["ENT1", "ENT2", "ENT3", "ENT4", "ENT5", "ENT6", "ENT7", "ENT8", "ENT9", "ENT10", "ENT11", "ENT12", "ENT13"] # this list is having thirteen entities from my dataset
model = NERModel(
"bert",
"dslim/bert-base-NER",
args=model_args,
)
Solution 1:[1]
I had the same problem. I updated my simpletransformers and it solved the problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
