prithivMLmods
commited on
Commit
•
37dc1d2
1
Parent(s):
c5ff478
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,195 @@
|
|
1 |
-
---
|
2 |
-
license: creativeml-openrail-m
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: creativeml-openrail-m
|
3 |
+
---
|
4 |
+
|
5 |
+
# BERT base model (uncased)
|
6 |
+
image
|
7 |
+
|
8 |
+
## Model description
|
9 |
+
|
10 |
+
BERT is a transformers model pretrained on a large corpus of English data in a self-supervised fashion. This means it
|
11 |
+
was pretrained on the raw texts only, with no humans labeling them in any way (which is why it can use lots of
|
12 |
+
publicly available data) with an automatic process to generate inputs and labels from those texts. More precisely, it
|
13 |
+
was pretrained with two objectives:
|
14 |
+
|
15 |
+
- Masked language modeling (MLM): taking a sentence, the model randomly masks 15% of the words in the input then run
|
16 |
+
the entire masked sentence through the model and has to predict the masked words. This is different from traditional
|
17 |
+
recurrent neural networks (RNNs) that usually see the words one after the other, or from autoregressive models like
|
18 |
+
GPT which internally masks the future tokens. It allows the model to learn a bidirectional representation of the
|
19 |
+
sentence.
|
20 |
+
- Next sentence prediction (NSP): the models concatenates two masked sentences as inputs during pretraining. Sometimes
|
21 |
+
they correspond to sentences that were next to each other in the original text, sometimes not. The model then has to
|
22 |
+
predict if the two sentences were following each other or not.
|
23 |
+
|
24 |
+
This way, the model learns an inner representation of the English language that can then be used to extract features
|
25 |
+
useful for downstream tasks: if you have a dataset of labeled sentences, for instance, you can train a standard
|
26 |
+
classifier using the features produced by the BERT model as inputs.
|
27 |
+
|
28 |
+
## Model variations
|
29 |
+
|
30 |
+
BERT has originally been released in base and large variations, for cased and uncased input text. The uncased models also strips out an accent markers.
|
31 |
+
Chinese and multilingual uncased and cased versions followed shortly after.
|
32 |
+
Modified preprocessing with whole word masking has replaced subpiece masking in a following work, with the release of two models.
|
33 |
+
Other 24 smaller models are released afterward.
|
34 |
+
|
35 |
+
## Intended uses & limitations
|
36 |
+
|
37 |
+
You can use the raw model for either masked language modeling or next sentence prediction, but it's mostly intended to
|
38 |
+
be fine-tuned on a downstream task. See the [model hub](https://huggingface.co/models?filter=bert) to look for
|
39 |
+
fine-tuned versions of a task that interests you.
|
40 |
+
|
41 |
+
Note that this model is primarily aimed at being fine-tuned on tasks that use the whole sentence (potentially masked)
|
42 |
+
to make decisions, such as sequence classification, token classification or question answering. For tasks such as text
|
43 |
+
generation you should look at model like GPT2.
|
44 |
+
|
45 |
+
### How to use
|
46 |
+
|
47 |
+
You can use this model directly with a pipeline for masked language modeling:
|
48 |
+
|
49 |
+
```python
|
50 |
+
>>> from transformers import pipeline
|
51 |
+
>>> unmasker = pipeline('fill-mask', model='prithivMLmods/Betelgeuse-bert-base-uncased')
|
52 |
+
>>> unmasker("Hello I'm a [MASK] model.")
|
53 |
+
|
54 |
+
[{'sequence': "[CLS] hello i'm a fashion model. [SEP]",
|
55 |
+
'score': 0.1073106899857521,
|
56 |
+
'token': 4827,
|
57 |
+
'token_str': 'fashion'},
|
58 |
+
{'sequence': "[CLS] hello i'm a role model. [SEP]",
|
59 |
+
'score': 0.08774490654468536,
|
60 |
+
'token': 2535,
|
61 |
+
'token_str': 'role'},
|
62 |
+
{'sequence': "[CLS] hello i'm a new model. [SEP]",
|
63 |
+
'score': 0.05338378623127937,
|
64 |
+
'token': 2047,
|
65 |
+
'token_str': 'new'},
|
66 |
+
{'sequence': "[CLS] hello i'm a super model. [SEP]",
|
67 |
+
'score': 0.04667217284440994,
|
68 |
+
'token': 3565,
|
69 |
+
'token_str': 'super'},
|
70 |
+
{'sequence': "[CLS] hello i'm a fine model. [SEP]",
|
71 |
+
'score': 0.027095865458250046,
|
72 |
+
'token': 2986,
|
73 |
+
'token_str': 'fine'}]
|
74 |
+
```
|
75 |
+
|
76 |
+
Here is how to use this model to get the features of a given text in PyTorch:
|
77 |
+
|
78 |
+
```python
|
79 |
+
from transformers import BertTokenizer, BertModel
|
80 |
+
tokenizer = BertTokenizer.from_pretrained('prithivMLmods/Betelgeuse-bert-base-uncased')
|
81 |
+
model = BertModel.from_pretrained("prithivMLmods/Betelgeuse-bert-base-uncased")
|
82 |
+
text = "Replace me by any text you'd like."
|
83 |
+
encoded_input = tokenizer(text, return_tensors='pt')
|
84 |
+
output = model(**encoded_input)
|
85 |
+
```
|
86 |
+
|
87 |
+
and in TensorFlow:
|
88 |
+
|
89 |
+
```python
|
90 |
+
from transformers import BertTokenizer, TFBertModel
|
91 |
+
tokenizer = BertTokenizer.from_pretrained('prithivMLmods/Betelgeuse-bert-base-uncased')
|
92 |
+
model = TFBertModel.from_pretrained("prithivMLmods/Betelgeuse-bert-base-uncased")
|
93 |
+
text = "Replace me by any text you'd like."
|
94 |
+
encoded_input = tokenizer(text, return_tensors='tf')
|
95 |
+
output = model(encoded_input)
|
96 |
+
```
|
97 |
+
|
98 |
+
### Limitations and bias
|
99 |
+
|
100 |
+
Even if the training data used for this model could be characterized as fairly neutral, this model can have biased
|
101 |
+
predictions:
|
102 |
+
|
103 |
+
```python
|
104 |
+
>>> from transformers import pipeline
|
105 |
+
>>> unmasker = pipeline('fill-mask', model='prithivMLmods/Betelgeuse-bert-base-uncased')
|
106 |
+
>>> unmasker("The man worked as a [MASK].")
|
107 |
+
|
108 |
+
[{'sequence': '[CLS] the man worked as a carpenter. [SEP]',
|
109 |
+
'score': 0.09747550636529922,
|
110 |
+
'token': 10533,
|
111 |
+
'token_str': 'carpenter'},
|
112 |
+
{'sequence': '[CLS] the man worked as a waiter. [SEP]',
|
113 |
+
'score': 0.0523831807076931,
|
114 |
+
'token': 15610,
|
115 |
+
'token_str': 'waiter'},
|
116 |
+
{'sequence': '[CLS] the man worked as a barber. [SEP]',
|
117 |
+
'score': 0.04962705448269844,
|
118 |
+
'token': 13362,
|
119 |
+
'token_str': 'barber'},
|
120 |
+
{'sequence': '[CLS] the man worked as a mechanic. [SEP]',
|
121 |
+
'score': 0.03788609802722931,
|
122 |
+
'token': 15893,
|
123 |
+
'token_str': 'mechanic'},
|
124 |
+
{'sequence': '[CLS] the man worked as a salesman. [SEP]',
|
125 |
+
'score': 0.037680890411138535,
|
126 |
+
'token': 18968,
|
127 |
+
'token_str': 'salesman'}]
|
128 |
+
|
129 |
+
>>> unmasker("The woman worked as a [MASK].")
|
130 |
+
|
131 |
+
[{'sequence': '[CLS] the woman worked as a nurse. [SEP]',
|
132 |
+
'score': 0.21981462836265564,
|
133 |
+
'token': 6821,
|
134 |
+
'token_str': 'nurse'},
|
135 |
+
{'sequence': '[CLS] the woman worked as a waitress. [SEP]',
|
136 |
+
'score': 0.1597415804862976,
|
137 |
+
'token': 13877,
|
138 |
+
'token_str': 'waitress'},
|
139 |
+
{'sequence': '[CLS] the woman worked as a maid. [SEP]',
|
140 |
+
'score': 0.1154729500412941,
|
141 |
+
'token': 10850,
|
142 |
+
'token_str': 'maid'},
|
143 |
+
{'sequence': '[CLS] the woman worked as a prostitute. [SEP]',
|
144 |
+
'score': 0.037968918681144714,
|
145 |
+
'token': 19215,
|
146 |
+
'token_str': 'prostitute'},
|
147 |
+
{'sequence': '[CLS] the woman worked as a cook. [SEP]',
|
148 |
+
'score': 0.03042375110089779,
|
149 |
+
'token': 5660,
|
150 |
+
'token_str': 'cook'}]
|
151 |
+
```
|
152 |
+
|
153 |
+
This bias will also affect all fine-tuned versions of this model.
|
154 |
+
|
155 |
+
## Training data
|
156 |
+
|
157 |
+
## Training procedure
|
158 |
+
|
159 |
+
### Preprocessing
|
160 |
+
|
161 |
+
The texts are lowercased and tokenized using WordPiece and a vocabulary size of 30,000. The inputs of the model are
|
162 |
+
then of the form:
|
163 |
+
|
164 |
+
```
|
165 |
+
[CLS] Sentence A [SEP] Sentence B [SEP]
|
166 |
+
```
|
167 |
+
|
168 |
+
With probability 0.5, sentence A and sentence B correspond to two consecutive sentences in the original corpus, and in
|
169 |
+
the other cases, it's another random sentence in the corpus. Note that what is considered a sentence here is a
|
170 |
+
consecutive span of text usually longer than a single sentence. The only constrain is that the result with the two
|
171 |
+
"sentences" has a combined length of less than 512 tokens.
|
172 |
+
|
173 |
+
The details of the masking procedure for each sentence are the following:
|
174 |
+
- 15% of the tokens are masked.
|
175 |
+
- In 80% of the cases, the masked tokens are replaced by `[MASK]`.
|
176 |
+
- In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
|
177 |
+
- In the 10% remaining cases, the masked tokens are left as is.
|
178 |
+
|
179 |
+
### Pretraining
|
180 |
+
|
181 |
+
The model was trained on 4 cloud TPUs in Pod configuration (16 TPU chips total) for one million steps with a batch size
|
182 |
+
of 256. The sequence length was limited to 128 tokens for 90% of the steps and 512 for the remaining 10%. The optimizer
|
183 |
+
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,
|
184 |
+
learning rate warmup for 10,000 steps and linear decay of the learning rate after.
|
185 |
+
|
186 |
+
## Evaluation results
|
187 |
+
|
188 |
+
When fine-tuned on downstream tasks, this model achieves the following results:
|
189 |
+
|
190 |
+
Glue test results:
|
191 |
+
|
192 |
+
| Task | MNLI-(m/mm) | QQP | QNLI | SST-2 | CoLA | STS-B | MRPC | RTE | Average |
|
193 |
+
|:----:|:-----------:|:----:|:----:|:-----:|:----:|:-----:|:----:|:----:|:-------:|
|
194 |
+
| | 84.6/83.4 | 71.2 | 90.5 | 93.5 | 52.1 | 85.8 | 88.9 | 66.4 | 79.6 |
|
195 |
+
|