Skip to content

Commit

Permalink
Merge pull request #47 from chakki-works/fix/#46
Browse files Browse the repository at this point in the history
Update validation to fix #46
  • Loading branch information
Hironsan authored Sep 30, 2020
2 parents 679a7c5 + d13bfb4 commit ca1ad9f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions seqeval/metrics/sequence_labeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ def get_entities(seq, suffix=False):
"""

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

if suffix:
if not (chunk.endswith('-B') or chunk.endswith('-I')):
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))

else:
if not (chunk.startswith('B-') or chunk.startswith('I-')):
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))

# for nested list
Expand Down
5 changes: 5 additions & 0 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def test_get_entities_with_unexpected_input_and_suffix_style(self):
with self.assertRaises(Exception):
get_entities(y_true)

def test_get_entities_with_only_IOB(self):
y_true = [['O', 'O', 'O', 'B', 'I', 'I', 'O'], ['B', 'I', 'O']]
entities = get_entities(y_true)
self.assertEqual(entities, [('_', 3, 5), ('_', 8, 9)])

def test_performance_measure(self):
y_true = [['O', 'O', 'O', 'B-MISC', 'I-MISC', 'O', 'B-ORG'], ['B-PER', 'I-PER', 'O', 'B-PER']]
y_pred = [['O', 'O', 'B-MISC', 'I-MISC', 'I-MISC', 'O', 'O'], ['B-PER', 'I-PER', 'O', 'B-MISC']]
Expand Down

0 comments on commit ca1ad9f

Please sign in to comment.