DistilCamemBERT-Sentiment
We present DistilCamemBERT-Sentiment, which is
DistilCamemBERT fine-tuned for the sentiment analysis task for the French language. This model is built using two datasets:
Amazon Reviews and
Allociné.fr to minimize the bias. Indeed, Amazon reviews are similar in messages and relatively shorts, contrary to Allociné critics, who are long and rich texts.
This modelization is close to
tblard/tf-allocine based on
CamemBERT model. The problem of the modelizations based on CamemBERT is at the scaling moment, for the production phase, for example. Indeed, inference cost can be a technological issue. To counteract this effect, we propose this modelization which
divides the inference time by two with the same consumption power thanks to
DistilCamemBERT.
Dataset
The dataset comprises 204,993 reviews for training and 4,999 reviews for the test from Amazon, and 235,516 and 4,729 critics from
Allocine website. The dataset is labeled into five categories:
- 1 star: represents a terrible appreciation,
- 2 stars: bad appreciation,
- 3 stars: neutral appreciation,
- 4 stars: good appreciation,
- 5 stars: excellent appreciation.
Evaluation results
In addition of accuracy (called here exact accuracy) in order to be robust to +/-1 star estimation errors, we will take the following definition as a performance measure:
$$\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)$$
where \(\hat{f}_l\) is the l-th largest predicted label, \(y\) the true label, \(\mathcal{O}\) is the test set of the observations and \(\mathbb{1}\) is the indicator function.
| class | exact accuracy (%) | top-2 acc (%) | support |
|---|
| global | 61.01 | 88.80 | 9,698 |
| 1 star | 87.21 | 77.17 | 1,905 |
| 2 stars | 79.19 | 84.75 | 1,935 |
| 3 stars | 77.85 | 78.98 | 1,974 |
| 4 stars | 78.61 | 90.22 | 1,952 |
| 5 stars | 85.96 | 82.92 | 1,932 |
Benchmark
This model is compared to 3 reference models (see below). As each model doesn't have the exact definition of targets, we detail the performance measure used for each. An AMD Ryzen 5 4500U @ 2.3GHz with 6 cores was used for the mean inference time measure.
bert-base-multilingual-uncased-sentiment
nlptown/bert-base-multilingual-uncased-sentiment is based on BERT model in the multilingual and uncased version. This sentiment analyzer is trained on Amazon reviews, similar to our model. Hence the targets and their definitions are the same.
tf-allociné and barthez-sentiment-classification
tblard/tf-allocine based on
CamemBERT model and
moussaKam/barthez-sentiment-classification based on
BARThez use the same bi-class definition between them. To bring this back to a two-class problem, we will only consider the
"1 star" and
"2 stars" labels for the
negative sentiments and
"4 stars" and
"5 stars" for
positive sentiments. We exclude the
"3 stars" which can be interpreted as a
neutral class. In this context, the problem of +/-1 star estimation errors disappears. Then we use only the classical accuracy definition.
How to use DistilCamemBERT-Sentiment
1from transformers import pipeline
2
3analyzer = pipeline(
4 task='text-classification',
5 model="cmarkea/distilcamembert-base-sentiment",
6 tokenizer="cmarkea/distilcamembert-base-sentiment"
7)
8result = analyzer(
9 "J'aime me promener en forêt même si ça me donne mal aux pieds.",
10 return_all_scores=True
11)
12
13result
14[{'label': '1 star',
15 'score': 0.047529436647892},
16 {'label': '2 stars',
17 'score': 0.14150355756282806},
18 {'label': '3 stars',
19 'score': 0.3586442470550537},
20 {'label': '4 stars',
21 'score': 0.3181498646736145},
22 {'label': '5 stars',
23 'score': 0.13417290151119232}]
Optimum + ONNX
1from optimum.onnxruntime import ORTModelForSequenceClassification
2from transformers import AutoTokenizer, pipeline
3
4HUB_MODEL = "cmarkea/distilcamembert-base-sentiment"
5
6tokenizer = AutoTokenizer.from_pretrained(HUB_MODEL)
7model = ORTModelForSequenceClassification.from_pretrained(HUB_MODEL)
8onnx_qa = pipeline("text-classification", model=model, tokenizer=tokenizer)
9
10# Quantized onnx model
11quantized_model = ORTModelForSequenceClassification.from_pretrained(
12 HUB_MODEL, file_name="model_quantized.onnx"
13)
Citation
1@inproceedings{delestre:hal-03674695,
2 TITLE = {{DistilCamemBERT : une distillation du mod{\`e}le fran{\c c}ais CamemBERT}},
3 AUTHOR = {Delestre, Cyrile and Amar, Abibatou},
4 URL = {https://hal.archives-ouvertes.fr/hal-03674695},
5 BOOKTITLE = {{CAp (Conf{\'e}rence sur l'Apprentissage automatique)}},
6 ADDRESS = {Vannes, France},
7 YEAR = {2022},
8 MONTH = Jul,
9 KEYWORDS = {NLP ; Transformers ; CamemBERT ; Distillation},
10 PDF = {https://hal.archives-ouvertes.fr/hal-03674695/file/cap2022.pdf},
11 HAL_ID = {hal-03674695},
12 HAL_VERSION = {v1},
13}