def forward(self, input, target):
n, k = input.shape<EOL>losses = input.new_zeros(n)<EOL>for i in range(k):<EOL><INDENT>cls_idx = input.new_full((n,), i, dtype=torch.long)<EOL>loss = F.cross_entropy(input, cls_idx, reduction="<STR_LIT:none>")<EOL>if self.weight is not None:<EOL><INDENT>loss = loss * self.weight[i]<EOL><DEDENT>losses += target[:, i].float() * loss<EOL><DEDENT>if self.reduction == "<STR_LIT>":<EOL><INDENT>losses = losses.mean()<EOL><DEDENT>elif self.reduction == "<STR_LIT>":<EOL><INDENT>losses = losses.sum()<EOL><DEDENT>elif self.reduction != "<STR_LIT:none>":<EOL><INDENT>raise ValueError(f"<STR_LIT>")<EOL><DEDENT>return losses<EOL>
Calculate the loss

:param input: prediction logits
:param target: target probabilities
:return: loss