🚀 Flairによる英語のチャンキング (高速モデル)
これは、Flair とともに提供される英語の高速フレーズチャンキングモデルです。
F1スコア: 96,22 (CoNLL-2000)
4つのタグを予測します:
タグ |
意味 |
ADJP |
形容詞句 |
ADVP |
副詞句 |
CONJP |
接続詞句 |
INTJ |
感嘆詞 |
LST |
リストマーカー |
NP |
名詞句 |
PP |
前置詞句 |
PRT |
小品詞 |
SBAR |
従属節 |
VP |
動詞句 |
このモデルは Flair埋め込み とLSTM-CRFに基づいています。
🚀 クイックスタート
デモ: Flairでの使用方法
必要条件: Flair (pip install flair
)
from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/chunk-english-fast")
sentence = Sentence("The happy man has been eating at the diner")
tagger.predict(sentence)
print(sentence)
print('The following NER tags are found:')
for entity in sentence.get_spans('np'):
print(entity)
これにより、以下の出力が得られます:
Span [1,2,3]: "The happy man" [− Labels: NP (0.9958)]
Span [4,5,6]: "has been eating" [− Labels: VP (0.8759)]
Span [7]: "at" [− Labels: PP (1.0)]
Span [8,9]: "the diner" [− Labels: NP (0.9991)]
したがって、文 "The happy man has been eating at the diner" では、スパン "The happy man" と "the diner" は 名詞句 (NP) としてラベル付けされ、"has been eating" は 動詞句 (VP) としてラベル付けされます。
トレーニング: このモデルをトレーニングするスクリプト
このモデルのトレーニングには、以下のFlairスクリプトが使用されました:
from flair.data import Corpus
from flair.datasets import CONLL_2000
from flair.embeddings import WordEmbeddings, StackedEmbeddings, FlairEmbeddings
corpus: Corpus = CONLL_2000()
tag_type = 'np'
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
embedding_types = [
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/chunk-english-fast',
train_with_dev=True,
max_epochs=150)
📚 ドキュメント
引用
このモデルを使用する際には、以下の論文を引用してください。
@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}
}
問題がありますか?
Flairの問題追跡システムは こちら で利用できます。