bert-large-NER 是一款经过微调的 BERT 模型,可直接用于命名实体识别(Named Entity Recognition) 任务,并在该任务上实现了最先进(state-of-the-art)的性能。该模型经过训练,能够识别四种实体类型:地点(LOC)、组织(ORG)、人物(PER)和其他(MISC)。
具体而言,此模型基于 bert-large-cased 模型,在标准的英语版 CoNLL-2003 命名实体识别 数据集上进行了微调。
您可以将此模型与 Transformers 的 pipeline 配合使用,以进行命名实体识别。
from transformers import AutoModelForTokenClassification
from openmind import pipeline, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("Changchun_Ascend/bert-large-NER")
model = AutoModelForTokenClassification.from_pretrained("Changchun_Ascend/bert-large-NER")
nlp = pipeline("ner", model=model, tokenizer=tokenizer)
example = "My name is Wolfgang and I live in Berlin"
ner_results = nlp(example)
print(ner_results)[{'entity': 'B-PER', 'score': 0.9971501, 'index': 4, 'word': 'Wolfgang', 'start': 11, 'end': 19}, {'entity': 'B-LOC', 'score': 0.9986046, 'index': 9, 'word': 'Berlin', 'start': 34, 'end': 40}]本模型受限于其训练数据集,该数据集包含特定时间段内带有实体标注的新闻文章。因此,它在不同领域的所有使用场景中可能无法很好地泛化。此外,模型偶尔会将子词标记为实体,可能需要对结果进行后处理以应对这些情况。
本模型在标准的CoNLL-2003命名实体识别数据集的英文版本上进行了微调。
训练数据集对实体的起始和延续进行了区分,这样如果存在连续的相同类型实体,模型就能输出第二个实体的起始位置。与数据集中一致,每个标记将被分类为以下类别之一:
| 缩写 | 描述 |
|---|---|
| O | 非命名实体 |
| B-MIS | 紧接另一个 miscellaneous 实体之后的 miscellaneous 实体的起始 |
| I-MIS | Miscellaneous 实体 |
| B-PER | 紧接另一个人名之后的人名的起始 |
| I-PER | 人名 |
| B-ORG | 紧接另一个组织之后的组织的起始 |
| I-ORG | 组织 |
| B-LOC | 紧接另一个地点之后的地点的起始 |
| I-LOC | 地点 |
该数据集源自路透社语料库,包含路透社新闻报道。你可以在CoNLL-2003论文中了解更多关于该数据集的创建方式。
| 数据集 | LOC | MISC | ORG | PER |
|---|---|---|---|---|
| Train | 7140 | 3438 | 6321 | 6600 |
| Dev | 1837 | 922 | 1341 | 1842 |
| Test | 1668 | 702 | 1661 | 1617 |
| 数据集 | 文章数 | 句子数 | 标记数 |
|---|---|---|---|
| Train | 946 | 14,987 | 203,621 |
| Dev | 216 | 3,466 | 51,362 |
| Test | 231 | 3,684 | 46,435 |
本模型在单个NVIDIA V100 GPU上进行训练,采用了原始BERT论文中推荐的超参数,该论文在CoNLL-2003 NER任务上对模型进行了训练和评估。
| 指标 | 开发集 | 测试集 |
|---|---|---|
| f1 | 95.7 | 91.7 |
| 精确率 | 95.3 | 91.2 |
| 召回率 | 96.1 | 92.3 |
测试集指标略低于 Google BERT 官方结果,后者对文档上下文进行了编码并尝试使用了 CRF。关于复现原始结果的更多信息,请参见此处。
@article{DBLP:journals/corr/abs-1810-04805,
author = {Jacob Devlin and
Ming{-}Wei Chang and
Kenton Lee and
Kristina Toutanova},
title = {{BERT:} Pre-training of Deep Bidirectional Transformers for Language
Understanding},
journal = {CoRR},
volume = {abs/1810.04805},
year = {2018},
url = {http://arxiv.org/abs/1810.04805},
archivePrefix = {arXiv},
eprint = {1810.04805},
timestamp = {Tue, 30 Oct 2018 20:39:56 +0100},
biburl = {https://dblp.org/rec/journals/corr/abs-1810-04805.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}@inproceedings{tjong-kim-sang-de-meulder-2003-introduction,
title = "Introduction to the {C}o{NLL}-2003 Shared Task: Language-Independent Named Entity Recognition",
author = "Tjong Kim Sang, Erik F. and
De Meulder, Fien",
booktitle = "Proceedings of the Seventh Conference on Natural Language Learning at {HLT}-{NAACL} 2003",
year = "2003",
url = "https://www.aclweb.org/anthology/W03-0419",
pages = "142--147",
}