🚀 Multilingual Universal Part-of-Speech Tagging in Flair (fast model)
This is a fast multilingual universal part-of-speech tagging model provided by Flair. It can effectively handle part-of-speech tagging tasks across multiple languages.
Key Information
- Supported Languages: English, German, French, Italian, Dutch, Polish, Spanish, Swedish, Danish, Norwegian, Finnish and Czech.
- F1-Score: 92.88 (evaluated on 12 UD Treebanks covering the above languages)
- Based on: Flair embeddings and LSTM-CRF
✨ Features
- Multilingual Support: Capable of tagging multiple languages, making it highly versatile.
- Fast Performance: Optimized for speed, suitable for real - time applications.
- High Accuracy: Achieves an F1 - Score of 92.88 on relevant datasets.
Predicted Universal POS Tags
tag |
meaning |
ADJ |
adjective |
ADP |
adposition |
ADV |
adverb |
AUX |
auxiliary |
CCONJ |
coordinating conjunction |
DET |
determiner |
INTJ |
interjection |
NOUN |
noun |
NUM |
numeral |
PART |
particle |
PRON |
pronoun |
PROPN |
proper noun |
PUNCT |
punctuation |
SCONJ |
subordinating conjunction |
SYM |
symbol |
VERB |
verb |
X |
other |
📦 Installation
Requires: Flair (pip install flair
)
💻 Usage Examples
Basic Usage
from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/upos-multi-fast")
sentence = Sentence("Ich liebe Berlin, as they say. ")
tagger.predict(sentence)
print(sentence)
print('The following NER tags are found:')
for entity in sentence.get_spans('pos'):
print(entity)
The above code demonstrates how to use the model to perform part - of - speech tagging on a given sentence.
Training Script
The following script shows how to train the model:
from flair.data import MultiCorpus
from flair.datasets import UD_ENGLISH, UD_GERMAN, UD_FRENCH, UD_ITALIAN, UD_POLISH, UD_DUTCH, UD_CZECH, \
UD_DANISH, UD_SPANISH, UD_SWEDISH, UD_NORWEGIAN, UD_FINNISH
from flair.embeddings import StackedEmbeddings, FlairEmbeddings
corpus = MultiCorpus([
UD_ENGLISH(in_memory=False),
UD_GERMAN(in_memory=False),
UD_DUTCH(in_memory=False),
UD_FRENCH(in_memory=False),
UD_ITALIAN(in_memory=False),
UD_SPANISH(in_memory=False),
UD_POLISH(in_memory=False),
UD_CZECH(in_memory=False),
UD_DANISH(in_memory=False),
UD_SWEDISH(in_memory=False),
UD_NORWEGIAN(in_memory=False),
UD_FINNISH(in_memory=False),
])
tag_type = 'upos'
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
embedding_types = [
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,
use_crf=False)
from flair.trainers import ModelTrainer
trainer = ModelTrainer(tagger, corpus)
trainer.train('resources/taggers/upos-multi-fast',
train_with_dev=True,
max_epochs=150)
📚 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.