Hello,
I want to make NLLLoss in pytorch to successfully treat multilabel target (e.g [0 0 1 0 1 1] ).
However I’ve got error that this loss is not for multitarget,
so I saw documents and find it considers input shape as (N,C) and target (N,).
I want to see how pytorch calculate NLLLoss since it expects values from log_softmax not softmax,
so thinking there may be difference with function I could build like below.
import torch
def NLLLoss(logs, targets):
ㅡout = torch.zeros_like(targets, dtype=torch.float)
ㅡfor i in range(len(targets)):
ㅡㅡout[i] = logs[i][targets[i]]
ㅡreturn -out.sum()/len(out)
But it seems it is made from C file, I don’t know C language sadly.
Is someone knows how NLLLoss is built in Pytorch (please change my code if possible…) or how to make nn.NLLLoss to successfully calculate for multitargetloss?
(I don’t want to use multimarginloss)