I was training the lstm network using pytorch and encountered this error
I was training the lstm network using pytorch and encountered this error in jupyter notebook.

RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-16-b6b1e0b8cad1&gt; in &lt;module&gt;()
      4 
      5 # train the model
----&gt; 6 train(net, encoded, epochs=n_epochs, batch_size=batch_size, seq_length=seq_length, lr=0.001, print_every=10)

&lt;ipython-input-14-43dc0cc515e7&gt; in train(net, data, epochs, batch_size, seq_length, lr, clip, val_frac, print_every)
     55 
     56             # calculate the loss and perform backprop
---&gt; 57             loss = criterion(output, targets.view(batch_size*seq_length))
     58             loss.backward()
     59             # `clip_grad_norm` helps prevent the exploding gradient problem in RNNs / LSTMs.

~\Anaconda3\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs)
    487             result = self._slow_forward(*input, **kwargs)
    488         else:
--&gt; 489             result = self.forward(*input, **kwargs)
    490         for hook in self._forward_hooks.values():
    491             hook_result = hook(self, input, result)

~\Anaconda3\lib\site-packages\torch\nn\modules\loss.py in forward(self, input, target)
    902     def forward(self, input, target):
    903         return F.cross_entropy(input, target, weight=self.weight,
--&gt; 904                                ignore_index=self.ignore_index, reduction=self.reduction)
    905 
    906 

~\Anaconda3\lib\site-packages\torch\nn\functional.py in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction)
   1968     if size_average is not None or reduce is not None:
   1969         reduction = _Reduction.legacy_get_string(size_average, reduce)
-&gt; 1970     return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
   1971 
   1972 

~\Anaconda3\lib\site-packages\torch\nn\functional.py in nll_loss(input, target, weight, size_average, ignore_index, reduce, reduction)
   1788                          .format(input.size(0), target.size(0)))
   1789     if dim == 2:
-&gt; 1790         ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
   1791     elif dim == 4:
   1792         ret = torch._C._nn.nll_loss2d(input, target, weight, _Reduction.get_enum(reduction), ignore_index)

RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #2 'target'


Cast output vector of your network to Long (you have Int) as the error says.

Oh, and please provide Minimal, Complete and Verifiable example next time you ask a question.
