taishan1994 / BERT-BILSTM-CRF

使用BERT-BILSTM-CRF进行中文命名实体识别。
291 stars 32 forks source link

运行main.py报错 #13

Open Bonizhao opened 5 months ago

Bonizhao commented 5 months ago

C:\Users\35845\Desktop\连铸\程序\模型构建\ner命名实体识别\BERT-BiLSTM-CRF\ner>python main.py ['O', 'B-故障设备', 'I-故障设备', 'B-故障原因', 'I-故障原因'] {'O': 0, 'B-故障设备': 1, 'I-故障设备': 2, 'B-故障原因': 3, 'I-故障原因': 4} C:\Users\35845\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\nn\modules\rnn.py:62: UserWarning: dropout option adds dropout after all but last recurrent layer, so non-zero dropout expects num_layers greater than 1, but got dropout=0.1 and num_layers=1 warnings.warn("dropout option adds dropout after all but last " C:\Users\35845\AppData\Local\Programs\Python\Python38\lib\site-packages\transformers\optimization.py:429: FutureWarning: This implementation of AdamW is deprecated and will be removed in a future version. Use the PyTorch implementation torch.optim.AdamW instead, or set no_deprecation_warning=True to disable this warning warnings.warn( Traceback (most recent call last): File "main.py", line 189, in main(data_name) File "main.py", line 183, in main report = train.test() File "main.py", line 66, in test self.model.load_state_dict(torch.load(os.path.join(self.output_dir, "pytorch_model_ner.bin"),map_location='cpu')) File "C:\Users\35845\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\nn\modules\module.py", line 1604, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for BertNer: Unexpected key(s) in state_dict: "bert.embeddings.position_ids". 网上查了一圈还是不知道怎么解决,求大佬解惑

taishan1994 commented 5 months ago

hugging face的模型和我训练好的模型都下载好放在指定位置了么。

Bonizhao commented 5 months ago

是chinese-bert-wwm-ext目录下的三个文件吗,我看里面已经有了,就没去hugging face下。。

Bonizhao commented 5 months ago

是chinese-bert-wwm-ext目录下的三个文件吗,我看里面已经有了,就没去hugging face下。。

应该不是那三个文件的问题,我刚刚去hugging face重新下载替换了一下,但是还是没解决问题

Bonizhao commented 5 months ago

已解决,transformer版本不对,之前是4.36.2,谢谢大佬~

ASan1527 commented 2 weeks ago

大佬你用的那个版本的transformers

taishan1994 commented 2 weeks ago

试试4.22.0。