Hello fellow coders!
I’m just getting started with pytorch because I want to use it for my bachelor thesis. I wanted to learn more about classification with RNNs. So I started this tutorial:
http://pytorch.org/tutorials/intermediate/char_rnn_classification_tutorial.html#sphx-glr-intermediate-char-rnn-classification-tutorial-py 27
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?
Thank you very much for helping me!