Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: en
|
3 |
+
license: apache-2.0
|
4 |
+
datasets:
|
5 |
+
- bookcorpus
|
6 |
+
- wikipedia
|
7 |
+
---
|
8 |
+
|
9 |
+
# BERT large model (uncased) whole word masking
|
10 |
+
|
11 |
+
Pretrained model on English language using a masked language modeling (MLM) objective. It was introduced in
|
12 |
+
[this paper](https://arxiv.org/abs/1810.04805) and first released in
|
13 |
+
[this repository](https://github.com/google-research/bert). This model is uncased: it does not make a difference
|
14 |
+
between english and English.
|
15 |
+
|
16 |
+
Differently to other BERT models, this model was trained with a new technique: Whole Word Masking. In this case, all of the tokens corresponding to a word are masked at once. The overall masking rate remains the same.
|
17 |
+
|
18 |
+
The training is identical -- each masked WordPiece token is predicted independently.
|
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 |
+
|
44 |
+
This model has the following configuration:
|
45 |
+
|
46 |
+
- 24-layer
|
47 |
+
- 1024 hidden dimension
|
48 |
+
- 16 attention heads
|
49 |
+
- 336M parameters.
|
50 |
+
|
51 |
+
## Intended uses & limitations
|
52 |
+
|
53 |
+
You can use the raw model for either masked language modeling or next sentence prediction, but it's mostly intended to
|
54 |
+
be fine-tuned on a downstream task. See the [model hub](https://huggingface.co/models?filter=bert) to look for
|
55 |
+
fine-tuned versions on a task that interests you.
|
56 |
+
|
57 |
+
Note that this model is primarily aimed at being fine-tuned on tasks that use the whole sentence (potentially masked)
|
58 |
+
to make decisions, such as sequence classification, token classification or question answering. For tasks such as text
|
59 |
+
generation you should look at model like GPT2.
|
60 |
+
|
61 |
+
### How to use
|
62 |
+
|
63 |
+
You can use this model directly with a pipeline for masked language modeling:
|
64 |
+
In tf_transformers
|
65 |
+
|
66 |
+
```python
|
67 |
+
from tf_transformers.models import BertModel
|
68 |
+
from transformers import BertTokenizer
|
69 |
+
|
70 |
+
tokenizer = BertTokenizer.from_pretrained('bert-large-uncased-whole-word-masking')
|
71 |
+
model = BertModel.from_pretrained("bert-large-uncased-whole-word-masking")
|
72 |
+
|
73 |
+
text = "Replace me by any text you'd like."
|
74 |
+
inputs_tf = {}
|
75 |
+
inputs = tokenizer(text, return_tensors='tf')
|
76 |
+
|
77 |
+
|
78 |
+
inputs_tf["input_ids"] = inputs["input_ids"]
|
79 |
+
inputs_tf["input_type_ids"] = inputs["token_type_ids"]
|
80 |
+
inputs_tf["input_mask"] = inputs["attention_mask"]
|
81 |
+
outputs_tf = model(inputs_tf)
|
82 |
+
```
|
83 |
+
|
84 |
+
## Training data
|
85 |
+
|
86 |
+
The BERT model was pretrained on [BookCorpus](https://yknzhu.wixsite.com/mbweb), a dataset consisting of 11,038
|
87 |
+
unpublished books and [English Wikipedia](https://en.wikipedia.org/wiki/English_Wikipedia) (excluding lists, tables and
|
88 |
+
headers).
|
89 |
+
|
90 |
+
## Training procedure
|
91 |
+
|
92 |
+
### Preprocessing
|
93 |
+
|
94 |
+
The texts are lowercased and tokenized using WordPiece and a vocabulary size of 30,000. The inputs of the model are
|
95 |
+
then of the form:
|
96 |
+
|
97 |
+
```
|
98 |
+
[CLS] Sentence A [SEP] Sentence B [SEP]
|
99 |
+
```
|
100 |
+
|
101 |
+
With probability 0.5, sentence A and sentence B correspond to two consecutive sentences in the original corpus and in
|
102 |
+
the other cases, it's another random sentence in the corpus. Note that what is considered a sentence here is a
|
103 |
+
consecutive span of text usually longer than a single sentence. The only constrain is that the result with the two
|
104 |
+
"sentences" has a combined length of less than 512 tokens.
|
105 |
+
|
106 |
+
The details of the masking procedure for each sentence are the following:
|
107 |
+
- 15% of the tokens are masked.
|
108 |
+
- In 80% of the cases, the masked tokens are replaced by `[MASK]`.
|
109 |
+
- In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
|
110 |
+
- In the 10% remaining cases, the masked tokens are left as is.
|
111 |
+
|
112 |
+
### Pretraining
|
113 |
+
|
114 |
+
The model was trained on 4 cloud TPUs in Pod configuration (16 TPU chips total) for one million steps with a batch size
|
115 |
+
of 256. The sequence length was limited to 128 tokens for 90% of the steps and 512 for the remaining 10%. The optimizer
|
116 |
+
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,
|
117 |
+
learning rate warmup for 10,000 steps and linear decay of the learning rate after.
|
118 |
+
|
119 |
+
## Evaluation results
|
120 |
+
|
121 |
+
When fine-tuned on downstream tasks, this model achieves the following results:
|
122 |
+
|
123 |
+
Model | SQUAD 1.1 F1/EM | Multi NLI Accuracy
|
124 |
+
---------------------------------------- | :-------------: | :----------------:
|
125 |
+
BERT-Large, Uncased (Whole Word Masking) | 92.8/86.7 | 87.07
|
126 |
+
|
127 |
+
|
128 |
+
### BibTeX entry and citation info
|
129 |
+
|
130 |
+
```bibtex
|
131 |
+
@article{DBLP:journals/corr/abs-1810-04805,
|
132 |
+
author = {Jacob Devlin and
|
133 |
+
Ming{-}Wei Chang and
|
134 |
+
Kenton Lee and
|
135 |
+
Kristina Toutanova},
|
136 |
+
title = {{BERT:} Pre-training of Deep Bidirectional Transformers for Language
|
137 |
+
Understanding},
|
138 |
+
journal = {CoRR},
|
139 |
+
volume = {abs/1810.04805},
|
140 |
+
year = {2018},
|
141 |
+
url = {http://arxiv.org/abs/1810.04805},
|
142 |
+
archivePrefix = {arXiv},
|
143 |
+
eprint = {1810.04805},
|
144 |
+
timestamp = {Tue, 30 Oct 2018 20:39:56 +0100},
|
145 |
+
biburl = {https://dblp.org/rec/journals/corr/abs-1810-04805.bib},
|
146 |
+
bibsource = {dblp computer science bibliography, https://dblp.org}
|
147 |
+
}
|
148 |
+
```
|