Transformers
ONNX
English
bert
exbert
phlippseitz commited on
Commit
0106a7d
1 Parent(s): 8a679e4

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +232 -0
README.md ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ inference: false
4
+ tags:
5
+ - onnx
6
+ - exbert
7
+ license: apache-2.0
8
+ datasets:
9
+ - bookcorpus
10
+ - wikipedia
11
+ ---
12
+
13
+ # ONNX export of bert-base-cased
14
+
15
+ Pretrained model on English language using a masked language modeling (MLM) objective. It was introduced in
16
+ [this paper](https://arxiv.org/abs/1810.04805) and first released in
17
+ [this repository](https://github.com/google-research/bert). This model is case-sensitive: it makes a difference between
18
+ english and English.
19
+
20
+ Disclaimer: The team releasing BERT did not write a model card for this model so this model card has been written by
21
+ the Hugging Face team.
22
+
23
+ ## Model description
24
+
25
+ BERT is a transformers model pretrained on a large corpus of English data in a self-supervised fashion. This means it
26
+ was pretrained on the raw texts only, with no humans labelling them in any way (which is why it can use lots of
27
+ publicly available data) with an automatic process to generate inputs and labels from those texts. More precisely, it
28
+ was pretrained with two objectives:
29
+
30
+ - Masked language modeling (MLM): taking a sentence, the model randomly masks 15% of the words in the input then run
31
+ the entire masked sentence through the model and has to predict the masked words. This is different from traditional
32
+ recurrent neural networks (RNNs) that usually see the words one after the other, or from autoregressive models like
33
+ GPT which internally mask the future tokens. It allows the model to learn a bidirectional representation of the
34
+ sentence.
35
+ - Next sentence prediction (NSP): the models concatenates two masked sentences as inputs during pretraining. Sometimes
36
+ they correspond to sentences that were next to each other in the original text, sometimes not. The model then has to
37
+ predict if the two sentences were following each other or not.
38
+
39
+ This way, the model learns an inner representation of the English language that can then be used to extract features
40
+ useful for downstream tasks: if you have a dataset of labeled sentences for instance, you can train a standard
41
+ classifier using the features produced by the BERT model as inputs.
42
+
43
+ ## Intended uses & limitations
44
+
45
+ You can use the raw model for either masked language modeling or next sentence prediction, but it's mostly intended to
46
+ be fine-tuned on a downstream task. See the [model hub](https://huggingface.co/models?filter=bert) to look for
47
+ fine-tuned versions on a task that interests you.
48
+
49
+ Note that this model is primarily aimed at being fine-tuned on tasks that use the whole sentence (potentially masked)
50
+ to make decisions, such as sequence classification, token classification or question answering. For tasks such as text
51
+ generation you should look at model like GPT2.
52
+
53
+ ### How to use
54
+
55
+ You can use this model directly with a pipeline for masked language modeling:
56
+
57
+ ```python
58
+ >>> from transformers import pipeline
59
+ >>> unmasker = pipeline('fill-mask', model='bert-base-cased')
60
+ >>> unmasker("Hello I'm a [MASK] model.")
61
+
62
+ [{'sequence': "[CLS] Hello I'm a fashion model. [SEP]",
63
+ 'score': 0.09019174426794052,
64
+ 'token': 4633,
65
+ 'token_str': 'fashion'},
66
+ {'sequence': "[CLS] Hello I'm a new model. [SEP]",
67
+ 'score': 0.06349995732307434,
68
+ 'token': 1207,
69
+ 'token_str': 'new'},
70
+ {'sequence': "[CLS] Hello I'm a male model. [SEP]",
71
+ 'score': 0.06228214129805565,
72
+ 'token': 2581,
73
+ 'token_str': 'male'},
74
+ {'sequence': "[CLS] Hello I'm a professional model. [SEP]",
75
+ 'score': 0.0441727414727211,
76
+ 'token': 1848,
77
+ 'token_str': 'professional'},
78
+ {'sequence': "[CLS] Hello I'm a super model. [SEP]",
79
+ 'score': 0.03326151892542839,
80
+ 'token': 7688,
81
+ 'token_str': 'super'}]
82
+ ```
83
+
84
+ Here is how to use this model to get the features of a given text in PyTorch:
85
+
86
+ ```python
87
+ from transformers import BertTokenizer, BertModel
88
+ tokenizer = BertTokenizer.from_pretrained('bert-base-cased')
89
+ model = BertModel.from_pretrained("bert-base-cased")
90
+ text = "Replace me by any text you'd like."
91
+ encoded_input = tokenizer(text, return_tensors='pt')
92
+ output = model(**encoded_input)
93
+ ```
94
+
95
+ and in TensorFlow:
96
+
97
+ ```python
98
+ from transformers import BertTokenizer, TFBertModel
99
+ tokenizer = BertTokenizer.from_pretrained('bert-base-cased')
100
+ model = TFBertModel.from_pretrained("bert-base-cased")
101
+ text = "Replace me by any text you'd like."
102
+ encoded_input = tokenizer(text, return_tensors='tf')
103
+ output = model(encoded_input)
104
+ ```
105
+
106
+ ### Limitations and bias
107
+
108
+ Even if the training data used for this model could be characterized as fairly neutral, this model can have biased
109
+ predictions:
110
+
111
+ ```python
112
+ >>> from transformers import pipeline
113
+ >>> unmasker = pipeline('fill-mask', model='bert-base-cased')
114
+ >>> unmasker("The man worked as a [MASK].")
115
+
116
+ [{'sequence': '[CLS] The man worked as a lawyer. [SEP]',
117
+ 'score': 0.04804691672325134,
118
+ 'token': 4545,
119
+ 'token_str': 'lawyer'},
120
+ {'sequence': '[CLS] The man worked as a waiter. [SEP]',
121
+ 'score': 0.037494491785764694,
122
+ 'token': 17989,
123
+ 'token_str': 'waiter'},
124
+ {'sequence': '[CLS] The man worked as a cop. [SEP]',
125
+ 'score': 0.035512614995241165,
126
+ 'token': 9947,
127
+ 'token_str': 'cop'},
128
+ {'sequence': '[CLS] The man worked as a detective. [SEP]',
129
+ 'score': 0.031271643936634064,
130
+ 'token': 9140,
131
+ 'token_str': 'detective'},
132
+ {'sequence': '[CLS] The man worked as a doctor. [SEP]',
133
+ 'score': 0.027423162013292313,
134
+ 'token': 3995,
135
+ 'token_str': 'doctor'}]
136
+
137
+ >>> unmasker("The woman worked as a [MASK].")
138
+
139
+ [{'sequence': '[CLS] The woman worked as a nurse. [SEP]',
140
+ 'score': 0.16927455365657806,
141
+ 'token': 7439,
142
+ 'token_str': 'nurse'},
143
+ {'sequence': '[CLS] The woman worked as a waitress. [SEP]',
144
+ 'score': 0.1501094549894333,
145
+ 'token': 15098,
146
+ 'token_str': 'waitress'},
147
+ {'sequence': '[CLS] The woman worked as a maid. [SEP]',
148
+ 'score': 0.05600163713097572,
149
+ 'token': 13487,
150
+ 'token_str': 'maid'},
151
+ {'sequence': '[CLS] The woman worked as a housekeeper. [SEP]',
152
+ 'score': 0.04838843643665314,
153
+ 'token': 26458,
154
+ 'token_str': 'housekeeper'},
155
+ {'sequence': '[CLS] The woman worked as a cook. [SEP]',
156
+ 'score': 0.029980547726154327,
157
+ 'token': 9834,
158
+ 'token_str': 'cook'}]
159
+ ```
160
+
161
+ This bias will also affect all fine-tuned versions of this model.
162
+
163
+ ## Training data
164
+
165
+ The BERT model was pretrained on [BookCorpus](https://yknzhu.wixsite.com/mbweb), a dataset consisting of 11,038
166
+ unpublished books and [English Wikipedia](https://en.wikipedia.org/wiki/English_Wikipedia) (excluding lists, tables and
167
+ headers).
168
+
169
+ ## Training procedure
170
+
171
+ ### Preprocessing
172
+
173
+ The texts are tokenized using WordPiece and a vocabulary size of 30,000. The inputs of the model are then of the form:
174
+
175
+ ```
176
+ [CLS] Sentence A [SEP] Sentence B [SEP]
177
+ ```
178
+
179
+ With probability 0.5, sentence A and sentence B correspond to two consecutive sentences in the original corpus and in
180
+ the other cases, it's another random sentence in the corpus. Note that what is considered a sentence here is a
181
+ consecutive span of text usually longer than a single sentence. The only constrain is that the result with the two
182
+ "sentences" has a combined length of less than 512 tokens.
183
+
184
+ The details of the masking procedure for each sentence are the following:
185
+ - 15% of the tokens are masked.
186
+ - In 80% of the cases, the masked tokens are replaced by `[MASK]`.
187
+ - In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
188
+ - In the 10% remaining cases, the masked tokens are left as is.
189
+
190
+ ### Pretraining
191
+
192
+ The model was trained on 4 cloud TPUs in Pod configuration (16 TPU chips total) for one million steps with a batch size
193
+ of 256. The sequence length was limited to 128 tokens for 90% of the steps and 512 for the remaining 10%. The optimizer
194
+ used is Adam with a learning rate of 1e-4, \\(\beta_{1} = 0.9\\) and \\(\beta_{2} = 0.999\\), a weight decay of 0.01,
195
+ learning rate warmup for 10,000 steps and linear decay of the learning rate after.
196
+
197
+ ## Evaluation results
198
+
199
+ When fine-tuned on downstream tasks, this model achieves the following results:
200
+
201
+ Glue test results:
202
+
203
+ | Task | MNLI-(m/mm) | QQP | QNLI | SST-2 | CoLA | STS-B | MRPC | RTE | Average |
204
+ |:----:|:-----------:|:----:|:----:|:-----:|:----:|:-----:|:----:|:----:|:-------:|
205
+ | | 84.6/83.4 | 71.2 | 90.5 | 93.5 | 52.1 | 85.8 | 88.9 | 66.4 | 79.6 |
206
+
207
+
208
+ ### BibTeX entry and citation info
209
+
210
+ ```bibtex
211
+ @article{DBLP:journals/corr/abs-1810-04805,
212
+ author = {Jacob Devlin and
213
+ Ming{-}Wei Chang and
214
+ Kenton Lee and
215
+ Kristina Toutanova},
216
+ title = {{BERT:} Pre-training of Deep Bidirectional Transformers for Language
217
+ Understanding},
218
+ journal = {CoRR},
219
+ volume = {abs/1810.04805},
220
+ year = {2018},
221
+ url = {http://arxiv.org/abs/1810.04805},
222
+ archivePrefix = {arXiv},
223
+ eprint = {1810.04805},
224
+ timestamp = {Tue, 30 Oct 2018 20:39:56 +0100},
225
+ biburl = {https://dblp.org/rec/journals/corr/abs-1810-04805.bib},
226
+ bibsource = {dblp computer science bibliography, https://dblp.org}
227
+ }
228
+ ```
229
+
230
+ <a href="https://huggingface.co/exbert/?model=bert-base-cased">
231
+ <img width="300px" src="https://cdn-media.huggingface.co/exbert/button.png">
232
+ </a>