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

Stop raising exception when get_entities takes a non-NE input #50

Merged
merged 2 commits into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions seqeval/metrics/sequence_labeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from __future__ import print_function

from collections import defaultdict
import warnings

import numpy as np

Expand All @@ -34,11 +35,11 @@ def _validate_chunk(chunk, suffix):

if suffix:
if not (chunk.endswith('-B') or chunk.endswith('-I') or chunk.endswith('-E') or chunk.endswith('-S')):
raise ValueError('Invalid tag is found: {}'.format(chunk))
warnings.warn('{} seems not to be NE tag.'.format(chunk))

else:
if not (chunk.startswith('B-') or chunk.startswith('I-') or chunk.startswith('E-') or chunk.startswith('S-')):
raise ValueError('Invalid tag is found: {}'.format(chunk))
warnings.warn('{} seems not to be NE tag.'.format(chunk))

# for nested list
if any(isinstance(s, list) for s in seq):
Expand Down
10 changes: 4 additions & 6 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ def test_get_entities_with_suffix_style(self):
y_true = ['O', 'O', 'O', 'MISC-B', 'MISC-I', 'MISC-I', 'O', 'PER-B', 'PER-I']
self.assertEqual(get_entities(y_true, suffix=True), [('MISC', 3, 5), ('PER', 7, 8)])

def test_get_entities_with_unexpected_input(self):
def test_get_entities_with_non_NE_input(self):
y_true = ['O', 'O', 'O', 'MISC', 'MISC', 'MISC', 'O', 'PER', 'PER']
with self.assertRaises(Exception):
with self.assertWarns(UserWarning):
get_entities(y_true)

def test_get_entities_with_unexpected_input_and_suffix_style(self):
y_true = ['O', 'O', 'O', 'MISC', 'MISC', 'MISC', 'O', 'PER', 'PER']
with self.assertRaises(Exception):
get_entities(y_true)
with self.assertWarns(UserWarning):
get_entities(y_true, suffix=True)

def test_get_entities_with_only_IOB(self):
y_true = [['O', 'O', 'O', 'B', 'I', 'I', 'O'], ['B', 'I', 'O']]
Expand Down