DistilCamemBERT-NER
我们推出DistilCamemBERT-NER,这是基于DistilCamemBERT微调的法语命名实体识别(NER)模型。该工作灵感来源于基于CamemBERT的Jean-Baptiste/camembert-ner模型。基于CamemBERT的模型在规模化应用(如生产阶段)时存在推理成本问题。为解决这一问题,我们提出该模型方案,借助DistilCamemBERT在相同算力下将推理时间缩短一半。
数据集
使用数据集为wikiner_fr,包含约17万句标注文本,分为5类:
- PER:人物
- LOC:地点
- ORG:组织机构
- MISC:其他实体(电影名、书籍等)
- O:非实体背景
评估结果
类别 |
精确率(%) |
召回率(%) |
F1值(%) |
支持数(子词) |
总体 |
98.17 |
98.19 |
98.18 |
378,776 |
PER |
96.78 |
96.87 |
96.82 |
23,754 |
LOC |
94.05 |
93.59 |
93.82 |
27,196 |
ORG |
86.05 |
85.92 |
85.98 |
6,526 |
MISC |
88.78 |
84.69 |
86.69 |
11,891 |
O |
99.26 |
99.47 |
99.37 |
309,409 |
基准测试
本模型性能与两个参考模型通过F1分数对比(如下表)。平均推理时间测试使用AMD Ryzen 5 4500U @ 2.3GHz六核处理器:
使用方法
from transformers import pipeline
ner = pipeline(
task='ner',
model="cmarkea/distilcamembert-base-ner",
tokenizer="cmarkea/distilcamembert-base-ner",
aggregation_strategy="simple"
)
result = ner(
"Le Crédit Mutuel Arkéa est une banque Française, elle comprend le CMB "
"qui est une banque située en Bretagne et le CMSO qui est une banque "
"qui se situe principalement en Aquitaine. C'est sous la présidence de "
"Louis Lichou, dans les années 1980 que différentes filiales sont créées "
"au sein du CMB et forment les principales filiales du groupe qui "
"existent encore aujourd'hui (Federal Finance, Suravenir, Financo, etc.)."
)
result
[{'entity_group': 'ORG',
'score': 0.9974479,
'word': 'Crédit Mutuel Arkéa',
'start': 3,
'end': 22},
{'entity_group': 'LOC',
'score': 0.9000358,
'word': 'Française',
'start': 38,
'end': 47},
{'entity_group': 'ORG',
'score': 0.9788757,
'word': 'CMB',
'start': 66,
'end': 69},
{'entity_group': 'LOC',
'score': 0.99919766,
'word': 'Bretagne',
'start': 99,
'end': 107},
{'entity_group': 'ORG',
'score': 0.9594884,
'word': 'CMSO',
'start': 114,
'end': 118},
{'entity_group': 'LOC',
'score': 0.99935514,
'word': 'Aquitaine',
'start': 169,
'end': 178},
{'entity_group': 'PER',
'score': 0.99911094,
'word': 'Louis Lichou',
'start': 208,
'end': 220},
{'entity_group': 'ORG',
'score': 0.96226394,
'word': 'CMB',
'start': 291,
'end': 294},
{'entity_group': 'ORG',
'score': 0.9983959,
'word': 'Federal Finance',
'start': 374,
'end': 389},
{'entity_group': 'ORG',
'score': 0.9984454,
'word': 'Suravenir',
'start': 391,
'end': 400},
{'entity_group': 'ORG',
'score': 0.9985084,
'word': 'Financo',
'start': 402,
'end': 409}]
Optimum + ONNX量化
from optimum.onnxruntime import ORTModelForTokenClassification
from transformers import AutoTokenizer, pipeline
HUB_MODEL = "cmarkea/distilcamembert-base-nli"
tokenizer = AutoTokenizer.from_pretrained(HUB_MODEL)
model = ORTModelForTokenClassification.from_pretrained(HUB_MODEL)
onnx_qa = pipeline("token-classification", model=model, tokenizer=tokenizer)
quantized_model = ORTModelForTokenClassification.from_pretrained(
HUB_MODEL, file_name="model_quantized.onnx"
)
引用文献
@inproceedings{delestre:hal-03674695,
TITLE = {{DistilCamemBERT:法语CamemBERT模型的蒸馏实现}},
AUTHOR = {Delestre, Cyrile and Amar, Abibatou},
URL = {https://hal.archives-ouvertes.fr/hal-03674695},
BOOKTITLE = {{CAp (机器学习会议)}},
ADDRESS = {法国瓦讷},
YEAR = {2022},
MONTH = Jul,
KEYWORDS = {自然语言处理;Transformer;CamemBERT;知识蒸馏},
PDF = {https://hal.archives-ouvertes.fr/hal-03674695/file/cap2022.pdf},
HAL_ID = {hal-03674695},
HAL_VERSION = {v1},
}