pytorch-chatbot icon indicating copy to clipboard operation
pytorch-chatbot copied to clipboard

RuntimeError: expected scalar type Long but found Int

Open Memerlin opened this issue 1 year ago • 1 comments

When I try to run train.py, I run into this error:

Traceback (most recent call last):
  File "C:\Users\Lucy\Documents\Chatbot maybe\train.py", line 83, in <module>
    loss = criterion(outputs, labels)
  File "C:\Users\Lucy\anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "C:\Users\Lucy\anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\loss.py", line 1174, in forward
    return F.cross_entropy(input, target, weight=self.weight,
  File "C:\Users\Lucy\anaconda3\envs\pytorch\lib\site-packages\torch\nn\functional.py", line 3029, in cross_entropy
    return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)
RuntimeError: expected scalar type Long but found Int

Memerlin avatar May 02 '23 00:05 Memerlin

The label for reposnse in train_dataloader should be Long.

In train.py

labels = labels.to(dtype=torch.long).to(device)

LuluW8071 avatar Feb 14 '24 09:02 LuluW8071