🚀 荷蘭語命名實體識別(Flair默認模型)
這是 Flair 庫中用於荷蘭語的標準4類命名實體識別(NER)模型。該模型在CoNLL - 03數據集上的F1分數達到了 92.58。它可以預測4種標籤,具體如下:
標籤 |
含義 |
PER |
人名 |
LOC |
地名 |
ORG |
組織名 |
MISC |
其他名稱 |
該模型基於Transformer嵌入和LSTM - CRF構建。
🚀 快速開始
依賴安裝
本模型需要安裝 Flair 庫,可以使用以下命令進行安裝:
pip install flair
代碼示例
from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/ner-dutch")
sentence = Sentence("George Washington ging naar 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.997)]
Span [5]: "Washington" [− Labels: LOC (0.9996)]
這表明在句子 "George Washington ging naar Washington" 中,識別出了實體 "George Washington"(標籤為 人名)和 "Washington"(標籤為 地名)。
💻 使用示例
基礎用法
上述代碼展示瞭如何在Flair中使用該模型進行荷蘭語命名實體識別,主要步驟包括加載模型、創建句子、進行預測和輸出結果。
高級用法
以下是訓練該模型的腳本示例:
from flair.data import Corpus
from flair.datasets import CONLL_03_DUTCH
from flair.embeddings import WordEmbeddings, StackedEmbeddings, FlairEmbeddings
corpus: Corpus = CONLL_03_DUTCH()
tag_type = 'ner'
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
embeddings = TransformerWordEmbeddings('wietsedv/bert-base-dutch-cased')
tagger: SequenceTagger = SequenceTagger(hidden_size=256,
embeddings=embeddings,
tag_dictionary=tag_dictionary,
tag_type=tag_type)
trainer: ModelTrainer = ModelTrainer(tagger, corpus)
trainer.train('resources/taggers/ner-dutch',
train_with_dev=True,
max_epochs=150)
📄 引用說明
使用此模型時,請引用以下論文:
@inproceedings{akbik-etal-2019-flair,
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 = "Proceedings of the 2019 Conference of the North {A}merican Chapter of the Association for Computational Linguistics (Demonstrations)",
year = "2019",
url = "https://www.aclweb.org/anthology/N19-4010",
pages = "54--59",
}
🔗 問題反饋
如果你在使用過程中遇到問題,可以在 Flair問題跟蹤器 中反饋。