taishan1994 / pytorch_triple_extraction

基于pytorch的中文三元组提取(命名实体识别+关系抽取)
330 stars 41 forks source link

隐层 #8

Closed newbieonCV closed 2 years ago

newbieonCV commented 2 years ago

Traceback (most recent call last): File "get_result.py", line 120, in entities = get_ner_result(raw_text) File "get_result.py", line 37, in get_ner_result pred_entities = bertForNer.predict(raw_text, model_path) File "/home/shijunwei/project/extract/extract/bert_bilstm_crf_ner/main.py", line 177, in predict logits = model(token_ids.to(device), attention_masks.to(device), token_type_ids.to(device), None) File "/home/shijunwei/.local/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, *kwargs) File "/home/shijunwei/project/extract/extract/bert_bilstm_crf_ner/bert_ner_model.py", line 75, in forward seqout, (hn, ) = self.lstm(seq_out, hidden) File "/home/shijunwei/.local/lib/python3.7/site-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(input, **kwargs) File "/home/shijunwei/.local/lib/python3.7/site-packages/torch/nn/modules/rnn.py", line 577, in forward self.dropout, self.training, self.bidirectional, self.batch_first) RuntimeError: Input and hidden tensors are not at the same device, found input tensor at cuda:0 and hidden tensor at cpu 感谢博主之前的解答。这个问题,我找了相关的博客,需要将hidden里的元素放入gpu,但是代码确实放进去了,还是会有改bug