🚀 Flairによる英語のチャンキング (デフォルトモデル)
これは、Flair とともに提供される英語の標準的なフレーズチャンキングモデルです。
F1スコア: 96,48 (CoNLL - 2000)
4つのタグを予測します:
タグ |
意味 |
ADJP |
形容詞句 |
ADVP |
副詞句 |
CONJP |
接続詞句 |
INTJ |
感嘆詞 |
LST |
リストマーカー |
NP |
名詞句 |
PP |
前置詞句 |
PRT |
小品詞 |
SBAR |
従属節 |
VP |
動詞句 |
このモデルは Flair埋め込み とLSTM - CRFに基づいています。
🚀 クイックスタート
このモデルを使用するには、Flair が必要です。以下のコマンドでインストールできます。
pip install flair
💻 使用例
基本的な使用法
from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/chunk-english")
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'),
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/chunk-english',
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の問題追跡システムは こちら で利用できます。