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)).