đ German NER in Flair (default model)
This project provides a standard 4 - class NER model for German, which is integrated with Flair. It effectively identifies named entities in German text, offering high - accuracy results.
⨠Features
- High Accuracy: Achieves an F1 - Score of 87.94 (CoNLL - 03 German revised).
- Four - Tag Prediction: Predicts four types of named entities:
| tag | meaning |
| ---- | ---- |
| PER | person name |
| LOC | location name |
| ORG | organization name |
| MISC | other name |
- Advanced Architecture: Based on Flair embeddings and LSTM - CRF.
đ Quick Start
Prerequisites
Requires Flair (pip install flair
).
Basic Usage
from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/ner-german")
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 code will yield the following output:
Span [1,2]: "George Washington" [â Labels: PER (0.9977)]
Span [5]: "Washington" [â Labels: LOC (0.9895)]
In the sentence "George Washington ging nach Washington", the entities "George Washington" (labeled as a person) and "Washington" (labeled as a location) are successfully identified.
đ§ Technical Details
Training Script
The following Flair script was used to train this model:
from flair.data import Corpus
from flair.datasets import CONLL_03_GERMAN
from flair.embeddings import WordEmbeddings, StackedEmbeddings, FlairEmbeddings
corpus: Corpus = CONLL_03_GERMAN()
tag_type = 'ner'
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
embedding_types = [
WordEmbeddings('de'),
FlairEmbeddings('de-forward'),
FlairEmbeddings('de-backward'),
]
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-german',
train_with_dev=True,
max_epochs=150)
đ License
No license information provided in the original document.
đ Documentation
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}
}
Issues?
The Flair issue tracker is available here.