def METHOD_NAME(
    self,
    attention,
    input_lengths,
    target_lengths,
    max_input_len=None,
    max_target_len=None,
):
    """
    Computes the guided attention loss for a single batch
    Arguments
    ---------
    attention: torch.Tensor
        A padded attention/alignments matrix
        (batch, targets, inputs)
    input_lengths: torch.tensor
        A (batch, lengths) tensor of input lengths
    target_lengths: torch.tensor
        A (batch, lengths) tensor of target lengths
    max_input_len: int
        The maximum input length - optional,
        if not computed will be set to the maximum
        of target_lengths. Setting it explicitly
        might be necessary when using data parallelism
    max_target_len: int
        The maximum target length - optional,
        if not computed will be set to the maximum
        of target_lengths. Setting it explicitly
        might be necessary when using data parallelism
    Returns
    -------
    loss: torch.Tensor
        A single-element tensor with the loss value
    """
    soft_mask = self.guided_attentions(
        input_lengths, target_lengths, max_input_len, max_target_len
    )
    return (attention * soft_mask.transpose(-1, -2)).mean()