Your model yields an output in the shape [batch_size, 4] (defined by the last linear layer) which contains logits for 4 classes. The target should thus contain class indices in the range [0, 3] and an index of 4 will be out of bounds. I’m not familiar with your use case, but in case your target contains 5 unique class indices, the model output should also have the shape [batch_size, nb_classes=5].
PS: you can post code snippets by wrapping them into three backticks ```, which makes debugging easier.