def output_to_IOB2_string(output):
    """
    Convert Stanford NER tags to IOB2 tags.
    """
    iob2_tags = []
    names = []
    previous_tag = 'O'
    for _, tup in enumerate(output):
        name, tag = tup
        if tag != 'O':
            tag = 'E'

        if tag == 'O':
            iob2_tags.append(tag)
            previous_tag = tag
            names.append(name)
        else:
            if previous_tag == 'O':
                iob2_tags.append('B-' + tag)
            else:
                iob2_tags.append('I-' + tag)
            previous_tag = tag
            names.append(name)
    return names, iob2_tags