我们介绍了DistilCamemBERT-NLI,它是用于法语自然语言推理(NLI)任务的预训练模型,也被称为文本蕴涵识别(RTE)。该模型是基于XNLI数据集构建的,该数据集确定前提是否蕴含、矛盾或既不蕴含也不矛盾于假设。
这种模型结构与基于CamemBERT的模型基本相似。基于CamemBERT的模型存在一个问题,即在产品生产阶段的扩展问题,特别是在这种任务的交叉编码的情况下,推理成本可能成为技术问题。为了抵消这种影响,我们提出了这种模型结构,通过DistilCamemBERT将推理时间减少了一半,同时具有相同的计算功耗。
来自XNLI数据集的数据包括392,702个前提与其假设的训练对和5,010个测试对。目标是预测文本蕴涵(句子A是否蕴含/矛盾/既不蕴含也不矛盾句子B),这是一个分类任务(给定两个句子,预测三个标签之一)。句子A称为“前提”,句子B称为“假设”,因此模型的目标可以确定如下:P(前提=c∈{矛盾,蕴涵,中性}∣假设)。
| class | precision (%) | f1-score (%) | support |
|---|---|---|---|
| global | 77.70 | 77.45 | 5,010 |
| contradiction | 78.00 | 79.54 | 1,670 |
| entailment | 82.90 | 78.87 | 1,670 |
| neutral | 72.18 | 74.04 | 1,670 |
我们将 DistilCamemBERT 模型与另外两种适用于法语的模型结构进行了比较。第一种是基于其名字为 CamemBERT 的法语RoBERTa模型,第二种是基于 mDeBERTav3 的多语言模型 MoritzLaurer/mDeBERTa-v3-base-mnli-xnli 。为了比较性能,使用了准确性和 MCC (Matthews Correlation Coefficient) 两个度量标准。我们使用AMD Ryzen 5 4500U @ 2.3GHz的6个核心来进行平均推理时间的测量。
| model | time (ms) | accuracy (%) | MCC (x100) |
|---|---|---|---|
| 12313321 | 51.35 | 77.45 | 66.24 |
| 12314321 | 105.0 | 81.72 | 72.67 |
| 12315321 | 299.18 | 83.43 | 75.15 |
这种模型结构的主要优势在于创建了一个无需训练即可进行文本分类的零样本分类器。这个任务可以概括为:P(假设=i∈C∣前提)=eP(前提=蕴涵∣假设=i)∑j∈CeP(前提=蕴涵∣假设=j)。
对于这部分,我们使用了两个数据集。第一个数据集 allocine 用于训练情感分析模型。该数据集包含两个类别:“positif”和“négatif”,表示电影评论的积极或消极评价。在这里,我们使用“Ce commentaire est {}。”作为假设模板,“positif”和“négatif”作为候选标签。
| model | time (ms) | accuracy (%) | MCC (x100) |
|---|---|---|---|
| 12313321 | 195.54 | 80.59 | 63.71 |
| 12314321 | 378.39 | 86.37 | 73.74 |
| 12315321 | 520.58 | 84.97 | 70.05 |
第二个数据集 mlsum 用于训练摘要生成模型。为此,我们聚合子主题并选择其中一些。我们使用文章摘要部分来预测它们的主题。在这种情况下,我们使用的假设模板是“C'est un article traitant de {}。”,候选标签是:“économie”,“politique”,“sport”和“science”。
| model | time (ms) | accuracy (%) | MCC (x100) |
|---|---|---|---|
| 12313321 | 217.77 | 79.30 | 70.55 |
| 12314321 | 448.27 | 70.7 | 64.10 |
| 12315321 | 591.34 | 64.45 | 58.67 |
from transformers import pipeline
classifier = pipeline(
task='zero-shot-classification',
model="cmarkea/distilcamembert-base-nli",
tokenizer="cmarkea/distilcamembert-base-nli"
)
result = classifier (
sequences="Le style très cinéphile de Quentin Tarantino "
"se reconnaît entre autres par sa narration postmoderne "
"et non linéaire, ses dialogues travaillés souvent "
"émaillés de références à la culture populaire, et ses "
"scènes hautement esthétiques mais d'une violence "
"extrême, inspirées de films d'exploitation, d'arts "
"martiaux ou de western spaghetti.",
candidate_labels="cinéma, technologie, littérature, politique",
hypothesis_template="Ce texte parle de {}."
)
result
{"labels": ["cinéma",
"littérature",
"technologie",
"politique"],
"scores": [0.7164115309715271,
0.12878799438476562,
0.1092301607131958,
0.0455702543258667]}
from optimum.onnxruntime import ORTModelForSequenceClassification
from transformers import AutoTokenizer, pipeline
HUB_MODEL = "cmarkea/distilcamembert-base-nli"
tokenizer = AutoTokenizer.from_pretrained(HUB_MODEL)
model = ORTModelForSequenceClassification.from_pretrained(HUB_MODEL)
onnx_qa = pipeline("zero-shot-classification", model=model, tokenizer=tokenizer)
# Quantized onnx model
quantized_model = ORTModelForSequenceClassification.from_pretrained(
HUB_MODEL, file_name="model_quantized.onnx"
)
@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},
}