CamemBERT
is a state-of-the-art language model for French based on the RoBERTa model.
It is now available on Hugging Face in 6 different versions with varying number of parameters, amount of pretraining data and pretraining data source domains.
from transformers import CamembertModel, CamembertTokenizer
# You can replace "camembert-base" with any other model from the table, e.g. "camembert/camembert-large".
tokenizer = CamembertTokenizer.from_pretrained("camembert/camembert-base-ccnet")
camembert = CamembertModel.from_pretrained("camembert/camembert-base-ccnet")
camembert.eval() # disable dropout (or leave in train mode to finetune)
Filling masks using pipeline
from transformers import pipeline
camembert_fill_mask = pipeline("fill-mask", model="camembert/camembert-base-ccnet", tokenizer="camembert/camembert-base-ccnet")
results = camembert_fill_mask("Le camembert est <mask> :)")
# results#[{'sequence': '<s> Le camembert est bon :)</s>', 'score': 0.14011502265930176, 'token': 305},# {'sequence': '<s> Le camembert est délicieux :)</s>', 'score': 0.13929404318332672, 'token': 11661}, # {'sequence': '<s> Le camembert est excellent :)</s>', 'score': 0.07010319083929062, 'token': 3497}, # {'sequence': '<s> Le camembert est parfait :)</s>', 'score': 0.025885622948408127, 'token': 2528}, # {'sequence': '<s> Le camembert est top :)</s>', 'score': 0.025684962049126625, 'token': 2328}]
Extract contextual embedding features from Camembert output
import torch
# Tokenize in sub-words with SentencePiece
tokenized_sentence = tokenizer.tokenize("J'aime le camembert !")
# ['▁J', "'", 'aime', '▁le', '▁cam', 'ember', 't', '▁!'] # 1-hot encode and add special starting and end tokens
encoded_sentence = tokenizer.encode(tokenized_sentence)
# [5, 133, 22, 1250, 16, 12034, 14324, 81, 76, 6]# NB: Can be done in one step : tokenize.encode("J'aime le camembert !")# Feed tokens to Camembert as a torch tensor (batch dim 1)
encoded_sentence = torch.tensor(encoded_sentence).unsqueeze(0)
embeddings, _ = camembert(encoded_sentence)
# embeddings.detach()# embeddings.size torch.Size([1, 10, 768])#tensor([[[ 0.0667, -0.2467, 0.0954, ..., 0.2144, 0.0279, 0.3621],# [-0.0472, 0.4092, -0.6602, ..., 0.2095, 0.1391, -0.0401],# [ 0.1911, -0.2347, -0.0811, ..., 0.4306, -0.0639, 0.1821],# ...,
Extract contextual embedding features from all Camembert layers
from transformers import CamembertConfig
# (Need to reload the model with new config)
config = CamembertConfig.from_pretrained("camembert/camembert-base-ccnet", output_hidden_states=True)
camembert = CamembertModel.from_pretrained("camembert/camembert-base-ccnet", config=config)
embeddings, _, all_layer_embeddings = camembert(encoded_sentence)
# all_layer_embeddings list of len(all_layer_embeddings) == 13 (input embedding layer + 12 self attention layers)
all_layer_embeddings[5]
# layer 5 contextual embedding : size torch.Size([1, 10, 768])#tensor([[[ 0.0057, -0.1022, 0.0163, ..., -0.0675, -0.0360, 0.1078],# [-0.1096, -0.3344, -0.0593, ..., 0.1625, -0.0432, -0.1646],# [ 0.3751, -0.3829, 0.0844, ..., 0.1067, -0.0330, 0.3334],# ...,
Authors
CamemBERT was trained and evaluated by Louis Martin*, Benjamin Muller*, Pedro Javier Ortiz Suárez*, Yoann Dupont, Laurent Romary, Éric Villemonte de la Clergerie, Djamé Seddah and Benoît Sagot.
Citation
If you use our work, please cite:
@inproceedings{martin2020camembert,
title={CamemBERT: a Tasty French Language Model},
author={Martin, Louis and Muller, Benjamin and Su{\'a}rez, Pedro Javier Ortiz and Dupont, Yoann and Romary, Laurent and de la Clergerie, {\'E}ric Villemonte and Seddah, Djam{\'e} and Sagot, Beno{\^\i}t},
booktitle={Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics},
year={2020}
}
Runs of almanach camembert-base-ccnet on huggingface.co
318
Total runs
0
24-hour runs
20
3-day runs
53
7-day runs
252
30-day runs
More Information About camembert-base-ccnet huggingface.co Model
camembert-base-ccnet huggingface.co
camembert-base-ccnet huggingface.co is an AI model on huggingface.co that provides camembert-base-ccnet's model effect (), which can be used instantly with this almanach camembert-base-ccnet model. huggingface.co supports a free trial of the camembert-base-ccnet model, and also provides paid use of the camembert-base-ccnet. Support call camembert-base-ccnet model through api, including Node.js, Python, http.
camembert-base-ccnet huggingface.co is an online trial and call api platform, which integrates camembert-base-ccnet's modeling effects, including api services, and provides a free online trial of camembert-base-ccnet, you can try camembert-base-ccnet online for free by clicking the link below.
almanach camembert-base-ccnet online free url in huggingface.co:
camembert-base-ccnet is an open source model from GitHub that offers a free installation service, and any user can find camembert-base-ccnet on GitHub to install. At the same time, huggingface.co provides the effect of camembert-base-ccnet install, users can directly use camembert-base-ccnet installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
camembert-base-ccnet install url in huggingface.co: