bentrevett/pytorch-sentiment-analysis

.squeeze(1)

pberko opened this issue · 5 comments

Hello,

Thanks for the tutortial!

I tried to copy the first rnn (Simple Sentiment Analysis) to Pycharm and run the same code, but I got the error:

Target size (torch.Size([1, 64])) must be the same as input size (torch.Size([64]))

on the row
loss = criterion(predictions, batch.label)

File "/usr/local/lib/python3.8/dist-packages/torch/nn/functional.py", line 2958, in binary_cross_entropy_with_logits raise ValueError("Target size ({}) must be the same as input size ({})".format(target.size(), input.size())) ValueError: Target size (torch.Size([1, 64])) must be the same as input size (torch.Size([64]))

after trying to fix that by adding
batch.label = batch.label.squeeze(0)
Althoght the code runs but it does not seem to work:

accuracy stays with 0 and loss is minus:
Epoch: 01 | Epoch Time: 7m 3s Train Loss: -56.793 | Train Acc: 0.00% Val. Loss: -108.977 | Val. Acc: 0.00%

I have the same problem...

What version of PyTorch and torchtext are you using?

@bentrevett thank you for your response.

In [2]: torchtext.version
Out[2]: '0.10.0'

In [4]: torch.version
Out[4]: '1.9.0'

for me also not working for the versions:
In [2]: torchtext.version
Out[2]: '0.10.0'

In [2]: torch.version
Out[2]: '1.9.0'

worked after
source ****/venv/Scripts/activate

python -m pip install torch==1.8.0+cpu torchvision==0.9.0+cpu torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html

python -m pip install torchtext==0.90

thanks!