🚀 Flairによるフランス語の固有表現抽出 (デフォルトモデル)
これは、Flairに付属する標準的な4クラスのフランス語固有表現抽出(NER)モデルです。
F1スコア: 90,61 (WikiNER)
以下の4つのタグを予測します:
タグ |
意味 |
PER |
人名 |
LOC |
地名 |
ORG |
組織名 |
MISC |
その他の名前 |
このモデルは、Flair埋め込みとLSTM-CRFに基づいています。
🚀 クイックスタート
必要条件
Flair (pip install flair
)
コード例
from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/ner-french")
sentence = Sentence("George Washington est allé à 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.7394)]
Span [6]: "Washington" [− Labels: LOC (0.9161)]
したがって、文 "George Washington est allé à Washington" から、エンティティ "George Washington"(人物とラベル付けされています)と "Washington"(場所とラベル付けされています)が検出されます。
💻 使用例
基本的な使用法
from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/ner-french")
sentence = Sentence("George Washington est allé à Washington")
tagger.predict(sentence)
print(sentence)
print('The following NER tags are found:')
for entity in sentence.get_spans('ner'):
print(entity)
🔧 技術詳細
このモデルは、以下のFlairスクリプトを使用して学習されました:
from flair.data import Corpus
from flair.datasets import WIKINER_FRENCH
from flair.embeddings import WordEmbeddings, StackedEmbeddings, FlairEmbeddings
corpus: Corpus = WIKINER_FRENCH()
tag_type = 'ner'
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
embedding_types = [
WordEmbeddings('fr'),
FlairEmbeddings('fr-forward'),
FlairEmbeddings('fr-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/ner-french',
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の問題追跡ページはこちらです。