đ English Universal Part-of-Speech Tagging in Flair (default model)
This is a standard universal part-of-speech tagging model for English provided by Flair, which can accurately predict universal POS tags.
đ Quick Start
This is the standard universal part-of-speech tagging model for English that ships with Flair.
F1-Score: 98,6 (Ontonotes)
Predicts 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 |
Based on Flair embeddings and LSTM-CRF.
đģ Usage Examples
Basic Usage
Requires: Flair (pip install flair
)
from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/upos-english")
sentence = Sentence("I love Berlin.")
tagger.predict(sentence)
print(sentence)
print('The following NER tags are found:')
for entity in sentence.get_spans('pos'):
print(entity)
This yields the following output:
Span [1]: "I" [â Labels: PRON (0.9996)]
Span [2]: "love" [â Labels: VERB (1.0)]
Span [3]: "Berlin" [â Labels: PROPN (0.9986)]
Span [4]: "." [â Labels: PUNCT (1.0)]
So, the word "I" is labeled as a pronoun (PRON), "love" is labeled as a verb (VERB) and "Berlin" is labeled as a proper noun (PROPN) in the sentence "I love Berlin".
đ§ Technical Details
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 ColumnCorpus
from flair.embeddings import WordEmbeddings, StackedEmbeddings, FlairEmbeddings
corpus: Corpus = ColumnCorpus(
"resources/tasks/onto-ner",
column_format={0: "text", 1: "pos", 2: "upos", 3: "ner"},
tag_to_bioes="ner",
)
tag_type = 'upos'
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
embedding_types = [
FlairEmbeddings('news-forward'),
FlairEmbeddings('news-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/upos-english',
train_with_dev=True,
max_epochs=150)
đ License
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.