The cross-entropy loss function in torch.nn.CrossEntropyLoss takes in inputs of shape (N, C) and targets of shape (N). This means that targets are one integer per sample showing the index that needs to be selected by the trained model.
In my case, I’ve already got my target formatted as a one-hot-vector. And also, the output of my model has already gone through a softmax function. Now, I’m looking for a loss function to calculate the loss between my model’s predictions and the gold targets. Is there already such a loss function in Pytorch? Or do I need to develop my own? If I have to develop my own, could you please point me in the right direction?
How about this:
def cross_entropy(output: torch.Tensor, target: torch.Tensor):
    return -1.0 * (output.log() * target).mean()