The error message points to an out-of-bounds indexing in nn.NLLLoss or nn.CrossEntropyLoss (which calls into nn.NLLLoss).
Usually this happens, if your target doesn’t contain class indices in the range [0, nb_classes-1].
Could you check the min and max values of your target tensors and make sure they are in the right range?