Problem in Pytorch tutorial

I receive: “TypeError: torch.LongTensor constructor received an invalid combination of arguments - got (map), but expected one of:” while running the “An LSTM for Part-of-Speech Tagging” example.

def prepare_sequence(seq, to_ix):
idxs = map(lambda w: to_ix[w], seq)
tensor = torch.LongTensor(idxs) <<========== This line gives error
return autograd.Variable(tensor)

called by

inputs = prepare_sequence(training_data[0][0], word_to_ix)

Could anyone help to solve this problem?

You are having the exact problem as in the error message. idxs is a map function object which you are passing to the torch.LongTensor() constructor. One way to do this would be to first construct a list of idxs first, using something like list(map(lambda w: to_ix[w], seq)).

Great thanks a lot, the problem is solved…