🚀 Flairによる英語の固有表現抽出 (高速モデル)
これは、Flair とともに提供される英語用の高速な4クラス固有表現抽出(NER)モデルです。
F1スコア: 92,92 (修正済みCoNLL - 03)
以下の4つのタグを予測します:
タグ |
意味 |
PER |
人名 |
LOC |
地名 |
ORG |
組織名 |
MISC |
その他の名前 |
このモデルは Flair埋め込み とLSTM - CRFに基づいています。
🚀 クイックスタート
デモ: Flairでの使用方法
必要条件: Flair (pip install flair
)
from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/ner-english-fast")
sentence = Sentence("George Washington went to Washington")
tagger.predict(sentence)
print(sentence)
print('The following NER tags are found:')
for entity in sentence.get_spans('ner'):
print(entity)
これにより、以下の出力が得られます:
Span [1,2]: "George Washington" [− Labels: PER (0.9515)]
Span [5]: "Washington" [− Labels: LOC (0.992)]
したがって、文 "George Washington went to Washington" から、エンティティ "George Washington"(人物とラベル付け)と "Washington"(場所とラベル付け)が検出されます。
📚 ドキュメント
トレーニング: このモデルをトレーニングするスクリプト
このモデルのトレーニングには、以下のFlairスクリプトが使用されました:
from flair.data import Corpus
from flair.datasets import CONLL_03
from flair.embeddings import WordEmbeddings, StackedEmbeddings, FlairEmbeddings
corpus: Corpus = CONLL_03()
tag_type = 'ner'
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
embedding_types = [
WordEmbeddings('glove'),
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/ner-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の問題追跡システムは こちら で利用できます。