julien-c HF staff commited on
Commit
3a0641d
1 Parent(s): 6ec0b68

Migrate model card from transformers-repo

Browse files

Read announcement at https://discuss.huggingface.co/t/announcement-all-model-cards-will-be-migrated-to-hf-co-model-repos/2755
Original file history: https://github.com/huggingface/transformers/commits/master/model_cards/camembert-base-README.md

Files changed (1) hide show
  1. README.md +115 -0
README.md ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: fr
3
+ license: mit
4
+ datasets:
5
+ - oscar
6
+ ---
7
+
8
+ # CamemBERT: a Tasty French Language Model
9
+
10
+ ## Introduction
11
+
12
+ [CamemBERT](https://arxiv.org/abs/1911.03894) is a state-of-the-art language model for French based on the RoBERTa model.
13
+
14
+ 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.
15
+
16
+ For further information or requests, please go to [Camembert Website](https://camembert-model.fr/)
17
+
18
+ ## Pre-trained models
19
+
20
+ | Model | #params | Arch. | Training data |
21
+ |--------------------------------|--------------------------------|-------|-----------------------------------|
22
+ | `camembert-base` | 110M | Base | OSCAR (138 GB of text) |
23
+ | `camembert/camembert-large` | 335M | Large | CCNet (135 GB of text) |
24
+ | `camembert/camembert-base-ccnet` | 110M | Base | CCNet (135 GB of text) |
25
+ | `camembert/camembert-base-wikipedia-4gb` | 110M | Base | Wikipedia (4 GB of text) |
26
+ | `camembert/camembert-base-oscar-4gb` | 110M | Base | Subsample of OSCAR (4 GB of text) |
27
+ | `camembert/camembert-base-ccnet-4gb` | 110M | Base | Subsample of CCNet (4 GB of text) |
28
+
29
+ ## How to use CamemBERT with HuggingFace
30
+
31
+ ##### Load CamemBERT and its sub-word tokenizer :
32
+ ```python
33
+ from transformers import CamembertModel, CamembertTokenizer
34
+
35
+ # You can replace "camembert-base" with any other model from the table, e.g. "camembert/camembert-large".
36
+ tokenizer = CamembertTokenizer.from_pretrained("camembert-base")
37
+ camembert = CamembertModel.from_pretrained("camembert-base")
38
+
39
+ camembert.eval() # disable dropout (or leave in train mode to finetune)
40
+
41
+ ```
42
+
43
+ ##### Filling masks using pipeline
44
+ ```python
45
+ from transformers import pipeline
46
+
47
+ camembert_fill_mask = pipeline("fill-mask", model="camembert-base", tokenizer="camembert-base")
48
+ results = camembert_fill_mask("Le camembert est <mask> :)")
49
+ # results
50
+ #[{'sequence': '<s> Le camembert est délicieux :)</s>', 'score': 0.4909103214740753, 'token': 7200},
51
+ # {'sequence': '<s> Le camembert est excellent :)</s>', 'score': 0.10556930303573608, 'token': 2183},
52
+ # {'sequence': '<s> Le camembert est succulent :)</s>', 'score': 0.03453315049409866, 'token': 26202},
53
+ # {'sequence': '<s> Le camembert est meilleur :)</s>', 'score': 0.03303130343556404, 'token': 528},
54
+ # {'sequence': '<s> Le camembert est parfait :)</s>', 'score': 0.030076518654823303, 'token': 1654}]
55
+
56
+ ```
57
+
58
+ ##### Extract contextual embedding features from Camembert output
59
+ ```python
60
+ import torch
61
+ # Tokenize in sub-words with SentencePiece
62
+ tokenized_sentence = tokenizer.tokenize("J'aime le camembert !")
63
+ # ['▁J', "'", 'aime', '▁le', '▁ca', 'member', 't', '▁!']
64
+
65
+ # 1-hot encode and add special starting and end tokens
66
+ encoded_sentence = tokenizer.encode(tokenized_sentence)
67
+ # [5, 121, 11, 660, 16, 730, 25543, 110, 83, 6]
68
+ # NB: Can be done in one step : tokenize.encode("J'aime le camembert !")
69
+
70
+ # Feed tokens to Camembert as a torch tensor (batch dim 1)
71
+ encoded_sentence = torch.tensor(encoded_sentence).unsqueeze(0)
72
+ embeddings, _ = camembert(encoded_sentence)
73
+ # embeddings.detach()
74
+ # embeddings.size torch.Size([1, 10, 768])
75
+ # tensor([[[-0.0254, 0.0235, 0.1027, ..., -0.1459, -0.0205, -0.0116],
76
+ # [ 0.0606, -0.1811, -0.0418, ..., -0.1815, 0.0880, -0.0766],
77
+ # [-0.1561, -0.1127, 0.2687, ..., -0.0648, 0.0249, 0.0446],
78
+ # ...,
79
+ ```
80
+
81
+ ##### Extract contextual embedding features from all Camembert layers
82
+ ```python
83
+ from transformers import CamembertConfig
84
+ # (Need to reload the model with new config)
85
+ config = CamembertConfig.from_pretrained("camembert-base", output_hidden_states=True)
86
+ camembert = CamembertModel.from_pretrained("camembert-base", config=config)
87
+
88
+ embeddings, _, all_layer_embeddings = camembert(encoded_sentence)
89
+ # all_layer_embeddings list of len(all_layer_embeddings) == 13 (input embedding layer + 12 self attention layers)
90
+ all_layer_embeddings[5]
91
+ # layer 5 contextual embedding : size torch.Size([1, 10, 768])
92
+ #tensor([[[-0.0032, 0.0075, 0.0040, ..., -0.0025, -0.0178, -0.0210],
93
+ # [-0.0996, -0.1474, 0.1057, ..., -0.0278, 0.1690, -0.2982],
94
+ # [ 0.0557, -0.0588, 0.0547, ..., -0.0726, -0.0867, 0.0699],
95
+ # ...,
96
+ ```
97
+
98
+
99
+ ## Authors
100
+
101
+ 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.
102
+
103
+
104
+ ## Citation
105
+ If you use our work, please cite:
106
+
107
+ ```bibtex
108
+ @inproceedings{martin2020camembert,
109
+ title={CamemBERT: a Tasty French Language Model},
110
+ 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},
111
+ booktitle={Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics},
112
+ year={2020}
113
+ }
114
+ ```
115
+