🚀 DistilCamemBERT-Sentiment
我们推出了 DistilCamemBERT-Sentiment,这是一个基于 DistilCamemBERT 微调的模型,用于法语的情感分析任务。该模型使用了两个数据集构建:亚马逊评论 和 Allociné.fr,以尽量减少偏差。实际上,亚马逊评论的内容较为相似且相对简短,而 Allociné 的评论则是长篇且内容丰富的文本。
此模型与基于 CamemBERT 模型的 tblard/tf-allocine 相近。基于 CamemBERT 的模型存在一个问题,例如在生产阶段的扩展时,推理成本可能会成为一个技术难题。为了应对这一影响,我们提出了这个模型,借助 DistilCamemBERT,在相同功耗下将推理时间缩短了一半。
🚀 快速开始
本模型可用于法语的情感分析任务,以下是使用示例,帮助你快速上手。
✨ 主要特性
- 微调模型:基于 DistilCamemBERT 进行微调,适用于法语情感分析。
- 减少偏差:使用两个不同的数据集构建,减少了数据偏差。
- 高效推理:相比基于 CamemBERT 的模型,在相同功耗下推理时间缩短一半。
📦 安装指南
文档未提及安装步骤,故跳过此章节。
💻 使用示例
基础用法
from transformers import pipeline
analyzer = pipeline(
task='text-classification',
model="cmarkea/distilcamembert-base-sentiment",
tokenizer="cmarkea/distilcamembert-base-sentiment"
)
result = analyzer(
"J'aime me promener en forêt même si ça me donne mal aux pieds.",
return_all_scores=True
)
result
[{'label': '1 star',
'score': 0.047529436647892},
{'label': '2 stars',
'score': 0.14150355756282806},
{'label': '3 stars',
'score': 0.3586442470550537},
{'label': '4 stars',
'score': 0.3181498646736145},
{'label': '5 stars',
'score': 0.13417290151119232}]
高级用法
from optimum.onnxruntime import ORTModelForSequenceClassification
from transformers import AutoTokenizer, pipeline
HUB_MODEL = "cmarkea/distilcamembert-base-sentiment"
tokenizer = AutoTokenizer.from_pretrained(HUB_MODEL)
model = ORTModelForSequenceClassification.from_pretrained(HUB_MODEL)
onnx_qa = pipeline("text-classification", model=model, tokenizer=tokenizer)
quantized_model = ORTModelForSequenceClassification.from_pretrained(
HUB_MODEL, file_name="model_quantized.onnx"
)
📚 详细文档
数据集
数据集包含来自亚马逊的 204,993 条训练评论和 4,999 条测试评论,以及来自 Allocine 网站 的 235,516 条评论和 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 |
基准测试
本模型与 3 个参考模型进行了比较(见下文)。由于每个模型的目标定义并不完全相同,我们详细说明了每个模型使用的性能指标。平均推理时间的测量使用了 AMD Ryzen 5 4500U @ 2.3GHz 6 核处理器。
bert-base-multilingual-uncased-sentiment
nlptown/bert-base-multilingual-uncased-sentiment 基于多语言无大小写版本的 BERT 模型。这个情感分析器与我们的模型一样,都是在亚马逊评论上进行训练的。因此,目标及其定义是相同的。
tf-allociné 和 barthez-sentiment-classification
tblard/tf-allocine 基于 CamemBERT 模型,moussaKam/barthez-sentiment-classification 基于 BARThez,它们使用相同的二分类定义。为了将其转化为二分类问题,我们只考虑 "1 星" 和 "2 星" 标签作为 负面 情感,"4 星" 和 "5 星" 作为 正面 情感。我们排除了 "3 星",因为它可以被解释为 中立 类别。在这种情况下,+/-1 星估计误差的问题就不存在了。然后我们只使用经典的准确率定义。
🔧 技术细节
文档未提供具体的技术实现细节,故跳过此章节。
📄 许可证
本项目采用 MIT 许可证。
📖 引用
@inproceedings{delestre:hal-03674695,
TITLE = {{DistilCamemBERT : une distillation du mod{\`e}le fran{\c c}ais CamemBERT}},
AUTHOR = {Delestre, Cyrile and Amar, Abibatou},
URL = {https://hal.archives-ouvertes.fr/hal-03674695},
BOOKTITLE = {{CAp (Conf{\'e}rence sur l'Apprentissage automatique)}},
ADDRESS = {Vannes, France},
YEAR = {2022},
MONTH = Jul,
KEYWORDS = {NLP ; Transformers ; CamemBERT ; Distillation},
PDF = {https://hal.archives-ouvertes.fr/hal-03674695/file/cap2022.pdf},
HAL_ID = {hal-03674695},
HAL_VERSION = {v1},
}