Exemplo n.º 1
0
# print the sentence with all tags of this type
print(sentence.to_tagged_string())

###

from flair.data import Label

tag: Label = sentence[3].get_tag('ner')

print(
    f'"{sentence[3]}" is tagged as "{tag.value}" with confidence score "{tag.score}"'
)

###

sentence = Sentence('France is the current world cup winner.')

# add a label to a sentence
sentence.add_label('sports')

# a sentence can also belong to multiple classes
sentence.add_labels(['sports', 'world cup'])

# you can also set the labels while initializing the sentence
sentence = Sentence('France is the current world cup winner.',
                    labels=['sports', 'world cup'])

print(sentence)
for label in sentence.labels:
    print(label)