Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sequence_labeling.py #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions seqeval/metrics/sequence_labeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,15 @@ def get_entities(seq, suffix=False):
"""

def _validate_chunk(chunk, suffix):
if chunk in ['O', 'B', 'I', 'E', 'S']:
if chunk in ['O', 'B', 'I', 'E', 'S', 'M']:
return

if suffix:
if not chunk.endswith(('-B', '-I', '-E', '-S')):
if not chunk.endswith(('-B', '-I', '-E', '-S', '-M')):
warnings.warn('{} seems not to be NE tag.'.format(chunk))

else:
if not chunk.startswith(('B-', 'I-', 'E-', 'S-')):
if not chunk.startswith(('B-', 'I-', 'E-', 'S-', 'M')):
warnings.warn('{} seems not to be NE tag.'.format(chunk))

# for nested list
Expand Down Expand Up @@ -229,6 +229,12 @@ def end_of_chunk(prev_tag, tag, prev_type, type_):
chunk_end = True
if prev_tag == 'I' and tag == 'O':
chunk_end = True
if prev_tag == 'M' and tag == 'B':
chunk_end = True
if prev_tag == 'M' and tag == 'S':
chunk_end = True
if prev_tag == 'M' and tag == 'O':
chunk_end = True

if prev_tag != 'O' and prev_tag != '.' and prev_type != type_:
chunk_end = True
Expand Down Expand Up @@ -267,6 +273,10 @@ def start_of_chunk(prev_tag, tag, prev_type, type_):
chunk_start = True
if prev_tag == 'O' and tag == 'I':
chunk_start = True
if prev_tag == 'M' and tag == 'E':
chunk_start = True
if prev_tag == 'M' and tag == 'I':
chunk_start = True

if tag != 'O' and tag != '.' and prev_type != type_:
chunk_start = True
Expand Down