Skip to content

Commit

Permalink
Merge pull request #3231 from flairNLP/label-verbalizer-non-bioes
Browse files Browse the repository at this point in the history
Adapt LabelVerbalizer so that it also works for non-BIOES span labes
  • Loading branch information
alanakbik committed Aug 11, 2023
2 parents 9ea0894 + 7f3b0f1 commit fd1ea0f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions flair/nn/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def verbalize_labels(label_dictionary: Dictionary) -> List[Sentence]:
for byte_label, idx in label_dictionary.item2idx.items():
str_label = byte_label.decode("utf-8")
if label_dictionary.span_labels:
# verbalize BIOES labels
if str_label == "O":
verbalized_labels.append("outside")
elif str_label.startswith("B-"):
Expand All @@ -184,6 +185,9 @@ def verbalize_labels(label_dictionary: Dictionary) -> List[Sentence]:
verbalized_labels.append("ending " + str_label.split("-")[1])
elif str_label.startswith("S-"):
verbalized_labels.append("single " + str_label.split("-")[1])
# if label is not BIOES, use label itself
else:
verbalized_labels.append(str_label)
else:
verbalized_labels.append(str_label)
return list(map(Sentence, verbalized_labels))
Expand Down

0 comments on commit fd1ea0f

Please sign in to comment.