def METHOD_NAME(log_p_attn, text_lengths, feats_lengths):
    """
    Args:
        log_p_attn (Tensor): 
            Batched log probability of attention matrix (B, T_feats, T_text)
        text_lengths (Tensor): 
            Text length tensor (B,)
        feats_legnths (Tensor): 
            Feature length tensor (B,)
    Returns:
        Tensor: 
            Batched token duration extracted from `log_p_attn` (B,T_text)
        Tensor: 
            binarization loss tensor ()
    """
    B = log_p_attn.shape[0]
    T_text = log_p_attn.shape[2]
    device = log_p_attn.place
    bin_loss = 0
    ds = paddle.zeros((B, T_text), dtype="int32")
    for b in range(B):
        cur_log_p_attn = log_p_attn[b, :feats_lengths[b], :text_lengths[b]]
        viterbi = _monotonic_alignment_search(cur_log_p_attn.numpy())
        _ds = np.bincount(viterbi)
        ds[b, :len(_ds)] = paddle.to_tensor(
            _ds, place=device, dtype="int32")  
        t_idx = paddle.arange(feats_lengths[b])
        bin_loss = bin_loss - cur_log_p_attn[t_idx, viterbi].mean()
    bin_loss = bin_loss / B
    return ds, bin_loss