def METHOD_NAME(self, model, net_output, sample, reduce=True):
    lprobs, target = self.get_lprobs_and_target(model, net_output, sample)
    n_correct = 0
    if isinstance(target, dict):
        t_lprobs = target["target_logprobs"]
        if not lprobs.batch_first:
            lprobs = lprobs.transpose(0, 1)
            t_lprobs = t_lprobs.transpose(0, 1)
        nsentences, seq_len = lprobs.size()[:2]
        ntokens = nsentences * seq_len
        t_probs = t_lprobs.exp()
        mask_indices = (
            net_output[1]["mask_indices"][0]
            if len(net_output[1]["mask_indices"]) > 0
            else None
        )
        # mask_indices is True for those masking frames
        if mask_indices is not None:  # B X T
            t_probs = t_probs.masked_fill(mask_indices.eq(False).unsqueeze(-1), 0)
            ntokens = mask_indices.int().sum()
        t_probs = t_probs.detach()
        t_lprobs = t_lprobs.detach()
        loss = (
            -(t_probs * (lprobs - t_lprobs)).sum()
            if reduce
            else -(t_probs * (lprobs - t_lprobs)).sum(-1, keepdim=True)
        )
        nll_loss = loss
    else:
        nsentences = target.size(0)
        mask = target.ne(self.padding_idx)
        loss, nll_loss = label_smoothed_nll_loss(
            lprobs.view(-1, lprobs.size(-1)),
            target.view(-1),
            self.eps,
            ignore_index=self.padding_idx,
            reduce=reduce,
        )
        n_correct = torch.sum(
            lprobs.argmax(-1).masked_select(mask).eq(target.masked_select(mask))
        )
        ntokens = torch.sum(mask)
    return loss, nll_loss, nsentences, ntokens, n_correct