def METHOD_NAME(self, model, net_output, target, reduction, log_probs):
    # N, T -> N * T
    target = target.view(-1)
    lprobs = model.get_normalized_probs(net_output, log_probs=log_probs)
    if not hasattr(lprobs, "batch_first"):
        logging.warning(
            "ERROR: we need to know whether "
            "batch first for the net output; "
            "you need to set batch_first attribute for the return value of "
            "model.get_normalized_probs. Now, we assume this is true, but "
            "in the future, we will raise exception instead. "
        )
    batch_first = getattr(lprobs, "batch_first", True)
    if not batch_first:
        lprobs = lprobs.transpose(0, 1)
    # N, T, D -> N * T, D
    lprobs = lprobs.view(-1, lprobs.size(-1))
    loss = F.nll_loss(
        lprobs, target, ignore_index=self.padding_idx, reduction=reduction
    )
    return lprobs, loss