README.md
6.0 KB · 125 lines · markdown Raw
1 ---
2 language: en
3 license: apache-2.0
4 datasets:
5 - bookcorpus
6 - wikipedia
7 ---
8
9 # BERT large model (cased) whole word masking finetuned on SQuAD
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 cased: it makes a difference between english and English.
14
15 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.
16
17 The training is identical -- each masked WordPiece token is predicted independently.
18
19 After pre-training, this model was fine-tuned on the SQuAD dataset with one of our fine-tuning scripts. See below for more information regarding this fine-tuning.
20
21 Disclaimer: The team releasing BERT did not write a model card for this model so this model card has been written by
22 the Hugging Face team.
23
24 ## Model description
25
26 BERT is a transformers model pretrained on a large corpus of English data in a self-supervised fashion. This means it
27 was pretrained on the raw texts only, with no humans labelling them in any way (which is why it can use lots of
28 publicly available data) with an automatic process to generate inputs and labels from those texts. More precisely, it
29 was pretrained with two objectives:
30
31 - Masked language modeling (MLM): taking a sentence, the model randomly masks 15% of the words in the input then run
32 the entire masked sentence through the model and has to predict the masked words. This is different from traditional
33 recurrent neural networks (RNNs) that usually see the words one after the other, or from autoregressive models like
34 GPT which internally mask the future tokens. It allows the model to learn a bidirectional representation of the
35 sentence.
36 - Next sentence prediction (NSP): the models concatenates two masked sentences as inputs during pretraining. Sometimes
37 they correspond to sentences that were next to each other in the original text, sometimes not. The model then has to
38 predict if the two sentences were following each other or not.
39
40 This way, the model learns an inner representation of the English language that can then be used to extract features
41 useful for downstream tasks: if you have a dataset of labeled sentences for instance, you can train a standard
42 classifier using the features produced by the BERT model as inputs.
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 This model should be used as a question-answering model. You may use it in a question answering pipeline, or use it to output raw results given a query and a context. You may see other use cases in the [task summary](https://huggingface.co/transformers/task_summary.html#extractive-question-answering) of the transformers documentation.## Training data
53
54 The BERT model was pretrained on [BookCorpus](https://yknzhu.wixsite.com/mbweb), a dataset consisting of 11,038
55 unpublished books and [English Wikipedia](https://en.wikipedia.org/wiki/English_Wikipedia) (excluding lists, tables and
56 headers).
57
58 ## Training procedure
59
60 ### Preprocessing
61
62 The texts are lowercased and tokenized using WordPiece and a vocabulary size of 30,000. The inputs of the model are
63 then of the form:
64
65 ```
66 [CLS] Sentence A [SEP] Sentence B [SEP]
67 ```
68
69 With probability 0.5, sentence A and sentence B correspond to two consecutive sentences in the original corpus and in
70 the other cases, it's another random sentence in the corpus. Note that what is considered a sentence here is a
71 consecutive span of text usually longer than a single sentence. The only constrain is that the result with the two
72 "sentences" has a combined length of less than 512 tokens.
73
74 The details of the masking procedure for each sentence are the following:
75 - 15% of the tokens are masked.
76 - In 80% of the cases, the masked tokens are replaced by `[MASK]`.
77 - In 10% of the cases, the masked tokens are replaced by a random token (different) from the one they replace.
78 - In the 10% remaining cases, the masked tokens are left as is.
79
80 ### Pretraining
81
82 The model was trained on 4 cloud TPUs in Pod configuration (16 TPU chips total) for one million steps with a batch size
83 of 256. The sequence length was limited to 128 tokens for 90% of the steps and 512 for the remaining 10%. The optimizer
84 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,
85 learning rate warmup for 10,000 steps and linear decay of the learning rate after.
86
87 ### Fine-tuning
88
89 After pre-training, this model was fine-tuned on the SQuAD dataset with one of our fine-tuning scripts. In order to reproduce the training, you may use the following command:
90 ```
91 python -m torch.distributed.launch --nproc_per_node=8 ./examples/question-answering/run_qa.py \
92 --model_name_or_path bert-large-cased-whole-word-masking \
93 --dataset_name squad \
94 --do_train \
95 --do_eval \
96 --learning_rate 3e-5 \
97 --num_train_epochs 2 \
98 --max_seq_length 384 \
99 --doc_stride 128 \
100 --output_dir ./examples/models/wwm_cased_finetuned_squad/ \
101 --per_device_eval_batch_size=3 \
102 --per_device_train_batch_size=3 \
103 ```
104
105 ### BibTeX entry and citation info
106
107 ```bibtex
108 @article{DBLP:journals/corr/abs-1810-04805,
109 author = {Jacob Devlin and
110 Ming{-}Wei Chang and
111 Kenton Lee and
112 Kristina Toutanova},
113 title = {{BERT:} Pre-training of Deep Bidirectional Transformers for Language
114 Understanding},
115 journal = {CoRR},
116 volume = {abs/1810.04805},
117 year = {2018},
118 url = {http://arxiv.org/abs/1810.04805},
119 archivePrefix = {arXiv},
120 eprint = {1810.04805},
121 timestamp = {Tue, 30 Oct 2018 20:39:56 +0100},
122 biburl = {https://dblp.org/rec/journals/corr/abs-1810-04805.bib},
123 bibsource = {dblp computer science bibliography, https://dblp.org}
124 }
125 ```