def decompose_tokenized_text(token_list):
    """
    Split the output of BERT tokenizer into word_list and tag_list
    """

    # The initial tag is 'O'
    tag = 'O'
    word_list = []
    tag_list = []

    # A flag to indicate if it is in the entity now
    # 0 means out, 1 means start, 2 means in the middle
    in_ent = 0

    for token in token_list:

        if token == '':
            continue

        # if the token ends with '-START]'
        # change the ent flag
        # if token[-len('-START]'):] == '-START]':
        if token.endswith('-START]'):
            tag = token[1:-1].rsplit('-', 1)[0]
            in_ent = 1
        # elif token[-len('-END]'):] == '-END]':
        elif token.endswith('-END]'):
            tag = 'O'
            in_ent = 0
        else:
            word_list.append(token)

            if in_ent == 1:
                tag_list.append('B-' + tag)
                in_ent = 2
            elif in_ent == 2:
                tag_list.append('I-' + tag)
            else:
                tag_list.append(tag)

    return word_list, tag_list