Some loss functions (CrossEntropyLoss, NLLLoss) take class “indices” as targets.
Others, KLDivLoss, L1Loss, … take probability distributions as the targets, so you’d need to translate your target to “one-hot” encoding. In the olden days, we used scatter for this, but now there is a utility function: torch.nn.functional.one_hot — PyTorch 1.9.1 documentation
Best regards
Thomas