【发布时间】:2020-10-23 11:59:44
【问题描述】:
我下载了基于 bert 的预训练模型。我编辑 config.json(从 512 到 256)
"max_position_embeddings": 256,
那我想用bert模型,
from transformers import BertForSequenceClassification
model = BertForSequenceClassification.from_pretrained(
MODEL_PATH,
num_labels = 2, # The number of output labels--2 for binary classification.
output_attentions = False,
output_hidden_states = False,
)
# Tell pytorch to run this model on the GPU.
model.cuda()
但它会引发错误
Error(s) in loading state_dict for BertForSequenceClassification:
size mismatch for bert.embeddings.position_embeddings.weight: copying a param with shape torch.Size([512, 768]) from checkpoint, the shape in current model is torch.Size([256, 768]).
我知道原因是因为我更改了最大序列长度。如果我想更改最大序列长度,正确的方法是什么?
【问题讨论】:
标签: pytorch transform bert-language-model