def score_function(scores, spans, mask, s_link=None):
    """[summary]

    Args:
        scores (Tensor(B, L-1, L-1)): ...
        spans (Tensor(B, L-1, L-1)): ground truth word segmentation, see SegmentField for details
        mask (Tensor(B, L-1, L-1)): L include <bos> and <eos>
        s_link (Tensor(B, L-1)): score for split point


    Returns:
        (Tensor(*)): scores of all spans for a batch
    """

    batch_size, seq_len, _ = scores.size()
    lens = mask[:, 0].sum(dim=-1)

    if s_link == None:
        return scores[mask & spans]
    else:
        return scores[mask & spans] + s_link.expand_as(scores)[mask & spans]