hunkim / PyTorchZeroToAll

Simple PyTorch Tutorials Zero to ALL!
http://bit.ly/PyTorchZeroAll
3.89k stars 1.2k forks source link

Fixed dimension bugs in 12_2_hello_rnn.py #49

Open kibitzing opened 5 years ago

kibitzing commented 5 years ago

Error messages were

  1. "RuntimeError: dimension specified as 0 but tensor has no dimensions". (line: 24) --> I changed the dimension using '.view'(-1, 1)' to make the label dimension to be 1 instead of "no dimensions"
  2. "IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number" (line: 80) --> Since the output of the Cross Entropy Loss here has no dimension, deleted the index term '[0]'.

It was tested with Pytorch 1.1.

hunkim commented 4 years ago

Could you check if the new merge fixed this problem? Thanks!