出現這個問題原因很多,尤其是使用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)