语言: 法语
许可证: MIT
数据集:
- amazon_reviews_multi
- allocine
示例输入:
- 文本: "我以为会读到一本烂书,但最后发现它超级棒!"
- 文本: "这家银行很不错,但它不提供非接触式支付服务。"
- 文本: "这家银行非常棒,而且还提供非接触式支付服务。"
基础模型:
- cmarkea/distilcamembert-base
DistilCamemBERT情感分析模型
我们推出DistilCamemBERT-Sentiment,这是基于DistilCamemBERT微调的法语情感分析模型。该模型使用两个数据集构建:亚马逊评论和Allociné.fr以最小化偏差。亚马逊评论内容相似且较短,而Allociné的影评则是长篇丰富的文本。
此模型与基于CamemBERT的tblard/tf-allocine相近。基于CamemBERT的模型在扩展时(如生产阶段)可能存在推理成本高的技术问题。为应对此问题,我们通过DistilCamemBERT实现了推理时间减半且保持相同性能。
数据集
训练集包含204,993条亚马逊评论和235,516条Allocine网站影评,测试集分别为4,999条和4,729条。标签分为五类:
- 1星:极差评价
- 2星:差评
- 3星:中性评价
- 4星:好评
- 5星:极佳评价
评估结果
除准确率(此处称精确准确率)外,为容忍±1星误差,我们采用以下性能指标:
$$\mathrm{top!-!2; acc}=\frac{1}{|\mathcal{O}|}\sum_{i\in\mathcal{O}}\sum_{0\leq l < 2}\mathbb{1}(\hat{f}_{i,l}=y_i)$$
其中\(\hat{f}_l\)为预测概率第l高的标签,\(y\)为真实标签,\(\mathcal{O}\)为测试集,\(\mathbb{1}\)为指示函数。
类别 |
精确准确率(%) |
top-2准确率(%) |
样本量 |
总体 |
61.01 |
88.80 |
9,698 |
1星 |
87.21 |
77.17 |
1,905 |
2星 |
79.19 |
84.75 |
1,935 |
3星 |
77.85 |
78.98 |
1,974 |
4星 |
78.61 |
90.22 |
1,952 |
5星 |
85.96 |
82.92 |
1,932 |
基准测试
对比三个参考模型(如下)。由于各模型目标定义不同,我们分别说明其性能指标。测试环境为AMD Ryzen 5 4500U @ 2.3GHz 6核处理器。
bert-base-multilingual-uncased-sentiment
nlptown/bert-base-multilingual-uncased-sentiment基于多语言无大小写BERT模型,训练数据与本研究相同。
模型 |
推理时间(ms) |
精确准确率(%) |
top-2准确率(%) |
本模型 |
95.56 |
61.01 |
88.80 |
对比模型 |
187.70 |
54.41 |
82.82 |
tf-allociné与barthez-sentiment-classification
tblard/tf-allocine和moussaKam/barthez-sentiment-classification采用相同的二分类定义。为统一比较,我们将"1-2星"视为负面,"4-5星"为正面,排除中性"3星"。
模型 |
推理时间(ms) |
精确准确率(%) |
本模型 |
95.56 |
97.52 |
tf-allocine |
329.74 |
95.69 |
barthez |
197.95 |
94.29 |
使用方法
from transformers import pipeline
analyzer = pipeline(
task='text-classification',
model="cmarkea/distilcamembert-base-sentiment",
tokenizer="cmarkea/distilcamembert-base-sentiment"
)
result = analyzer(
"我喜欢在森林里散步,即使脚会疼。",
return_all_scores=True
)
[{'label': '1星', 'score': 0.0475},
{'label': '2星', 'score': 0.1415},
{'label': '3星', 'score': 0.3586},
{'label': '4星', 'score': 0.3181},
{'label': '5星', 'score': 0.1342}]
Optimum + ONNX加速
from optimum.onnxruntime import ORTModelForSequenceClassification
from transformers import AutoTokenizer, pipeline
model_path = "cmarkea/distilcamembert-base-sentiment"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = ORTModelForSequenceClassification.from_pretrained(model_path)
onnx_analyzer = pipeline("text-classification", model=model, tokenizer=tokenizer)
quantized_model = ORTModelForSequenceClassification.from_pretrained(
model_path, file_name="model_quantized.onnx"
)
引用
@inproceedings{delestre:hal-03674695,
title = {DistilCamemBERT:法语CamemBERT模型的蒸馏},
author = {Delestre, Cyrile and Amar, Abibatou},
booktitle = {CAp(机器学习会议)},
year = {2022},
month = 7,
keywords = {自然语言处理;Transformer;CamemBERT;模型蒸馏},
url = {https://hal.archives-ouvertes.fr/hal-03674695},
}