def METHOD_NAME(
    self,
    text: torch.Tensor,
    text_lengths: torch.Tensor,
    max_length: Optional[int] = None,
) -> Tuple[torch.Tensor, torch.Tensor]:
    """Compute negative log likelihood(nll)
    Normally, this function is called in batchify_nll.
    Args:
        text: (Batch, Length)
        text_lengths: (Batch,)
        max_lengths: int
    """
    batch_size = text.size(0)
    # For data parallel
    if max_length is None:
        text = text[:, : text_lengths.max()]
    else:
        text = text[:, :max_length]
    # 1. Create a sentence pair like '<sos> w1 w2 w3' and 'w1 w2 w3 <eos>'
    # text: (Batch, Length) -> x, y: (Batch, Length + 1)
    x = F.pad(text, [1, 0], "constant", self.eos)
    t = F.pad(text, [0, 1], "constant", self.ignore_id)
    for i, l in enumerate(text_lengths):
        t[i, l] = self.sos
    x_lengths = text_lengths + 1
    # 2. Forward Language model
    # x: (Batch, Length) -> y: (Batch, Length, NVocab)
    y, _ = self.lm(x, None)
    # 3. Calc negative log likelihood
    # nll: (BxL,)
    METHOD_NAME = F.cross_entropy(y.view(-1, y.shape[-1]), t.view(-1), reduction="none")
    # nll: (BxL,) -> (BxL,)
    if max_length is None:
        METHOD_NAME.masked_fill_(make_pad_mask(x_lengths).to(METHOD_NAME.device).view(-1), 0.0)
    else:
        METHOD_NAME.masked_fill_(
            make_pad_mask(x_lengths, maxlen=max_length + 1).to(METHOD_NAME.device).view(-1),
            0.0,
        )
    # nll: (BxL,) -> (B, L)
    METHOD_NAME = METHOD_NAME.view(batch_size, -1)
    return METHOD_NAME, x_lengths