def is_valid_iob(tags, version='IOB2'):
    """Judge whether `tags' is a valid IOB string.

    Parameters
    ----------
    tags: list
        List of tags.

    version: str
        The IOB version of the tags, should be one of ["IOB1", "IOB2"].

    Returns
    -------
    is_valid: boolean
        True if `tags' is in valid IOB format, otherwise False.

    """
    for i, tag in enumerate(tags):
        if tag == 'O':
            continue
        fields = tag.split('-')
        if len(fields) != 2 or fields[0] not in ['B', 'I']:
            return False
        pos, tag_name = fields
        if i == 0 or tags[i - 1].split('-') not in [['I', tag_name], ['B',
            tag_name]]:
            if version == 'IOB1' and pos == 'B':
                return False
            if version == 'IOB2' and pos == 'I':
                return False
    return True
