出现这个问题原因很多,尤其是使用Jupyter时,一般而言,都是代码出错,或者多次运行。检查输入和模型是否批评。例如
在运行BertModel时,如果num_labels指定错了,和你输入不匹配,就会造成这种问题。
bert_config = BertConfig(vocab_size_or_config_json_file=30522, type_vocab_size=2, num_labels=len(label_list), hidden_size=128, num_hidden_layers=2, num_attention_heads=8, intermediate_size=256, hidden_dropout_prob=0.01, max_position_embeddings=128, attention_probs_dropout_prob=0.01 )
model = BertForSequenceClassification(bert_config)