Cyrile's picture
Update README.md
affa694
|
raw
history blame
3.4 kB
metadata
language: fr
license: mit
datasets:
  - oscar
widget:
  - text: J'aime lire les <mask> de SF.

DistilCamemBERT

We present a distillation version of the well named CamemBERT, a RoBERTa French model version, alias DistilCamemBERT. The aim of distillation is to drastically reduce the complexity of the model while preserving the performances. The proof of concept is shown in the DistilBERT paper and the code used for the training is inspired by the code of DistilBERT.

Loss function

The training for the distilled model (student model) is designed to be the closest as possible to the original model (teacher model). To perform this the loss function is composed of 3 parts:

  • DistilLoss: a distillation loss which measures the silimarity between the probabilities at the outputs of the student and teacher models with a cross-entropy loss on the MLM task ;
  • MLMLoss: a Masked Language Modeling (MLM) task loss to perform the student model with the original task of the teacher model ;
  • CosineLoss: and finally a cosine embedding loss. This loss function is applied on the last hidden layers of student and teacher models to guarantee a collinearity between them.

The final loss function is a combination of these three loss functions. We use the following ponderation:

Loss = 0.5 DistilLoss + 0.2 MLMLoss + 0.3 CosineLoss

Dataset

To limit the bias between the student and teacher models, the dataset used for the DstilCamemBERT training is the same as the camembert-base training one: OSCAR. The French part of this dataset approximately represents 140 GB on a hard drive disk.

Training

We pre-trained the model on a nVidia Titan RTX during 18 days.

Evaluation results

Dataset name f1-score
FLUE CLS 83%
FLUE PAWS-X 77%
FLUE XNLI 68%
wikiner_fr NER 92%

How to use DistilCamemBERT

Load CamemBERT and its sub-word tokenizer :

from transformers import CamembertModel, CamembertTokenizer

tokeinzer = CamembertTokenizer.from_pretrained("cmarkea/distilcamembert-base")
model = CamembertModel.from_pretrained("cmarkea/distilcamembert-base")
model.eval()
...

Filling masks using pipeline :

from transformers import pipeline

model_fill_mask = pipeline("fill-mask", model="cmarkea/distilcamembert-base", tokenizer="cmarkea/distilcamembert-base")
results = model_fill_mask("Le camembert est <mask> :)")
#results
#[{'sequence': '<s> Le camembert est délicieux :)</s>', 'score': 0.3878222405910492, 'token': 7200},
# {'sequence': '<s> Le camembert est excellent :)</s>', 'score': 0.06469205021858215, 'token': 2183}, 
# {'sequence': '<s> Le camembert est parfait :)</s>', 'score': 0.04534877464175224, 'token': 1654}, 
# {'sequence': '<s> Le camembert est succulent :)</s>', 'score': 0.04128391295671463, 'token': 26202}, 
# {'sequence': '<s> Le camembert est magnifique :)</s>', 'score': 0.02425697259604931, 'token': 1509}]