🚀 Flair英文命名實體識別(大模型)
本項目是一個用於英文的大型4類別命名實體識別(NER)模型,它是 Flair 庫的一部分。該模型能有效識別英文文本中的命名實體,為信息提取等自然語言處理任務提供支持。
✨ 主要特性
- 高準確率:在修正後的CoNLL - 03數據集上,F1分數達到 94.36。
- 多標籤預測:可預測4種標籤,涵蓋人物、地點、組織和其他類型的命名實體。
- 先進技術:基於文檔級XLM - R嵌入和 FLERT 技術。
預測標籤詳情
標籤 |
含義 |
PER |
人名 |
LOC |
地名 |
ORG |
組織機構名 |
MISC |
其他名稱 |
🚀 快速開始
環境要求
需要安裝 Flair 庫,可以使用以下命令進行安裝:
pip install flair
代碼示例
from flair.data import Sentence
from flair.models import SequenceTagger
tagger = SequenceTagger.load("flair/ner-english-large")
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 (1.0)]
Span [5]: "Washington" [− Labels: LOC (1.0)]
在句子 "George Washington went to Washington" 中,成功識別出實體 "George Washington"(標記為 人物)和 "Washington"(標記為 地點)。
📚 詳細文檔
模型訓練腳本
以下是用於訓練此模型的Flair腳本:
import torch
from flair.datasets import CONLL_03
corpus = CONLL_03()
tag_type = 'ner'
tag_dictionary = corpus.make_tag_dictionary(tag_type=tag_type)
from flair.embeddings import TransformerWordEmbeddings
embeddings = TransformerWordEmbeddings(
model='xlm-roberta-large',
layers="-1",
subtoken_pooling="first",
fine_tune=True,
use_context=True,
)
from flair.models import SequenceTagger
tagger = SequenceTagger(
hidden_size=256,
embeddings=embeddings,
tag_dictionary=tag_dictionary,
tag_type='ner',
use_crf=False,
use_rnn=False,
reproject_embeddings=False,
)
from flair.trainers import ModelTrainer
trainer = ModelTrainer(tagger, corpus, optimizer=torch.optim.AdamW)
from torch.optim.lr_scheduler import OneCycleLR
trainer.train('resources/taggers/ner-english-large',
learning_rate=5.0e-6,
mini_batch_size=4,
mini_batch_chunk_size=1,
max_epochs=20,
scheduler=OneCycleLR,
embeddings_storage_mode='none',
weight_decay=0.,
)
📄 許可證
文檔中未提及許可證相關信息。
📖 引用
使用此模型時,請引用以下論文:
@misc{schweter2020flert,
title={FLERT: Document-Level Features for Named Entity Recognition},
author={Stefan Schweter and Alan Akbik},
year={2020},
eprint={2011.06993},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
❓ 問題反饋
如果你在使用過程中遇到問題,可以在 Flair問題跟蹤器 中反饋。