Skip to content

Commit

Permalink
Merge pull request #5825 from RasaHQ/fix-ensure-consistent-bilou-tagging
Browse files Browse the repository at this point in the history
Fix error in 'ensure_consistent_bilou_tagging'
  • Loading branch information
tabergma authored May 15, 2020
2 parents 56b15b0 + 760f0d5 commit ec4a2b1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/5825.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix list index out of range error in ``ensure_consistent_bilou_tagging``.
9 changes: 9 additions & 0 deletions rasa/nlu/utils/bilou_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@ def _find_bilou_end(start_idx: int, predicted_tags: List[Text]) -> int:
start_tag = tag_without_prefix(predicted_tags[start_idx])

while not finished:
if current_idx >= len(predicted_tags):
logger.debug(
"Inconsistent BILOU tagging found, B- tag not closed by L- tag, "
"i.e [B-a, I-a, O] instead of [B-a, L-a, O].\n"
"Assuming last tag is L- instead of I-."
)
current_idx -= 1
break

current_label = predicted_tags[current_idx]
prefix = bilou_prefix_from_tag(current_label)
tag = tag_without_prefix(current_label)
Expand Down
16 changes: 16 additions & 0 deletions tests/nlu/utils/test_bilou_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@ def test_apply_bilou_schema():
"B- tag, L- tag pair encloses multiple entity classes",
),
(["O", "B-person", "O"], ["O", "U-person", "O"], "B- tag not closed"),
(["O", "B-person"], ["O", "U-person"], "B- tag not closed"),
(
["O", "B-person", "I-person"],
["O", "B-person", "L-person"],
"B- tag not closed",
),
(
["O", "B-person", "I-location"],
["O", "B-person", "L-person"],
"B- tag not closed",
),
(
["O", "B-person", "B-location"],
["O", "U-person", "U-location"],
"B- tag not closed",
),
],
)
def test_check_consistent_bilou_tagging(
Expand Down

0 comments on commit ec4a2b1

Please sign in to comment.