đ English Verb Disambiguation in Flair (fast model)
This is a fast verb disambiguation model for English that comes with Flair, which can effectively predict Proposition Bank verb frames.
This is the fast verb disambiguation model for English that ships with Flair.
F1-Score: 88,27 (Ontonotes) - predicts Proposition Bank verb frames.
Based on Flair embeddings and LSTM-CRF.
đ Quick Start
Prerequisites
Requires: Flair (pip install flair
)
Usage Example
from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/frame-english-fast")
sentence = Sentence("George returned to Berlin to return his hat.")
tagger.predict(sentence)
print(sentence)
print('The following frame tags are found:')
for entity in sentence.get_spans('frame'):
print(entity)
This yields the following output:
Span [2]: "returned" [â Labels: return.01 (0.9867)]
Span [6]: "return" [â Labels: return.02 (0.4741)]
So, the word "returned" is labeled as return.01 (as in go back somewhere) while "return" is labeled as return.02 (as in give back something) in the sentence "George returned to Berlin to return his hat".
đĻ Installation
To use this model, you need to install the Flair
library. You can install it via the following command:
pip install flair
đģ Usage Examples
Basic Usage
The above code example demonstrates the basic usage of this model. You can load the model and perform verb disambiguation on a given sentence.
đ§ Technical Details
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 = ColumnCorpus(
"resources/tasks/srl", column_format={1: "text", 11: "frame"}
)
tag_type = 'frame'
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
embedding_types = [
BytePairEmbeddings("en"),
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/frame-english-fast',
train_with_dev=True,
max_epochs=150)
đ License
Please cite the following paper when using this model.
@inproceedings{akbik2019flair,
title={FLAIR: An easy-to-use framework for state-of-the-art NLP},
author={Akbik, Alan and Bergmann, Tanja and Blythe, Duncan and Rasul, Kashif and Schweter, Stefan and Vollgraf, Roland},
booktitle={{NAACL} 2019, 2019 Conference of the North American Chapter of the Association for Computational Linguistics (Demonstrations)},
pages={54--59},
year={2019}
}
â Issues
The Flair issue tracker is available here.