đ 4-Language NER in Flair (English, German, Dutch and Spanish)
This project presents a fast 4-class NER model for 4 CoNLL-03 languages integrated with Flair. It also shows effectiveness for related languages such as French.
⨠Features
- Multi - language Support: Covers English, German, Dutch, and Spanish, with potential application in related languages.
- High Performance: Achieves remarkable F1 - Scores: 91.51 (CoNLL - 03 English), 85.72 (CoNLL - 03 German revised), 86.22 (CoNLL - 03 Dutch), 85.78 (CoNLL - 03 Spanish).
- Four - Tag Prediction: Predicts 4 tags including PER (person name), LOC (location name), ORG (organization name), and MISC (other name).
- Powered by Flair: 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-multi-fast")
sentence = Sentence("George Washington ging nach 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.9977)]
Span [5]: "Washington" [â Labels: LOC (0.9895)]
So, the entities "George Washington" (labeled as a person) and "Washington" (labeled as a location) are found in the sentence "George Washington ging nach Washington".
đ§ Technical Details
- Predicted Tags
| Property | Details |
|----------|---------|
| PER | person name |
| LOC | location name |
| ORG | organization name |
| MISC | other name |
- Underlying Technology: Based on Flair embeddings and LSTM - CRF.
đ Documentation
Training Script
The following Flair script was used to train this model:
from flair.data import Corpus
from flair.datasets import CONLL_03, CONLL_03_GERMAN, CONLL_03_DUTCH, CONLL_03_SPANISH
from flair.embeddings import WordEmbeddings, StackedEmbeddings, FlairEmbeddings
corpus: Corpus = MultiCorpus([
CONLL_03(),
CONLL_03_GERMAN(),
CONLL_03_DUTCH(),
CONLL_03_SPANISH(),
])
tag_type = 'ner'
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
embedding_types = [
WordEmbeddings('glove'),
WordEmbeddings('de'),
FlairEmbeddings('multi-forward-fast'),
FlairEmbeddings('multi-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-multi-fast',
train_with_dev=True,
max_epochs=150)
đ License
Please cite the following papers when using this model.
@misc{akbik2019multilingual,
title={Multilingual sequence labeling with one model},
author={Akbik, Alan and Bergmann, Tanja and Vollgraf, Roland}
booktitle = {{NLDL} 2019, Northern Lights Deep Learning Workshop},
year = {2019}
}
@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}
}