julien-c HF staff commited on
Commit
efb6c58
1 Parent(s): 52a19f0

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/camembert-base-oscar-4gb/README.md

Files changed (1) hide show
  1. README.md +111 -0
README.md ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: fr
3
+ ---
4
+
5
+ # CamemBERT: a Tasty French Language Model
6
+
7
+ ## Introduction
8
+
9
+ [CamemBERT](https://arxiv.org/abs/1911.03894) is a state-of-the-art language model for French based on the RoBERTa model.
10
+
11
+ 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.
12
+
13
+ For further information or requests, please go to [Camembert Website](https://camembert-model.fr/)
14
+
15
+ ## Pre-trained models
16
+
17
+ | Model | #params | Arch. | Training data |
18
+ |--------------------------------|--------------------------------|-------|-----------------------------------|
19
+ | `camembert-base` | 110M | Base | OSCAR (138 GB of text) |
20
+ | `camembert/camembert-large` | 335M | Large | CCNet (135 GB of text) |
21
+ | `camembert/camembert-base-ccnet` | 110M | Base | CCNet (135 GB of text) |
22
+ | `camembert/camembert-base-wikipedia-4gb` | 110M | Base | Wikipedia (4 GB of text) |
23
+ | `camembert/camembert-base-oscar-4gb` | 110M | Base | Subsample of OSCAR (4 GB of text) |
24
+ | `camembert/camembert-base-ccnet-4gb` | 110M | Base | Subsample of CCNet (4 GB of text) |
25
+
26
+ ## How to use CamemBERT with HuggingFace
27
+
28
+ ##### Load CamemBERT and its sub-word tokenizer :
29
+ ```python
30
+ from transformers import CamembertModel, CamembertTokenizer
31
+
32
+ # You can replace "camembert-base" with any other model from the table, e.g. "camembert/camembert-large".
33
+ tokenizer = CamembertTokenizer.from_pretrained("camembert/camembert-base-oscar-4gb")
34
+ camembert = CamembertModel.from_pretrained("camembert/camembert-base-oscar-4gb")
35
+
36
+ camembert.eval() # disable dropout (or leave in train mode to finetune)
37
+
38
+ ```
39
+
40
+ ##### Filling masks using pipeline
41
+ ```python
42
+ from transformers import pipeline
43
+
44
+ camembert_fill_mask = pipeline("fill-mask", model="camembert/camembert-base-oscar-4gb", tokenizer="camembert/camembert-base-oscar-4gb")
45
+ >>> results = camembert_fill_mask("Le camembert est <mask> !")
46
+ # results
47
+ #[{'sequence': '<s> Le camembert est parfait!</s>', 'score': 0.04089554399251938, 'token': 1654},
48
+ #{'sequence': '<s> Le camembert est délicieux!</s>', 'score': 0.037193264812231064, 'token': 7200},
49
+ #{'sequence': '<s> Le camembert est prêt!</s>', 'score': 0.025467922911047935, 'token': 1415},
50
+ #{'sequence': '<s> Le camembert est meilleur!</s>', 'score': 0.022812040522694588, 'token': 528},
51
+ #{'sequence': '<s> Le camembert est différent!</s>', 'score': 0.017135459929704666, 'token': 2935}]
52
+
53
+ ```
54
+
55
+ ##### Extract contextual embedding features from Camembert output
56
+ ```python
57
+ import torch
58
+ # Tokenize in sub-words with SentencePiece
59
+ tokenized_sentence = tokenizer.tokenize("J'aime le camembert !")
60
+ # ['▁J', "'", 'aime', '▁le', '▁ca', 'member', 't', '▁!']
61
+
62
+ # 1-hot encode and add special starting and end tokens
63
+ encoded_sentence = tokenizer.encode(tokenized_sentence)
64
+ # [5, 121, 11, 660, 16, 730, 25543, 110, 83, 6]
65
+ # NB: Can be done in one step : tokenize.encode("J'aime le camembert !")
66
+
67
+ # Feed tokens to Camembert as a torch tensor (batch dim 1)
68
+ encoded_sentence = torch.tensor(encoded_sentence).unsqueeze(0)
69
+ embeddings, _ = camembert(encoded_sentence)
70
+ # embeddings.detach()
71
+ # embeddings.size torch.Size([1, 10, 768])
72
+ #tensor([[[-0.1120, -0.1464, 0.0181, ..., -0.1723, -0.0278, 0.1606],
73
+ # [ 0.1234, 0.1202, -0.0773, ..., -0.0405, -0.0668, -0.0788],
74
+ # [-0.0440, 0.0480, -0.1926, ..., 0.1066, -0.0961, 0.0637],
75
+ # ...,
76
+ ```
77
+
78
+ ##### Extract contextual embedding features from all Camembert layers
79
+ ```python
80
+ from transformers import CamembertConfig
81
+ # (Need to reload the model with new config)
82
+ config = CamembertConfig.from_pretrained("camembert/camembert-base-oscar-4gb", output_hidden_states=True)
83
+ camembert = CamembertModel.from_pretrained("camembert/camembert-base-oscar-4gb", config=config)
84
+
85
+ embeddings, _, all_layer_embeddings = camembert(encoded_sentence)
86
+ # all_layer_embeddings list of len(all_layer_embeddings) == 13 (input embedding layer + 12 self attention layers)
87
+ all_layer_embeddings[5]
88
+ # layer 5 contextual embedding : size torch.Size([1, 10, 768])
89
+ #tensor([[[-0.1584, -0.1207, -0.0179, ..., 0.5457, 0.1491, -0.1191],
90
+ # [-0.1122, 0.3634, 0.0676, ..., 0.4395, -0.0470, -0.3781],
91
+ # [-0.2232, 0.0019, 0.0140, ..., 0.4461, -0.0233, 0.0735],
92
+ # ...,
93
+ ```
94
+
95
+
96
+ ## Authors
97
+
98
+ 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.
99
+
100
+
101
+ ## Citation
102
+ If you use our work, please cite:
103
+
104
+ ```bibtex
105
+ @inproceedings{martin2020camembert,
106
+ title={CamemBERT: a Tasty French Language Model},
107
+ 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},
108
+ booktitle={Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics},
109
+ year={2020}
110
+ }
111
+ ```