Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: dimension specified as 0 but tensor has no dimensions #24

Open
jiapei100 opened this issue May 8, 2018 · 2 comments
Open

Comments

@jiapei100
Copy link

line 78 of 12_2_hello_rnn.py
What's wrong with it? loss += criterion(output, label)

$ python 12_2_hello_rnn.py
Model(
(rnn): RNN(5, 5, batch_first=True)
)
predicted string: lTraceback (most recent call last):
File "12_2_hello_rnn.py", line 78, in
loss += criterion(output, label)
File "/home/jiapei/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 491, in call
result = self.forward(*input, **kwargs)
File "/home/jiapei/.local/lib/python3.6/site-packages/torch/nn/modules/loss.py", line 759, in forward
self.ignore_index, self.reduce)
File "/home/jiapei/.local/lib/python3.6/site-packages/torch/nn/functional.py", line 1442, in cross_entropy
return nll_loss(log_softmax(input, 1), target, weight, size_average, ignore_index, reduce)
File "/home/jiapei/.local/lib/python3.6/site-packages/torch/nn/functional.py", line 1328, in nll_loss
if input.size(0) != target.size(0):
RuntimeError: dimension specified as 0 but tensor has no dimensions

@wbaik
Copy link

wbaik commented May 10, 2018

I ran into the same issue, guessing this happened from a recent update in pytorch . @jiapei100
A solution, though I am sure this is not the best way, was adding this before line 78
label = label.unsqueeze(0)

Is this a better solution? Adding this after line 19 @hunkim
y_data = [[y] for y in y_data]

@lauraliu61b
Copy link

I guess another possible solution is to replace the original label at line 78 with torch.LongTensor([label]).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants