taishan1994 / pytorch_bert_bilstm_crf_ner

基于pytorch的bert_bilstm_crf中文命名实体识别
517 stars 81 forks source link

运行问题 #38

Closed wxr666666 closed 1 year ago

wxr666666 commented 1 year ago

作者您好 在用高版本torch运行您的代码时出现了和楼上一样的错误 在第89轮训练报错 ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (32,) + inhomogeneous part. image 更换低版本后 并修改这句代码后attention_masks = torch.from_numpy(np.array(encode_dict['attention_mask'])).long().unsqueeze(0).to(device) 还是会出现 image 大佬可以指点一下吗 谢谢!

taishan1994 commented 1 year ago

作者您好 在用高版本torch运行您的代码时出现了和楼上一样的错误 在第89轮训练报错 ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (32,) + inhomogeneous part. image 更换低版本后 并修改这句代码后attention_masks = torch.from_numpy(np.array(encode_dict['attention_mask'])).long().unsqueeze(0).to(device) 还是会出现 image 大佬可以指点一下吗 谢谢!

你predict里面代码是这样的吗:

try:
    attention_masks = torch.from_numpy(np.array(encode_dict['attention_mask'], dtype=np.uint8)).unsqueeze(0).to(device)
except Exception as e:
    attention_masks = torch.from_numpy(np.array(encode_dict['attention_mask'])).long().unsqueeze(0).to(device)
yyQUQ commented 1 year ago

作者您好,问题同上,更改你刚才给出的代码依然报错,请问哪里出问题了,烦请解答 24260a86b839a96d5e05c09055c0f96

taishan1994 commented 1 year ago

作者您好,问题同上,更改你刚才给出的代码依然报错,请问哪里出问题了,烦请解答 24260a86b839a96d5e05c09055c0f96

方便发下你的torch和transformers版本么

taishan1994 commented 1 year ago

作者您好,问题同上,更改你刚才给出的代码依然报错,请问哪里出问题了,烦请解答 24260a86b839a96d5e05c09055c0f96

改下这个试试:

token_ids = torch.from_numpy(np.array(encode_dict['input_ids'])).long().unsqueeze(0).to(device)
yyQUQ commented 1 year ago

谢谢大佬,好了!

yyQUQ commented 1 year ago

已经好了,太感谢啦!

@.***

@.*** |

---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2023年03月13日 18:34 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [taishan1994/pytorch_bert_bilstm_crf_ner] 运行问题 (Issue #38) |

作者您好,问题同上,更改你刚才给出的代码依然报错,请问哪里出问题了,烦请解答

方便发下你的torch和transformers版本么

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>