Monday, March 18, 2019

How I solved "Expected tensor for argument #1 ‘indices’ to have scalar type Long" error

Today I was trying to train my 2 layer LSTM on some long documentry extract and kept geting this irritating error
Expected tensor for argument #1 ‘indices’ to have scalar type Long; but got CPUFloatTensor instead (while checking arguments for embedding)

After many google searches and stackoverflow crawling, I figured out that the error was caused by the following line of code

dataset = TensorDataset(torch.Tensor(features), torch.Tensor(target))

Changed it to
dataset = TensorDataset(torch.tensor(features), torch.tensor(target))

and it fixed the issue

0 comments:

Post a Comment

Blog Archive