đ English NER in Flair (fast model)
This is a fast 4 - class NER model for English provided by Flair. It solves the problem of named - entity recognition in English texts, offering high - accuracy tagging with an F1 - Score of 92,92 (corrected CoNLL - 03).
⨠Features
- Predicts 4 tags:
| Property | Details |
|----------|---------|
| PER | person name |
| LOC | location name |
| ORG | organization name |
| MISC | other name |
- Based on Flair embeddings and LSTM - CRF.
đĻ Installation
Requires: Flair (pip install flair
)
đģ Usage Examples
Basic Usage
from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/ner-english-fast")
sentence = Sentence("George Washington went to Washington")
tagger.predict(sentence)
print(sentence)
print('The following NER tags are found:')
for entity in sentence.get_spans('ner'):
print(entity)
This yields the following output:
Span [1,2]: "George Washington" [â Labels: PER (0.9515)]
Span [5]: "Washington" [â Labels: LOC (0.992)]
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".
đ Documentation
Training: Script to train this model
The following Flair script was used to train this model:
from flair.data import Corpus
from flair.datasets import CONLL_03
from flair.embeddings import WordEmbeddings, StackedEmbeddings, FlairEmbeddings
corpus: Corpus = CONLL_03()
tag_type = 'ner'
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
embedding_types = [
WordEmbeddings('glove'),
FlairEmbeddings('news-forward-fast'),
FlairEmbeddings('news-backward-fast'),
]
embeddings = StackedEmbeddings(embeddings=embedding_types)
from flair.models import SequenceTagger
tagger = SequenceTagger(hidden_size=256,
embeddings=embeddings,
tag_dictionary=tag_dictionary,
tag_type=tag_type)
from flair.trainers import ModelTrainer
trainer = ModelTrainer(tagger, corpus)
trainer.train('resources/taggers/ner-english',
train_with_dev=True,
max_epochs=150)
đ License
No license information provided in the original document.
đ Cite
Please cite the following paper when using this model.
@inproceedings{akbik2018coling,
title={Contextual String Embeddings for Sequence Labeling},
author={Akbik, Alan and Blythe, Duncan and Vollgraf, Roland},
booktitle = {{COLING} 2018, 27th International Conference on Computational Linguistics},
pages = {1638--1649},
year = {2018}
}
đĄ Usage Tip
The Flair issue tracker is available here.