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

Minor change is label dictionary creation #2453

Merged
merged 1 commit into from
Sep 28, 2021
Merged
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
16 changes: 8 additions & 8 deletions flair/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1406,6 +1406,14 @@ def make_label_dictionary(self, label_type: str) -> Dictionary:

for sentence in batch:

# check for labels of words
if isinstance(sentence, Sentence):
for token in sentence.tokens:
all_label_types.update(token.annotation_layers.keys())
for label in token.get_labels(label_type):
label_dictionary.add_item(label.value)
token_labels_exist = True

# if we are looking for sentence-level labels
if not token_labels_exist:
# check if sentence itself has labels
Expand All @@ -1419,14 +1427,6 @@ def make_label_dictionary(self, label_type: str) -> Dictionary:
if len(labels) > 1:
label_dictionary.multi_label = True

# check for labels of words
if isinstance(sentence, Sentence):
for token in sentence.tokens:
all_label_types.update(token.annotation_layers.keys())
for label in token.get_labels(label_type):
label_dictionary.add_item(label.value)
token_labels_exist = True

# if this is not a token-level prediction problem, add sentence-level labels to dictionary
if not token_labels_exist:
for label in all_sentence_labels:
Expand Down