So criterion(output, target[c]) gives RuntimeError: dimension specified as 0 but tensor has no dimensions. See PyTorch doc's about CrossEntropyLoss, it expects inputs of shape: "Input: (N,C) where C = number of classes" and "Target: (N)".
target[c].view([1])
gives tensor([10]), which fixes the error.
return loss.data[0] / args.chunk_len gives IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number.
output
givestensor([[-1.5800e-01, ... 1.1632e-01]], grad_fn=<AddmmBackward>)
target
givestensor([10, 29, 14, 73, 96, 55, ..., 94])
target[c]
givestensor(10)
So
criterion(output, target[c])
givesRuntimeError: dimension specified as 0 but tensor has no dimensions
. See PyTorch doc's about CrossEntropyLoss, it expects inputs of shape: "Input: (N,C) where C = number of classes" and "Target: (N)".target[c].view([1])
givestensor([10])
, which fixes the error.return loss.data[0] / args.chunk_len
givesIndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
.