s4sarath commited on
Commit
84013ec
1 Parent(s): cf822fa

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +145 -0
README.md ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 (cased)
12
+
13
+ Pretrained model on English language using a masked language modeling (MLM) objective. It was introduced in
14
+ [this paper](https://arxiv.org/abs/1810.04805) and first released in
15
+ [this repository](https://github.com/google-research/bert). This model is case-sensitive: it makes a difference between
16
+ english and English.
17
+
18
+ Disclaimer: The team releasing BERT did not write a model card for this model so this model card has been written by
19
+ the Hugging Face team.
20
+
21
+ ## Model description
22
+
23
+ BERT is a transformers model pretrained on a large corpus of English data in a self-supervised fashion. This means it
24
+ was pretrained on the raw texts only, with no humans labelling them in any way (which is why it can use lots of
25
+ publicly available data) with an automatic process to generate inputs and labels from those texts. More precisely, it
26
+ was pretrained with two objectives:
27
+
28
+ - Masked language modeling (MLM): taking a sentence, the model randomly masks 15% of the words in the input then run
29
+ the entire masked sentence through the model and has to predict the masked words. This is different from traditional
30
+ recurrent neural networks (RNNs) that usually see the words one after the other, or from autoregressive models like
31
+ GPT which internally mask the future tokens. It allows the model to learn a bidirectional representation of the
32
+ sentence.
33
+ - Next sentence prediction (NSP): the models concatenates two masked sentences as inputs during pretraining. Sometimes
34
+ they correspond to sentences that were next to each other in the original text, sometimes not. The model then has to
35
+ predict if the two sentences were following each other or not.
36
+
37
+ This way, the model learns an inner representation of the English language that can then be used to extract features
38
+ useful for downstream tasks: if you have a dataset of labeled sentences for instance, you can train a standard
39
+ classifier using the features produced by the BERT model as inputs.
40
+
41
+ ## Intended uses & limitations
42
+
43
+ You can use the raw model for either masked language modeling or next sentence prediction, but it's mostly intended to
44
+ be fine-tuned on a downstream task. See the [model hub](https://huggingface.co/models?filter=bert) to look for
45
+ fine-tuned versions on a task that interests you.
46
+
47
+ Note that this model is primarily aimed at being fine-tuned on tasks that use the whole sentence (potentially masked)
48
+ to make decisions, such as sequence classification, token classification or question answering. For tasks such as text
49
+ generation you should look at model like GPT2.
50
+
51
+ ### How to use
52
+
53
+ You can use this model directly with a pipeline for masked language modeling:
54
+ In tf_transformers
55
+
56
+ ```python
57
+ from tf_transformers.models import BertModel
58
+ from transformers import BertTokenizer
59
+
60
+ tokenizer = BertTokenizer.from_pretrained('bert-base-cased')
61
+ model = BertModel.from_pretrained("bert-base-cased")
62
+
63
+ text = "Replace me by any text you'd like."
64
+ inputs_tf = {}
65
+ inputs = tokenizer(text, return_tensors='tf')
66
+
67
+
68
+ inputs_tf["input_ids"] = inputs["input_ids"]
69
+ inputs_tf["input_type_ids"] = inputs["token_type_ids"]
70
+ inputs_tf["input_mask"] = inputs["attention_mask"]
71
+ outputs_tf = model(inputs_tf)
72
+ ```
73
+
74
+
75
+
76
+ ## Training data
77
+
78
+ The BERT model was pretrained on [BookCorpus](https://yknzhu.wixsite.com/mbweb), a dataset consisting of 11,038
79
+ unpublished books and [English Wikipedia](https://en.wikipedia.org/wiki/English_Wikipedia) (excluding lists, tables and
80
+ headers).
81
+
82
+ ## Training procedure
83
+
84
+ ### Preprocessing
85
+
86
+ The texts are tokenized using WordPiece and a vocabulary size of 30,000. The inputs of the model are then of the form:
87
+
88
+ ```
89
+ [CLS] Sentence A [SEP] Sentence B [SEP]
90
+ ```
91
+
92
+ With probability 0.5, sentence A and sentence B correspond to two consecutive sentences in the original corpus and in
93
+ the other cases, it's another random sentence in the corpus. Note that what is considered a sentence here is a
94
+ consecutive span of text usually longer than a single sentence. The only constrain is that the result with the two
95
+ "sentences" has a combined length of less than 512 tokens.
96
+
97
+ The details of the masking procedure for each sentence are the following:
98
+ - 15% of the tokens are masked.
99
+ - In 80% of the cases, the masked tokens are replaced by `[MASK]`.
100
+ - In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
101
+ - In the 10% remaining cases, the masked tokens are left as is.
102
+
103
+ ### Pretraining
104
+
105
+ The model was trained on 4 cloud TPUs in Pod configuration (16 TPU chips total) for one million steps with a batch size
106
+ of 256. The sequence length was limited to 128 tokens for 90% of the steps and 512 for the remaining 10%. The optimizer
107
+ 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,
108
+ learning rate warmup for 10,000 steps and linear decay of the learning rate after.
109
+
110
+ ## Evaluation results
111
+
112
+ When fine-tuned on downstream tasks, this model achieves the following results:
113
+
114
+ Glue test results:
115
+
116
+ | Task | MNLI-(m/mm) | QQP | QNLI | SST-2 | CoLA | STS-B | MRPC | RTE | Average |
117
+ |:----:|:-----------:|:----:|:----:|:-----:|:----:|:-----:|:----:|:----:|:-------:|
118
+ | | 84.6/83.4 | 71.2 | 90.5 | 93.5 | 52.1 | 85.8 | 88.9 | 66.4 | 79.6 |
119
+
120
+
121
+ ### BibTeX entry and citation info
122
+
123
+ ```bibtex
124
+ @article{DBLP:journals/corr/abs-1810-04805,
125
+ author = {Jacob Devlin and
126
+ Ming{-}Wei Chang and
127
+ Kenton Lee and
128
+ Kristina Toutanova},
129
+ title = {{BERT:} Pre-training of Deep Bidirectional Transformers for Language
130
+ Understanding},
131
+ journal = {CoRR},
132
+ volume = {abs/1810.04805},
133
+ year = {2018},
134
+ url = {http://arxiv.org/abs/1810.04805},
135
+ archivePrefix = {arXiv},
136
+ eprint = {1810.04805},
137
+ timestamp = {Tue, 30 Oct 2018 20:39:56 +0100},
138
+ biburl = {https://dblp.org/rec/journals/corr/abs-1810-04805.bib},
139
+ bibsource = {dblp computer science bibliography, https://dblp.org}
140
+ }
141
+ ```
142
+
143
+ <a href="https://huggingface.co/exbert/?model=bert-base-cased">
144
+ <img width="300px" src="https://cdn-media.huggingface.co/exbert/button.png">
145
+ </a>