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

Fix error in 'ensure_consistent_bilou_tagging' #5825

Merged
merged 3 commits into from
May 15, 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
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-."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tabergma in what type of situations does this actually happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRFEntityExtractor or DIETClassifier may predict inconsistent BILOU tags.

)
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