This error is most likely thrown, if you pass an invalid index.
nn.CrossEntropyLoss (and thus also nn.NLLLoss, which will be called internally) expect a target tensor as a LongTensor containing the class indices in the range [0, nb_classes-1].
This error will be thrown, if you pass indices outside of the mentioned range.