我在b站跟着一名up主在做医疗实体命名识别的项目,我用的是自己标注的数据源。目前在进行到模型测评时出现错误。
Traceback (most recent call last):
File "D:\py-project\test4_16\Pytorch_BiLSTM_CRF\test.py", line 18, in
y_pred = model(input, mask)
^^^^^^^^^^^^^^^^^^
File "D:\py-project\venv\Lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\py-project\test4_16\Pytorch_BiLSTM_CRF\model.py", line 25, in forward
out = self._get_lstm_feature(input)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\py-project\test4_16\Pytorch_BiLSTM_CRF\model.py", line 20, in _get_lstm_feature
out = self.embed(input)
^^^^^^^^^^^^^^^^^
File "D:\py-project\venv\Lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\py-project\venv\Lib\site-packages\torch\nn\modules\sparse.py", line 162, in forward
return F.embedding(
^^^^^^^^^^^^
File "D:\py-project\venv\Lib\site-packages\torch\nn\functional.py", line 2210, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Expected tensor for argument #1 'indices' to have one of the following scalar types: Long, Int; but got torch.FloatTensor instead (while checking arguments for embedding)
以上是错误信息
接下来给大家看一下那一段的源码
from utils import *
from model import *
from config import *
if __name__ == '__main__':
dataset = Dataset('test')
loader = data.DataLoader(dataset, batch_size=100, collate_fn=collate_fn)
with torch.no_grad():
model = torch.load(MODEL_DIR + 'model_99.pth', map_location=DEVICE)
for b, (input, target, mask) in enumerate(loader):
y_pred = model(input, mask)
loss = model.loss_fn(input, target, mask)
print('>> batch:', b, 'loss:', loss.item())
还请大家们帮忙分析指正。第一次用csdn,有哪些错误的地方还请大家多包涵