Named entity recognition in Flair
NER is a special sequence tagging task that identifies and labels named entities. Named entities are real-word objects such as persons, locations, or organizations. The set of possible distinct named entities isn't strictly defined and may vary from model to model. Flair ships with a rich set of pretrained NER models, as well as tools to train custom models. In this section, we are going to focus on covering the pretrained models, as well as how to interpret and understand their output.
To get a good understanding of how NER tagging works in Flair, let's try it out as part of an exercise. We will start with tagging a single word that is clearly a named entity.
from flair.data import Sentence from flair.models import SequenceTagger tagger = SequenceTagger.load('ner') sentence = Sentence('Berlin') tagger.predict(sentence) print(sentence.to_tagged_string())
In the preceding script, we loaded Flair's default...