基于camemBERT微调的NER模型(含DATE标签)——camembert-ner
简介
[camembert-ner-with-dates]是对原法语camembert-ner模型的扩展,新增了日期标签功能。该模型基于增强版wikiner-fr数据集训练(约170,634条语句)。
在测试数据(混合聊天记录和电子邮件)上,本模型的F1分数达到约83%(相比之下dateparser库约为70%)。仍可使用dateparser库将模型输出的日期文本转换为Python datetime对象(参见https://dateparser.readthedocs.io/en/latest/)。
使用指南
加载模型及子词分词器:
from transformers import AutoTokenizer, AutoModelForTokenClassification
tokenizer = AutoTokenizer.from_pretrained("Jean-Baptiste/camembert-ner-with-dates")
model = AutoModelForTokenClassification.from_pretrained("Jean-Baptiste/camembert-ner-with-dates")
from transformers import pipeline
nlp = pipeline('ner', model=model, tokenizer=tokenizer, aggregation_strategy="simple")
nlp("Apple est créée le 1er avril 1976 dans le garage de la maison d'enfance de Steve Jobs à Los Altos en Californie par Steve Jobs, Steve Wozniak et Ronald Wayne14, puis constituée sous forme de société le 3 janvier 1977 à l'origine sous le nom d'Apple Computer, mais pour ses 30 ans et pour refléter la diversification de ses produits, le mot « computer » est retiré le 9 janvier 2015.")
[{'entity_group': 'ORG',
'score': 0.9776379466056824,
'word': 'Apple',
'start': 0,
'end': 5},
{'entity_group': 'DATE',
'score': 0.9793774570737567,
'word': 'le 1er avril 1976 dans le',
'start': 15,
'end': 41},
{'entity_group': 'PER',
'score': 0.9958226680755615,
'word': 'Steve Jobs',
'start': 74,
'end': 85},
{'entity_group': 'LOC',
'score': 0.995087186495463,
'word': 'Los Altos',
'start': 87,
'end': 97},
{'entity_group': 'LOC',
'score': 0.9953305125236511,
'word': 'Californie',
'start': 100,
'end': 111},
{'entity_group': 'PER',
'score': 0.9961076378822327,
'word': 'Steve Jobs',
'start': 115,
'end': 126},
{'entity_group': 'PER',
'score': 0.9960325956344604,
'word': 'Steve Wozniak',
'start': 127,
'end': 141},
{'entity_group': 'PER',
'score': 0.9957776467005411,
'word': 'Ronald Wayne',
'start': 144,
'end': 157},
{'entity_group': 'DATE',
'score': 0.994030773639679,
'word': 'le 3 janvier 1977 à',
'start': 198,
'end': 218},
{'entity_group': 'ORG',
'score': 0.9720810294151306,
'word': "d'Apple Computer",
'start': 240,
'end': 257},
{'entity_group': 'DATE',
'score': 0.9924157659212748,
'word': '30 ans et',
'start': 272,
'end': 282},
{'entity_group': 'DATE',
'score': 0.9934852868318558,
'word': 'le 9 janvier 2015.',
'start': 363,
'end': 382}]
模型性能(评估指标:seqeval)
整体表现
'精确率': 0.928
'召回率': 0.928
'F1分数': 0.928
按实体分类
地点LOC: (精确率:0.929, 召回率:0.932, F1:0.931, 样本量:9510)
人名PER: (精确率:0.952, 召回率:0.965, F1:0.959, 样本量:9399)
其他MISC: (精确率:0.878, 召回率:0.844, F1:0.860, 样本量:5364)
组织ORG: (精确率:0.848, 召回率:0.883, F1:0.865, 样本量:2299)
日期DATE: 因wikiner数据集标注方法不适用评估(预估F1约90%)