Text-Classification-LSTMs-PyTorch icon indicating copy to clipboard operation
Text-Classification-LSTMs-PyTorch copied to clipboard

Using a target size (torch.Size([64])) that is different to the input size (torch.Size([64, 1])

Open astraleosun opened this issue 3 years ago • 1 comments

https://github.com/FernandoLpz/Text-Classification-LSTMs-PyTorch/blob/2f8bada8190b76ca9bbe8f0694fb79da2c2a4d46/main.py#L89 Hello, First I got a ValueError: Using a target size (torch.Size([64])) that is different to the input size (torch.Size([64, 1])) is deprecated. Please ensure they have the same size. Then I altered y_pred to y_pred.squeeze().detach(), but I got a new error showing element 0 of tensors does not require grad and does not have a grad_fn where in line 93, loss.backward(). So can you help me? what should I do?

astraleosun avatar Apr 11 '22 13:04 astraleosun

@bajixing Add at main.py after line 85 the next code line : y = y.unsqueeze(1), will solve out the problem for you.

NivNagli avatar May 14 '22 17:05 NivNagli