patrickloeber / pytorch-chatbot

Simple chatbot implementation with PyTorch.
MIT License
420 stars 334 forks source link

RuntimeError: expected scalar type Long but found Int #17

Open Memerlin opened 1 year ago

Memerlin commented 1 year ago

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
LuluW8071 commented 9 months ago

The label for reposnse in train_dataloader should be Long.

In train.py

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