Under “Training/Training the Network” it implements the loss function. I wrote it exactly the same way as it is written there, but I get a RuntimeError:
Traceback (most recent call last):
File "/home/erika/PycharmProjects/lstm_test/training.py", line 80, in <module>
network.output, loss = train(category_tensor, line_tensor)
File "/home/erika/PycharmProjects/lstm_test/training.py", line 50, in train
loss = criterion(network.output, category_tensor)
File "/home/erika/.local/lib/python3.5/site-packages/torch/nn/modules/module.py", line 357, in __call__
result = self.forward(*input, **kwargs)
File "/home/erika/.local/lib/python3.5/site-packages/torch/nn/modules/loss.py", line 170, in forward
self.ignore_index, self.reduce)
File "/home/erika/.local/lib/python3.5/site-packages/torch/nn/functional.py", line 1052, in nll_loss
return torch._C._nn.nll_loss(input, target, weight, size_average, ignore_index, reduce)
RuntimeError: Expected object of type Variable[torch.LongTensor] but found type Variable[torch.FloatTensor] for argument #1 'target'
I already tried to change “category_tensor” to a LongTensor, but this won’t work either.
Did anyone have the same problem?