julien-c HF staff commited on
Commit
df7dbf5
1 Parent(s): 19b6f72

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-large/README.md

Files changed (1) hide show
  1. README.md +110 -0
README.md ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-large")
34
+ camembert = CamembertModel.from_pretrained("camembert/camembert-large")
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-large", tokenizer="camembert/camembert-large")
45
+ results = camembert_fill_mask("Le camembert est <mask> :)")
46
+ # results
47
+ #[{'sequence': '<s> Le camembert est bon :)</s>', 'score': 0.15560828149318695, 'token': 305},
48
+ #{'sequence': '<s> Le camembert est excellent :)</s>', 'score': 0.06821336597204208, 'token': 3497},
49
+ #{'sequence': '<s> Le camembert est délicieux :)</s>', 'score': 0.060438305139541626, 'token': 11661},
50
+ #{'sequence': '<s> Le camembert est ici :)</s>', 'score': 0.02023460529744625, 'token': 373},
51
+ #{'sequence': '<s> Le camembert est meilleur :)</s>', 'score': 0.01778135634958744, 'token': 876}]
52
+ ```
53
+
54
+ ##### Extract contextual embedding features from Camembert output
55
+ ```python
56
+ import torch
57
+ # Tokenize in sub-words with SentencePiece
58
+ tokenized_sentence = tokenizer.tokenize("J'aime le camembert !")
59
+ # ['▁J', "'", 'aime', '▁le', '▁cam', 'ember', 't', '▁!']
60
+
61
+ # 1-hot encode and add special starting and end tokens
62
+ encoded_sentence = tokenizer.encode(tokenized_sentence)
63
+ # [5, 133, 22, 1250, 16, 12034, 14324, 81, 76, 6]
64
+ # NB: Can be done in one step : tokenize.encode("J'aime le camembert !")
65
+
66
+ # Feed tokens to Camembert as a torch tensor (batch dim 1)
67
+ encoded_sentence = torch.tensor(encoded_sentence).unsqueeze(0)
68
+ embeddings, _ = camembert(encoded_sentence)
69
+ # embeddings.detach()
70
+ # torch.Size([1, 10, 1024])
71
+ #tensor([[[-0.1284, 0.2643, 0.4374, ..., 0.1627, 0.1308, -0.2305],
72
+ # [ 0.4576, -0.6345, -0.2029, ..., -0.1359, -0.2290, -0.6318],
73
+ # [ 0.0381, 0.0429, 0.5111, ..., -0.1177, -0.1913, -0.1121],
74
+ # ...,
75
+ ```
76
+
77
+ ##### Extract contextual embedding features from all Camembert layers
78
+ ```python
79
+ from transformers import CamembertConfig
80
+ # (Need to reload the model with new config)
81
+ config = CamembertConfig.from_pretrained("camembert/camembert-large", output_hidden_states=True)
82
+ camembert = CamembertModel.from_pretrained("camembert/camembert-large", config=config)
83
+
84
+ embeddings, _, all_layer_embeddings = camembert(encoded_sentence)
85
+ # all_layer_embeddings list of len(all_layer_embeddings) == 25 (input embedding layer + 24 self attention layers)
86
+ all_layer_embeddings[5]
87
+ # layer 5 contextual embedding : size torch.Size([1, 10, 1024])
88
+ #tensor([[[-0.0600, 0.0742, 0.0332, ..., -0.0525, -0.0637, -0.0287],
89
+ # [ 0.0950, 0.2840, 0.1985, ..., 0.2073, -0.2172, -0.6321],
90
+ # [ 0.1381, 0.1872, 0.1614, ..., -0.0339, -0.2530, -0.1182],
91
+ # ...,
92
+ ```
93
+
94
+
95
+ ## Authors
96
+
97
+ 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.
98
+
99
+
100
+ ## Citation
101
+ If you use our work, please cite:
102
+
103
+ ```bibtex
104
+ @inproceedings{martin2020camembert,
105
+ title={CamemBERT: a Tasty French Language Model},
106
+ 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},
107
+ booktitle={Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics},
108
+ year={2020}
109
+ }
110
+ ```