def split_tgt_sequence(tgt, bos, eos):
    """
    Split gold target into previous tokens and prediction target.
    For examples in text, `[hello, world, !] -> [<bos>, hello, world, !], [hello, world, !, <eos>]`

    Args:
        tgt: target sequence
        bos: begin-of-sequence index
        eos: end-of-sequence index

    Returns:
        - previous tokens
        - prediction target
    """
    if len(tgt[0]) > 0 and tgt[0][0] == bos and tgt[0][-1] == eos:
        prev_tokens = [v[:-1] for v in tgt]
        tgt = [v[1:] for v in tgt]
    else:
        prev_tokens = [[bos] + v for v in tgt]
        tgt = [v + [eos] for v in tgt]
    return tgt, prev_tokens