1from flair.data import Sentence
2from flair.models import SequenceTagger
34# load tagger5tagger = SequenceTagger.load("acuvity/flair_ner-fast")67# make example sentence8sentence = Sentence("George Washington went to Washington")910# predict NER tags11tagger.predict(sentence)1213# print sentence14print(sentence)1516# print predicted NER spans17print('The following NER tags are found:')18# iterate over entities and print19for entity in sentence.get_spans('ner'):20print(entity)21
This yields the following output:
Span [1,2]: "George Washington" [− Labels: PER (1.0)]
Span [5]: "Washington" [− Labels: LOC (1.0)]
So, the entities "George Washington" (labeled as a person) and "Washington" (labeled as a location) are found in the sentence "George Washington went to Washington".