Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不同电脑运行出现IndexError: tensors used as indices must be long, byte or bool tensors问题 #48

Open
okfmeplz opened this issue Dec 10, 2024 · 2 comments

Comments

@okfmeplz
Copy link

换一个电脑之后运行main.py报错:
Traceback (most recent call last):
File "G:/BERT-Relation-Extraction/BERT-Relation-Extraction/ner_main.py", line 190, in
main(data_name)
File "G:/BERT-Relation-Extraction/BERT-Relation-Extraction/ner_main.py", line 182, in main
train.train()
File "G:/BERT-Relation-Extraction/BERT-Relation-Extraction/ner_main.py", line 52, in train
output = self.model(input_ids, attention_mask, labels)
File "C:\ProgramData\Anaconda3\envs\pytorchpy38_gpu_cuda111\lib\site-packages\torch\nn\modules\module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "G:\BERT-Relation-Extraction\BERT-Relation-Extraction\model.py", line 37, in forward
loss = -self.crf(seq_out, labels, mask=attention_mask.bool(), reduction='mean')
File "C:\ProgramData\Anaconda3\envs\pytorchpy38_gpu_cuda111\lib\site-packages\torch\nn\modules\module.py", line 1051, in call_impl
return forward_call(*input, **kwargs)
File "C:\ProgramData\Anaconda3\envs\pytorchpy38_gpu_cuda111\lib\site-packages\torchcrf_init
.py", line 102, in forward
numerator = self.compute_score(emissions, tags, mask)
File "C:\ProgramData\Anaconda3\envs\pytorchpy38_gpu_cuda111\lib\site-packages\torchcrf_init
.py", line 186, in _compute_score
score = self.start_transitions[tags[0]]
IndexError: tensors used as indices must be long, byte or bool tensors
请问大佬知道原因吗? TAT

@taishan1994
Copy link
Owner

可能是torch版本的问题。

@okfmeplz
Copy link
Author

if labels is not None:
  labels=labels.long()
  loss = -self.crf(seq_out, labels, mask=attention_mask.bool(), reduction='mean')

已解决,在model里错误代码前一句添加 labels=labels.long()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants