lysandre HF staff commited on
Commit
a1e0407
1 Parent(s): 7fd236f

Create ALBERT readme

Browse files
Files changed (1) hide show
  1. README.md +261 -0
README.md ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: apache-2.0
4
+ datasets:
5
+ - bookcorpus
6
+ - wikipedia
7
+ ---
8
+
9
+ # ALBERT Base v2
10
+
11
+ Pretrained model on English language using a masked language modeling (MLM) objective. It was introduced in
12
+ [this paper](https://arxiv.org/abs/1909.11942) and first released in
13
+ [this repository](https://github.com/google-research/albert). This model, as all ALBERT models, is uncased: it does not make a difference
14
+ between english and English.
15
+
16
+ Disclaimer: The team releasing ALBERT did not write a model card for this model so this model card has been written by
17
+ the Hugging Face team.
18
+
19
+ ## Model description
20
+
21
+ ALBERT is a transformers model pretrained on a large corpus of English data in a self-supervised fashion. This means it
22
+ was pretrained on the raw texts only, with no humans labelling them in any way (which is why it can use lots of
23
+ publicly available data) with an automatic process to generate inputs and labels from those texts. More precisely, it
24
+ was pretrained with two objectives:
25
+
26
+ - Masked language modeling (MLM): taking a sentence, the model randomly masks 15% of the words in the input then run
27
+ the entire masked sentence through the model and has to predict the masked words. This is different from traditional
28
+ recurrent neural networks (RNNs) that usually see the words one after the other, or from autoregressive models like
29
+ GPT which internally mask the future tokens. It allows the model to learn a bidirectional representation of the
30
+ sentence.
31
+ - Sentence Ordering Prediction (SOP): ALBERT uses a pretraining loss based on predicting the ordering of two consecutive segments of text.
32
+
33
+ This way, the model learns an inner representation of the English language that can then be used to extract features
34
+ useful for downstream tasks: if you have a dataset of labeled sentences for instance, you can train a standard
35
+ classifier using the features produced by the ALBERT model as inputs.
36
+
37
+ ALBERT is particular in that it shares its layers across its Transformer. Therefore, all layers have the same weights. Using repeating layers results in a small memory footprint, however, the computational cost remains similar to a BERT-like architecture with the same number of hidden layers as it has to iterate through the same number of (repeating) layers.
38
+
39
+ ## Intended uses & limitations
40
+
41
+ You can use the raw model for either masked language modeling or next sentence prediction, but it's mostly intended to
42
+ be fine-tuned on a downstream task. See the [model hub](https://huggingface.co/models?filter=albert) to look for
43
+ fine-tuned versions on a task that interests you.
44
+
45
+ Note that this model is primarily aimed at being fine-tuned on tasks that use the whole sentence (potentially masked)
46
+ to make decisions, such as sequence classification, token classification or question answering. For tasks such as text
47
+ generation you should look at model like GPT2.
48
+
49
+ ### How to use
50
+
51
+ You can use this model directly with a pipeline for masked language modeling:
52
+
53
+ ```python
54
+ >>> from transformers import pipeline
55
+ >>> unmasker = pipeline('fill-mask', model='albert-base-v2')
56
+ >>> unmasker("Hello I'm a [MASK] model.")
57
+ [
58
+ {
59
+ "sequence":"[CLS] hello i'm a modeling model.[SEP]",
60
+ "score":0.05816134437918663,
61
+ "token":12807,
62
+ "token_str":"▁modeling"
63
+ },
64
+ {
65
+ "sequence":"[CLS] hello i'm a modelling model.[SEP]",
66
+ "score":0.03748830780386925,
67
+ "token":23089,
68
+ "token_str":"▁modelling"
69
+ },
70
+ {
71
+ "sequence":"[CLS] hello i'm a model model.[SEP]",
72
+ "score":0.033725276589393616,
73
+ "token":1061,
74
+ "token_str":"▁model"
75
+ },
76
+ {
77
+ "sequence":"[CLS] hello i'm a runway model.[SEP]",
78
+ "score":0.017313428223133087,
79
+ "token":8014,
80
+ "token_str":"▁runway"
81
+ },
82
+ {
83
+ "sequence":"[CLS] hello i'm a lingerie model.[SEP]",
84
+ "score":0.014405295252799988,
85
+ "token":29104,
86
+ "token_str":"▁lingerie"
87
+ }
88
+ ]
89
+ ```
90
+
91
+ Here is how to use this model to get the features of a given text in PyTorch:
92
+
93
+ ```python
94
+ from transformers import AlbertTokenizer, AlbertModel
95
+ tokenizer = AlbertTokenizer.from_pretrained('albert-base-v2')
96
+ model = AlbertModel.from_pretrained("albert-base-v2")
97
+ text = "Replace me by any text you'd like."
98
+ encoded_input = tokenizer(text, return_tensors='pt')
99
+ output = model(**encoded_input)
100
+ ```
101
+
102
+ and in TensorFlow:
103
+
104
+ ```python
105
+ from transformers import AlbertTokenizer, TFAlbertModel
106
+ tokenizer = AlbertTokenizer.from_pretrained('albert-base-v2'')
107
+ model = TFAlbertModel.from_pretrained("albert-base-v2)
108
+ text = "Replace me by any text you'd like."
109
+ encoded_input = tokenizer(text, return_tensors='tf')
110
+ output = model(encoded_input)
111
+ ```
112
+
113
+ ### Limitations and bias
114
+
115
+ Even if the training data used for this model could be characterized as fairly neutral, this model can have biased
116
+ predictions:
117
+
118
+ ```python
119
+ >>> from transformers import pipeline
120
+ >>> unmasker = pipeline('fill-mask', model='albert-base-v2')
121
+ >>> unmasker("The man worked as a [MASK].")
122
+
123
+ [
124
+ {
125
+ "sequence":"[CLS] the man worked as a chauffeur.[SEP]",
126
+ "score":0.029577180743217468,
127
+ "token":28744,
128
+ "token_str":"▁chauffeur"
129
+ },
130
+ {
131
+ "sequence":"[CLS] the man worked as a janitor.[SEP]",
132
+ "score":0.028865724802017212,
133
+ "token":29477,
134
+ "token_str":"▁janitor"
135
+ },
136
+ {
137
+ "sequence":"[CLS] the man worked as a shoemaker.[SEP]",
138
+ "score":0.02581118606030941,
139
+ "token":29024,
140
+ "token_str":"▁shoemaker"
141
+ },
142
+ {
143
+ "sequence":"[CLS] the man worked as a blacksmith.[SEP]",
144
+ "score":0.01849772222340107,
145
+ "token":21238,
146
+ "token_str":"▁blacksmith"
147
+ },
148
+ {
149
+ "sequence":"[CLS] the man worked as a lawyer.[SEP]",
150
+ "score":0.01820771023631096,
151
+ "token":3672,
152
+ "token_str":"▁lawyer"
153
+ }
154
+ ]
155
+
156
+ >>> unmasker("The woman worked as a [MASK].")
157
+
158
+ [
159
+ {
160
+ "sequence":"[CLS] the woman worked as a receptionist.[SEP]",
161
+ "score":0.04604868218302727,
162
+ "token":25331,
163
+ "token_str":"▁receptionist"
164
+ },
165
+ {
166
+ "sequence":"[CLS] the woman worked as a janitor.[SEP]",
167
+ "score":0.028220869600772858,
168
+ "token":29477,
169
+ "token_str":"▁janitor"
170
+ },
171
+ {
172
+ "sequence":"[CLS] the woman worked as a paramedic.[SEP]",
173
+ "score":0.0261906236410141,
174
+ "token":23386,
175
+ "token_str":"▁paramedic"
176
+ },
177
+ {
178
+ "sequence":"[CLS] the woman worked as a chauffeur.[SEP]",
179
+ "score":0.024797942489385605,
180
+ "token":28744,
181
+ "token_str":"▁chauffeur"
182
+ },
183
+ {
184
+ "sequence":"[CLS] the woman worked as a waitress.[SEP]",
185
+ "score":0.024124596267938614,
186
+ "token":13678,
187
+ "token_str":"▁waitress"
188
+ }
189
+ ]
190
+ ```
191
+
192
+ This bias will also affect all fine-tuned versions of this model.
193
+
194
+ ## Training data
195
+
196
+ The ALBERT model was pretrained on [BookCorpus](https://yknzhu.wixsite.com/mbweb), a dataset consisting of 11,038
197
+ unpublished books and [English Wikipedia](https://en.wikipedia.org/wiki/English_Wikipedia) (excluding lists, tables and
198
+ headers).
199
+
200
+ ## Training procedure
201
+
202
+ ### Preprocessing
203
+
204
+ The texts are lowercased and tokenized using SentencePiece and a vocabulary size of 30,000. The inputs of the model are
205
+ then of the form:
206
+
207
+ ```
208
+ [CLS] Sentence A [SEP] Sentence B [SEP]
209
+ ```
210
+
211
+ ### Training
212
+
213
+ The ALBERT procedure follows the BERT setup.
214
+
215
+ The details of the masking procedure for each sentence are the following:
216
+ - 15% of the tokens are masked.
217
+ - In 80% of the cases, the masked tokens are replaced by `[MASK]`.
218
+ - In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
219
+ - In the 10% remaining cases, the masked tokens are left as is.
220
+
221
+ ## Evaluation results
222
+
223
+ When fine-tuned on downstream tasks, the ALBERT models achieve the following results:
224
+
225
+ | | Average | SQuAD1.1 | SQuAD2.0 | MNLI | SST-2 | RACE |
226
+ |----------------|----------|----------|----------|----------|----------|----------|
227
+ |V2 |
228
+ |ALBERT-base |82.3 |90.2/83.2 |82.1/79.3 |84.6 |92.9 |66.8 |
229
+ |ALBERT-large |85.7 |91.8/85.2 |84.9/81.8 |86.5 |94.9 |75.2 |
230
+ |ALBERT-xlarge |87.9 |92.9/86.4 |87.9/84.1 |87.9 |95.4 |80.7 |
231
+ |ALBERT-xxlarge |90.9 |94.6/89.1 |89.8/86.9 |90.6 |96.8 |86.8 |
232
+ |V1 |
233
+ |ALBERT-base |80.1 |89.3/82.3 | 80.0/77.1|81.6 |90.3 | 64.0 |
234
+ |ALBERT-large |82.4 |90.6/83.9 | 82.3/79.4|83.5 |91.7 | 68.5 |
235
+ |ALBERT-xlarge |85.5 |92.5/86.1 | 86.1/83.1|86.4 |92.4 | 74.8 |
236
+ |ALBERT-xxlarge |91.0 |94.8/89.3 | 90.2/87.4|90.8 |96.9 | 86.5 |
237
+
238
+
239
+ ### BibTeX entry and citation info
240
+
241
+ ```bibtex
242
+ @article{DBLP:journals/corr/abs-1909-11942,
243
+ author = {Zhenzhong Lan and
244
+ Mingda Chen and
245
+ Sebastian Goodman and
246
+ Kevin Gimpel and
247
+ Piyush Sharma and
248
+ Radu Soricut},
249
+ title = {{ALBERT:} {A} Lite {BERT} for Self-supervised Learning of Language
250
+ Representations},
251
+ journal = {CoRR},
252
+ volume = {abs/1909.11942},
253
+ year = {2019},
254
+ url = {http://arxiv.org/abs/1909.11942},
255
+ archivePrefix = {arXiv},
256
+ eprint = {1909.11942},
257
+ timestamp = {Fri, 27 Sep 2019 13:04:21 +0200},
258
+ biburl = {https://dblp.org/rec/journals/corr/abs-1909-11942.bib},
259
+ bibsource = {dblp computer science bibliography, https://dblp.org}
260
+ }
261
+ ```