Shivam22182 commited on
Commit
a1beb09
1 Parent(s): e12c8ac

Update README.md

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