def is_valid_iobes(tags):
    """Judge whether `tags' is a valid IOBES string.

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

    Returns
    -------
    is_valid: boolean
        True if `tags' is in valid IOBES 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', 'E', 'S']:
            return False
        pos, tag_name = fields
        if pos in ['B', 'I'] and (i + 1 == len(tags) or tags[i + 1].split(
            '-') not in [['I', tag_name], ['E', tag_name]]):
            return False
        if pos in ['I', 'E'] and (i == 0 or tags[i - 1].split('-') not in [
            ['B', tag_name], ['I', tag_name]]):
            return False
    return True
