prithivMLmods commited on
Commit
b3ca0a9
·
verified ·
1 Parent(s): c0967b5

Create README.md

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