-
Notifications
You must be signed in to change notification settings - Fork 30.7k
Updated CamemBERT model card to new standardized format #39227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
stevhliu
merged 6 commits into
huggingface:main
from
MShaheerMalik77:update-camembert-model-card
Jul 11, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
70a2fa4
Updated CamemBERT model card to new standardized format
MShaheerMalik77 b54d431
Merge branch 'main' into update-camembert-model-card
MShaheerMalik77 a5dd7e1
Applied review suggestions for CamemBERT: restored API refs, added ex…
MShaheerMalik77 99e12dd
Updated CamemBERT usage examples, quantization, badges, and format
MShaheerMalik77 aef8440
Updated CamemBERT badges
MShaheerMalik77 b4640fe
Fixed CLI Section
MShaheerMalik77 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,49 +14,105 @@ rendered properly in your Markdown viewer. | |
|
||
--> | ||
|
||
<div style="float: right;"> | ||
MShaheerMalik77 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<div class="flex flex-wrap space-x-1"> | ||
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white"> | ||
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white"> | ||
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white"> | ||
</div> | ||
</div> | ||
|
||
# CamemBERT | ||
|
||
<div class="flex flex-wrap space-x-1"> | ||
<img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white"> | ||
<img alt="TensorFlow" src="https://img.shields.io/badge/TensorFlow-FF6F00?style=flat&logo=tensorflow&logoColor=white"> | ||
<img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white"> | ||
</div> | ||
[CamemBERT](https://huggingface.co/papers/1911.03894) is a language model based on [RoBERTa](./roberta), but trained specifically on French text from the OSCAR dataset, making it more effective for French language tasks. | ||
|
||
What sets CamemBERT apart is that it learned from a huge, high quality collection of French data, as opposed to mixing lots of languages. This helps it really understand French better than many multilingual models. | ||
MShaheerMalik77 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Common applications of CamemBERT include masked language modeling (Fill-mask prediction), text classification (sentiment analysis), token classification (entity recognition) and sentence pair classification (entailment tasks). | ||
MShaheerMalik77 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
You can find all the original CamemBERT checkpoints under the [ALMAnaCH](https://huggingface.co/almanach/models?search=camembert) organization. | ||
|
||
> [!TIP] | ||
> This model was contributed by the [ALMAnaCH (Inria)](https://huggingface.co/almanach) team. | ||
> | ||
> Click on the CamemBERT models in the right sidebar for more examples of how to apply CamemBERT to different NLP tasks. | ||
|
||
The examples below demonstrate how to predict the `<mask>` token with [`Pipeline`], [`AutoModel`], and from the command line. | ||
|
||
<hfoptions id="usage"> | ||
|
||
<hfoption id="Pipeline"> | ||
|
||
```python | ||
import torch | ||
from transformers import pipeline | ||
MShaheerMalik77 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Overview | ||
pipeline = pipeline("fill-mask", model="camembert-base", torch_dtype=torch.float16, device=0) | ||
pipeline("Le camembert est un délicieux fromage <mask>.") | ||
``` | ||
</hfoption> | ||
|
||
The CamemBERT model was proposed in [CamemBERT: a Tasty French Language Model](https://huggingface.co/papers/1911.03894) by | ||
[Louis Martin](https://huggingface.co/louismartin), [Benjamin Muller](https://huggingface.co/benjamin-mlr), [Pedro Javier Ortiz Suárez](https://huggingface.co/pjox), Yoann Dupont, Laurent Romary, Éric Villemonte de la | ||
Clergerie, [Djamé Seddah](https://huggingface.co/Djame), and [Benoît Sagot](https://huggingface.co/sagot). It is based on Facebook's RoBERTa model released in 2019. It is a model | ||
trained on 138GB of French text. | ||
<hfoption id="AutoModel"> | ||
|
||
The abstract from the paper is the following: | ||
```python | ||
import torch | ||
from transformers import AutoTokenizer, AutoModelForMaskedLM | ||
MShaheerMalik77 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
*Pretrained language models are now ubiquitous in Natural Language Processing. Despite their success, most available | ||
models have either been trained on English data or on the concatenation of data in multiple languages. This makes | ||
practical use of such models --in all languages except English-- very limited. Aiming to address this issue for French, | ||
we release CamemBERT, a French version of the Bi-directional Encoders for Transformers (BERT). We measure the | ||
performance of CamemBERT compared to multilingual models in multiple downstream tasks, namely part-of-speech tagging, | ||
dependency parsing, named-entity recognition, and natural language inference. CamemBERT improves the state of the art | ||
for most of the tasks considered. We release the pretrained model for CamemBERT hoping to foster research and | ||
downstream applications for French NLP.* | ||
tokenizer = AutoTokenizer.from_pretrained("camembert-base") | ||
model = AutoModelForMaskedLM.from_pretrained("camembert-base", torch_dtype="auto", device_map="auto", attn_implementation="sdpa") | ||
inputs = tokenizer("Le camembert est un délicieux fromage <mask>.", return_tensors="pt").to("cuda") | ||
|
||
This model was contributed by [the ALMAnaCH team (Inria)](https://huggingface.co/almanach). The original code can be found [here](https://camembert-model.fr/). | ||
with torch.no_grad(): | ||
outputs = model(**inputs) | ||
predictions = outputs.logits | ||
|
||
<Tip> | ||
masked_index = torch.where(inputs['input_ids'] == tokenizer.mask_token_id)[1] | ||
predicted_token_id = predictions[0, masked_index].argmax(dim=-1) | ||
predicted_token = tokenizer.decode(predicted_token_id) | ||
|
||
This implementation is the same as RoBERTa. Refer to the [documentation of RoBERTa](roberta) for usage examples as well | ||
as the information relative to the inputs and outputs. | ||
print(f"The predicted token is: {predicted_token}") | ||
``` | ||
</hfoption> | ||
|
||
</Tip> | ||
<hfoption id="transformers CLI"> | ||
|
||
## Resources | ||
```bash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. echo -e "Le camembert est un délicieux fromage <mask>." | transformers run --task fill-mask --model camembert-base --device 0 |
||
echo -e "Le camembert est un délicieux fromage <mask>." | transformers run --task fill-mask --model camembert-base --device 0 | ||
``` | ||
|
||
- [Text classification task guide](../tasks/sequence_classification) | ||
- [Token classification task guide](../tasks/token_classification) | ||
- [Question answering task guide](../tasks/question_answering) | ||
- [Causal language modeling task guide](../tasks/language_modeling) | ||
- [Masked language modeling task guide](../tasks/masked_language_modeling) | ||
- [Multiple choice task guide](../tasks/multiple_choice) | ||
</hfoption> | ||
|
||
</hfoptions> | ||
|
||
|
||
Quantization reduces the memory burden of large models by representing weights in lower precision. Refer to the [Quantization](../quantization/overview) overview for available options. | ||
|
||
The example below uses [bitsandbytes](../quantization/bitsandbytes) quantization to quantize the weights to 8-bits. | ||
|
||
```python | ||
from transformers import AutoTokenizer, AutoModelForMaskedLM, BitsAndBytesConfig | ||
MShaheerMalik77 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import torch | ||
|
||
quant_config = BitsAndBytesConfig(load_in_8bit=True) | ||
model = AutoModelForMaskedLM.from_pretrained( | ||
"almanach/camembert-large", | ||
quantization_config=quant_config, | ||
device_map="auto" | ||
) | ||
tokenizer = AutoTokenizer.from_pretrained("almanach/camembert-large") | ||
|
||
inputs = tokenizer("Le camembert est un délicieux fromage <mask>.", return_tensors="pt").to("cuda") | ||
|
||
with torch.no_grad(): | ||
outputs = model(**inputs) | ||
predictions = outputs.logits | ||
|
||
masked_index = torch.where(inputs["input_ids"] == tokenizer.mask_token_id)[1] | ||
predicted_token_id = predictions[0, masked_index].argmax(dim=-1) | ||
predicted_token = tokenizer.decode(predicted_token_id) | ||
|
||
print(f"The predicted token is: {predicted_token}") | ||
``` | ||
|
||
## CamembertConfig | ||
MShaheerMalik77 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
@@ -137,5 +193,4 @@ as the information relative to the inputs and outputs. | |
[[autodoc]] TFCamembertForQuestionAnswering | ||
|
||
</tf> | ||
</frameworkcontent> | ||
|
||
</frameworkcontent> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.