bert-base-uncased for teachable-nlp
Browse files- README.md +233 -0
- config.json +23 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +1 -0
- tokenizer.json +0 -0
- tokenizer_config.json +1 -0
README.md
ADDED
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: en
|
3 |
+
tags:
|
4 |
+
- exbert
|
5 |
+
license: apache-2.0
|
6 |
+
datasets:
|
7 |
+
- bookcorpus
|
8 |
+
- wikipedia
|
9 |
+
---
|
10 |
+
|
11 |
+
# BERT base model (uncased) for Teachable NLP
|
12 |
+
|
13 |
+
- This model forked from [bert-base-uncased](https://huggingface.co/bert-base-uncased) for fine tune [Teachable NLP](https://ainize.ai/teachable-nlp).
|
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 uncased: it does not make a difference
|
18 |
+
between 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-uncased')
|
60 |
+
>>> unmasker("Hello I'm a [MASK] model.")
|
61 |
+
|
62 |
+
[{'sequence': "[CLS] hello i'm a fashion model. [SEP]",
|
63 |
+
'score': 0.1073106899857521,
|
64 |
+
'token': 4827,
|
65 |
+
'token_str': 'fashion'},
|
66 |
+
{'sequence': "[CLS] hello i'm a role model. [SEP]",
|
67 |
+
'score': 0.08774490654468536,
|
68 |
+
'token': 2535,
|
69 |
+
'token_str': 'role'},
|
70 |
+
{'sequence': "[CLS] hello i'm a new model. [SEP]",
|
71 |
+
'score': 0.05338378623127937,
|
72 |
+
'token': 2047,
|
73 |
+
'token_str': 'new'},
|
74 |
+
{'sequence': "[CLS] hello i'm a super model. [SEP]",
|
75 |
+
'score': 0.04667217284440994,
|
76 |
+
'token': 3565,
|
77 |
+
'token_str': 'super'},
|
78 |
+
{'sequence': "[CLS] hello i'm a fine model. [SEP]",
|
79 |
+
'score': 0.027095865458250046,
|
80 |
+
'token': 2986,
|
81 |
+
'token_str': 'fine'}]
|
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-uncased')
|
89 |
+
model = BertModel.from_pretrained("bert-base-uncased")
|
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-uncased')
|
100 |
+
model = TFBertModel.from_pretrained("bert-base-uncased")
|
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-uncased')
|
114 |
+
>>> unmasker("The man worked as a [MASK].")
|
115 |
+
|
116 |
+
[{'sequence': '[CLS] the man worked as a carpenter. [SEP]',
|
117 |
+
'score': 0.09747550636529922,
|
118 |
+
'token': 10533,
|
119 |
+
'token_str': 'carpenter'},
|
120 |
+
{'sequence': '[CLS] the man worked as a waiter. [SEP]',
|
121 |
+
'score': 0.0523831807076931,
|
122 |
+
'token': 15610,
|
123 |
+
'token_str': 'waiter'},
|
124 |
+
{'sequence': '[CLS] the man worked as a barber. [SEP]',
|
125 |
+
'score': 0.04962705448269844,
|
126 |
+
'token': 13362,
|
127 |
+
'token_str': 'barber'},
|
128 |
+
{'sequence': '[CLS] the man worked as a mechanic. [SEP]',
|
129 |
+
'score': 0.03788609802722931,
|
130 |
+
'token': 15893,
|
131 |
+
'token_str': 'mechanic'},
|
132 |
+
{'sequence': '[CLS] the man worked as a salesman. [SEP]',
|
133 |
+
'score': 0.037680890411138535,
|
134 |
+
'token': 18968,
|
135 |
+
'token_str': 'salesman'}]
|
136 |
+
|
137 |
+
>>> unmasker("The woman worked as a [MASK].")
|
138 |
+
|
139 |
+
[{'sequence': '[CLS] the woman worked as a nurse. [SEP]',
|
140 |
+
'score': 0.21981462836265564,
|
141 |
+
'token': 6821,
|
142 |
+
'token_str': 'nurse'},
|
143 |
+
{'sequence': '[CLS] the woman worked as a waitress. [SEP]',
|
144 |
+
'score': 0.1597415804862976,
|
145 |
+
'token': 13877,
|
146 |
+
'token_str': 'waitress'},
|
147 |
+
{'sequence': '[CLS] the woman worked as a maid. [SEP]',
|
148 |
+
'score': 0.1154729500412941,
|
149 |
+
'token': 10850,
|
150 |
+
'token_str': 'maid'},
|
151 |
+
{'sequence': '[CLS] the woman worked as a prostitute. [SEP]',
|
152 |
+
'score': 0.037968918681144714,
|
153 |
+
'token': 19215,
|
154 |
+
'token_str': 'prostitute'},
|
155 |
+
{'sequence': '[CLS] the woman worked as a cook. [SEP]',
|
156 |
+
'score': 0.03042375110089779,
|
157 |
+
'token': 5660,
|
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 lowercased and tokenized using WordPiece and a vocabulary size of 30,000. The inputs of the model are
|
174 |
+
then of the form:
|
175 |
+
|
176 |
+
```
|
177 |
+
[CLS] Sentence A [SEP] Sentence B [SEP]
|
178 |
+
```
|
179 |
+
|
180 |
+
With probability 0.5, sentence A and sentence B correspond to two consecutive sentences in the original corpus and in
|
181 |
+
the other cases, it's another random sentence in the corpus. Note that what is considered a sentence here is a
|
182 |
+
consecutive span of text usually longer than a single sentence. The only constrain is that the result with the two
|
183 |
+
"sentences" has a combined length of less than 512 tokens.
|
184 |
+
|
185 |
+
The details of the masking procedure for each sentence are the following:
|
186 |
+
|
187 |
+
- 15% of the tokens are masked.
|
188 |
+
- In 80% of the cases, the masked tokens are replaced by `[MASK]`.
|
189 |
+
- In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
|
190 |
+
- In the 10% remaining cases, the masked tokens are left as is.
|
191 |
+
|
192 |
+
### Pretraining
|
193 |
+
|
194 |
+
The model was trained on 4 cloud TPUs in Pod configuration (16 TPU chips total) for one million steps with a batch size
|
195 |
+
of 256. The sequence length was limited to 128 tokens for 90% of the steps and 512 for the remaining 10%. The optimizer
|
196 |
+
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,
|
197 |
+
learning rate warmup for 10,000 steps and linear decay of the learning rate after.
|
198 |
+
|
199 |
+
## Evaluation results
|
200 |
+
|
201 |
+
When fine-tuned on downstream tasks, this model achieves the following results:
|
202 |
+
|
203 |
+
Glue test results:
|
204 |
+
|
205 |
+
| Task | MNLI-(m/mm) | QQP | QNLI | SST-2 | CoLA | STS-B | MRPC | RTE | Average |
|
206 |
+
| :--: | :---------: | :--: | :--: | :---: | :--: | :---: | :--: | :--: | :-----: |
|
207 |
+
| | 84.6/83.4 | 71.2 | 90.5 | 93.5 | 52.1 | 85.8 | 88.9 | 66.4 | 79.6 |
|
208 |
+
|
209 |
+
### BibTeX entry and citation info
|
210 |
+
|
211 |
+
```bibtex
|
212 |
+
@article{DBLP:journals/corr/abs-1810-04805,
|
213 |
+
author = {Jacob Devlin and
|
214 |
+
Ming{-}Wei Chang and
|
215 |
+
Kenton Lee and
|
216 |
+
Kristina Toutanova},
|
217 |
+
title = {{BERT:} Pre-training of Deep Bidirectional Transformers for Language
|
218 |
+
Understanding},
|
219 |
+
journal = {CoRR},
|
220 |
+
volume = {abs/1810.04805},
|
221 |
+
year = {2018},
|
222 |
+
url = {http://arxiv.org/abs/1810.04805},
|
223 |
+
archivePrefix = {arXiv},
|
224 |
+
eprint = {1810.04805},
|
225 |
+
timestamp = {Tue, 30 Oct 2018 20:39:56 +0100},
|
226 |
+
biburl = {https://dblp.org/rec/journals/corr/abs-1810-04805.bib},
|
227 |
+
bibsource = {dblp computer science bibliography, https://dblp.org}
|
228 |
+
}
|
229 |
+
```
|
230 |
+
|
231 |
+
<a href="https://huggingface.co/exbert/?model=bert-base-uncased">
|
232 |
+
<img width="300px" src="https://cdn-media.huggingface.co/exbert/button.png">
|
233 |
+
</a>
|
config.json
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"BertForMaskedLM"
|
4 |
+
],
|
5 |
+
"attention_probs_dropout_prob": 0.1,
|
6 |
+
"gradient_checkpointing": false,
|
7 |
+
"hidden_act": "gelu",
|
8 |
+
"hidden_dropout_prob": 0.1,
|
9 |
+
"hidden_size": 768,
|
10 |
+
"initializer_range": 0.02,
|
11 |
+
"intermediate_size": 3072,
|
12 |
+
"layer_norm_eps": 1e-12,
|
13 |
+
"max_position_embeddings": 512,
|
14 |
+
"model_type": "bert",
|
15 |
+
"num_attention_heads": 12,
|
16 |
+
"num_hidden_layers": 12,
|
17 |
+
"pad_token_id": 0,
|
18 |
+
"position_embedding_type": "absolute",
|
19 |
+
"transformers_version": "4.6.0.dev0",
|
20 |
+
"type_vocab_size": 2,
|
21 |
+
"use_cache": true,
|
22 |
+
"vocab_size": 30522
|
23 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:097417381d6c7230bd9e3557456d726de6e83245ec8b24f529f60198a67b203a
|
3 |
+
size 440473133
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"do_lower_case": true, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "model_max_length": 512, "special_tokens_map_file": null, "name_or_path": "bert-base-uncased"}
|