(sequence, mapping, begin_tag='B', inside_tag='I')
return set(segments)
Convert an IOB tag sequence to segments (O tags are excluded). Used
    by iob_metrics_fn
    Parameters:
        sequence: List of tag ids
        mapping: Maps ids to tags (B/I prefix + O etc.)
        begin_tag: Label for begin tag (default 'B')
        inside_tag: Label for inside tag (default 'I')

    Returns:
        A set of segment tuples of the form 
        (segment value, segment start index, segment end index)
Convert an IOB tag sequence to segments (O tags are excluded). Used
    by iob_metrics_fn
    Parameters:
        sequence: List of tag ids
        mapping: Maps ids to tags (B/I prefix + O etc.)
        begin_tag: Label for begin tag (default 'B')
        inside_tag: Label for inside tag (default 'I')
Convert an IOB tag sequence to segments ( O tags are excluded ) . Used by iob_metrics_fn Parameters : sequence : List of tag ids mapping : Maps ids to tags ( B / I prefix + O etc . ) begin_tag : Label for begin tag ( default B ) inside_tag : Label for inside tag ( default I )
def convert_iob_to_segments(sequence, mapping, begin_tag='B', inside_tag='I'):
    """
    Convert an IOB tag sequence to segments (O tags are excluded). Used
    by iob_metrics_fn
    Parameters:
        sequence: List of tag ids
        mapping: Maps ids to tags (B/I prefix + O etc.)
        begin_tag: Label for begin tag (default 'B')
        inside_tag: Label for inside tag (default 'I')

    Returns:
        A set of segment tuples of the form 
        (segment value, segment start index, segment end index)
    """
    segments = []
    segment, segment_start, segment_end = None, None, None
    relevant_tags = set([begin_tag, inside_tag])

    for i, tok in enumerate(map(lambda s: mapping[s].split('-', 1), sequence)):
        if tok[0] in relevant_tags:
            if segment is None:
                segment, segment_start = tok[1], i
            elif tok[0] == begin_tag or tok[1] != segment:
                segments.append((segment, segment_start, segment_end))
                segment, segment_start = tok[1], i
            segment_end = i

    if segment is not None:
        segments.append((segment, segment_start, segment_end))

    return set(segments)
def convert_iob_to_segments ( sequence , mapping , begin_tag = 'B' , inside_tag = 'I' ) : segments = [ ] segment , segment_start , segment_end = None , None , None relevant_tags = set ( [ begin_tag , inside_tag ] ) for i , tok in enumerate ( map ( lambda s : mapping [ s ] . split ( '-' , 1 ) , sequence ) ) : if tok [ 0 ] in relevant_tags : if segment is None : segment , segment_start = tok [ 1 ] , i elif tok [ 0 ] == begin_tag or tok [ 1 ] != segment : segments . append ( ( segment , segment_start , segment_end ) ) segment , segment_start = tok [ 1 ] , i segment_end = i if segment is not None : segments . append ( ( segment , segment_start , segment_end ) ) return set ( segments )