Hello, I am a beginner in Deep Learning and PyTorch. If my question is not relevant or does not follow the community guidelines, please pardon me.
I am studying the following Kaggle kernel and trying to replicate it:
https://www.kaggle.com/piantic/plant-pathology-2020-pytorch-for-beginner 4
In the section titled, “PreTrainedModels”, the author uses a resnet34 model and writes the following loss function class:
class DenseCrossEntropy(nn.Module):

    def __init__(self):
        super(DenseCrossEntropy, self).__init__()
        
        
    def forward(self, logits, labels):
        logits = logits.float()
        labels = labels.float()
        
        logprobs = F.log_softmax(logits, dim=-1)
        
        loss = -labels * logprobs
        loss = loss.sum(-1)

        return loss.mean()

I’ve read about Cross Entropy Loss function and I think I get the basic gist of it. But I do not understand what’s going on in this class. Can someone please explain what’s going on?
I can see its calculating the log softmax but then why the multiplication with the labels? And why loss.sum(-1)?
This is a Kaggle competition where given a plant image, we have to predict 4 classes (healthy or 3 types of diseases).
Thank you so much for your help!