中文数据集是CMeEE,错误是:Error(s) in loading state_dict for BertForEntity:size mismatch for ner_classifier.1.weight;size mismatch for ner_classifier.1.bias;与这个入口参数有关:max_span_length,这个参数是用来初始化预训练bert的:self.width_embedding = nn.Embedding(max_span_length+1, width_embedding_dim),各位前辈可否给点建议。调试已久,没有思路,即使将max_span_length改成CMeEE的实体类别个数也报同样的错误。具体报错如下:
03/09/2022 18:35:29 - INFO - transformers.modeling_utils - All the weights of BertForEntity were initialized from the model checkpoint at /data/sciERC-bert-model/ent-scib-ctx0/.
If your task is similar to the task the model of the ckeckpoint was trained on, you can already use BertForEntity for predictions without further training.
Traceback (most recent call last):
File "E:\java-workspace\PureTest\wonerMain.py", line 154, in
model = EntityModel(args, num_ner_labels=num_ner_labels)
File "E:\java-workspace\PureTest\wonerModel.py", line 174, in init
self.bert_model = BertForEntity.from_pretrained(bert_model_name, num_ner_labels=num_ner_labels, max_span_length=args.max_span_length)
File "C:\ProgramData\Anaconda3\envs\pytorch37\lib\site-packages\transformers\modeling_utils.py", line 781, in from_pretrained
model.class.name, "\n\t".join(error_msgs)
RuntimeError: Error(s) in loading state_dict for BertForEntity:
size mismatch for ner_classifier.1.weight: copying a param with shape torch.Size([7, 150]) from checkpoint, the shape in current model is torch.Size([10, 150]).
size mismatch for ner_classifier.1.bias: copying a param with shape torch.Size([7]) from checkpoint, the shape in current model is torch.Size([10]).