https://codechina.csdn.net/mirrors/chenxiaoyouyou/Bert-BiLSTM-CRF-pytorch
README.md
Bert-BiLSTM-CRF-pytorch
使用谷歌预训练bert做字嵌入的BiLSTM-CRF序列标注模型
本模型使用谷歌预训练bert模型(https://github.com/google-research/bert), 同时使用pytorch-pretrained-BERT(https://github.com/huggingface/pytorch-pretrained-BERT) 项目加载bert模型并转化为pytorch参数,CRF代码参考了SLTK(https://github.com/liu-nlper/SLTK)
准备数据格式参见data
模型参数可以在config中进行设置
运行代码
python main.py train --use_cuda=False --batch_size=10
pytorch.bin 百度网盘链接 链接:https://pan.baidu.com/s/160cvZXyR_qdAv801bDY2mQ 提取码:q67r
作者也是新手,很希望看到的大家能够提意见,共同学习
eval epoch: 0| loss: 13.609519958496094
当输出第一轮的结果后,开始报错
eval epoch: 0| loss: 13.609519958496094
Traceback (most recent call last):
File “main.py”, line 94, in
fire.Fire()
File “D:\tools\python\lib\site-packages\fire\core.py”, line 141, in Fire
component_trace = _Fire(component, args, parsed_flag_args, context, name)
File “D:\tools\python\lib\site-packages\fire\core.py”, line 471, in _Fire
target=component.name)
File “D:\tools\python\lib\site-packages\fire\core.py”, line 681, in _CallAndUpdateTrace
component = fn(*varargs, **kwargs)
File “main.py”, line 67, in train
save_model(model,epoch)
File “D:\1学习文档\nlp\代码\Bert-BiLSTM-CRF-pytorch-master\utils.py”, line 81, in save_model
torch.save(model.state_dict(), full_name)
File “D:\tools\python\lib\site-packages\torch\serialization.py”, line 369, in save
with _open_file_like(f, ‘wb’) as opened_file:
File “D:\tools\python\lib\site-packages\torch\serialization.py”, line 230, in _open_file_like
return _open_file(name_or_buffer, mode)
File “D:\tools\python\lib\site-packages\torch\serialization.py”, line 211, in init
super(_open_file, self).init(open(name, mode))
OSError: [Errno 22] Invalid argument: ‘result\2021-06-20#17:00:29–epoch:0’
指向了这里 File “D:\1学习文档\nlp\代码\Bert-BiLSTM-CRF-pytorch-master\utils.py”, line 81, in save_model
torch.save(model.state_dict(), full_name)
参数错误,未找出原因
实验了本机与实验室的机器都是一样的结果