Add 1 files
Browse files- 1810/1810.04805.md +477 -0
1810/1810.04805.md
ADDED
|
@@ -0,0 +1,477 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Title: Pre-training of Deep Bidirectional Transformers for Language Understanding
|
| 2 |
+
|
| 3 |
+
URL Source: https://arxiv.org/html/1810.04805
|
| 4 |
+
|
| 5 |
+
Markdown Content:
|
| 6 |
+
Jacob Devlin Ming-Wei Chang Kenton Lee Kristina Toutanova
|
| 7 |
+
|
| 8 |
+
Google AI Language
|
| 9 |
+
|
| 10 |
+
{jacobdevlin,mingweichang,kentonl,kristout}@google.com
|
| 11 |
+
|
| 12 |
+
###### Abstract
|
| 13 |
+
|
| 14 |
+
We introduce a new language representation model called BERT, which stands for B idirectional E ncoder R epresentations from T ransformers. Unlike recent language representation models Peters et al. ([2018a](https://arxiv.org/html/1810.04805#bib.bib36)); Radford et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib38)), BERT is designed to pre-train deep bidirectional representations from unlabeled text by jointly conditioning on both left and right context in all layers. As a result, the pre-trained BERT model can be fine-tuned with just one additional output layer to create state-of-the-art models for a wide range of tasks, such as question answering and language inference, without substantial task-specific architecture modifications.
|
| 15 |
+
|
| 16 |
+
BERT is conceptually simple and empirically powerful. It obtains new state-of-the-art results on eleven natural language processing tasks, including pushing the GLUE score to 80.5% (7.7% point absolute improvement), MultiNLI accuracy to 86.7% (4.6% absolute improvement), SQuAD v1.1 question answering Test F1 to 93.2 (1.5 point absolute improvement) and SQuAD v2.0 Test F1 to 83.1 (5.1 point absolute improvement).
|
| 17 |
+
|
| 18 |
+
1 Introduction
|
| 19 |
+
--------------
|
| 20 |
+
|
| 21 |
+
Language model pre-training has been shown to be effective for improving many natural language processing tasks Dai and Le ([2015](https://arxiv.org/html/1810.04805#bib.bib15)); Peters et al. ([2018a](https://arxiv.org/html/1810.04805#bib.bib36)); Radford et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib38)); Howard and Ruder ([2018](https://arxiv.org/html/1810.04805#bib.bib21)). These include sentence-level tasks such as natural language inference Bowman et al. ([2015](https://arxiv.org/html/1810.04805#bib.bib6)); Williams et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib51)) and paraphrasing Dolan and Brockett ([2005](https://arxiv.org/html/1810.04805#bib.bib17)), which aim to predict the relationships between sentences by analyzing them holistically, as well as token-level tasks such as named entity recognition and question answering, where models are required to produce fine-grained output at the token level Tjong Kim Sang and De Meulder ([2003](https://arxiv.org/html/1810.04805#bib.bib44)); Rajpurkar et al. ([2016](https://arxiv.org/html/1810.04805#bib.bib39)).
|
| 22 |
+
|
| 23 |
+
There are two existing strategies for applying pre-trained language representations to downstream tasks: feature-based and fine-tuning. The feature-based approach, such as ELMo Peters et al. ([2018a](https://arxiv.org/html/1810.04805#bib.bib36)), uses task-specific architectures that include the pre-trained representations as additional features. The fine-tuning approach, such as the Generative Pre-trained Transformer (OpenAI GPT)Radford et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib38)), introduces minimal task-specific parameters, and is trained on the downstream tasks by simply fine-tuning all pre-trained parameters. The two approaches share the same objective function during pre-training, where they use unidirectional language models to learn general language representations.
|
| 24 |
+
|
| 25 |
+
We argue that current techniques restrict the power of the pre-trained representations, especially for the fine-tuning approaches. The major limitation is that standard language models are unidirectional, and this limits the choice of architectures that can be used during pre-training. For example, in OpenAI GPT, the authors use a left-to-right architecture, where every token can only attend to previous tokens in the self-attention layers of the Transformer Vaswani et al. ([2017](https://arxiv.org/html/1810.04805#bib.bib46)). Such restrictions are sub-optimal for sentence-level tasks, and could be very harmful when applying fine-tuning based approaches to token-level tasks such as question answering, where it is crucial to incorporate context from both directions.
|
| 26 |
+
|
| 27 |
+
In this paper, we improve the fine-tuning based approaches by proposing BERT: B idirectional E ncoder R epresentations from T ransformers. BERT alleviates the previously mentioned unidirectionality constraint by using a “masked language model”(MLM) pre-training objective, inspired by the Cloze task Taylor ([1953](https://arxiv.org/html/1810.04805#bib.bib43)). The masked language model randomly masks some of the tokens from the input, and the objective is to predict the original vocabulary id of the masked word based only on its context. Unlike left-to-right language model pre-training, the MLM objective enables the representation to fuse the left and the right context, which allows us to pre-train a deep bidirectional Transformer. In addition to the masked language model, we also use a “next sentence prediction” task that jointly pre-trains text-pair representations. The contributions of our paper are as follows:
|
| 28 |
+
|
| 29 |
+
* •
|
| 30 |
+
We demonstrate the importance of bidirectional pre-training for language representations. Unlike Radford et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib38)), which uses unidirectional language models for pre-training, BERT uses masked language models to enable pre-trained deep bidirectional representations. This is also in contrast to Peters et al. ([2018a](https://arxiv.org/html/1810.04805#bib.bib36)), which uses a shallow concatenation of independently trained left-to-right and right-to-left LMs.
|
| 31 |
+
|
| 32 |
+
* •
|
| 33 |
+
We show that pre-trained representations reduce the need for many heavily-engineered task-specific architectures. BERT is the first fine-tuning based representation model that achieves state-of-the-art performance on a large suite of sentence-level and token-level tasks, outperforming many task-specific architectures.
|
| 34 |
+
|
| 35 |
+
* •
|
| 36 |
+
|
| 37 |
+
2 Related Work
|
| 38 |
+
--------------
|
| 39 |
+
|
| 40 |
+
There is a long history of pre-training general language representations, and we briefly review the most widely-used approaches in this section.
|
| 41 |
+
|
| 42 |
+
### 2.1 Unsupervised Feature-based Approaches
|
| 43 |
+
|
| 44 |
+
Learning widely applicable representations of words has been an active area of research for decades, including non-neural Brown et al. ([1992](https://arxiv.org/html/1810.04805#bib.bib7)); Ando and Zhang ([2005](https://arxiv.org/html/1810.04805#bib.bib3)); Blitzer et al. ([2006](https://arxiv.org/html/1810.04805#bib.bib5)) and neural Mikolov et al. ([2013](https://arxiv.org/html/1810.04805#bib.bib31)); Pennington et al. ([2014](https://arxiv.org/html/1810.04805#bib.bib34)) methods. Pre-trained word embeddings are an integral part of modern NLP systems, offering significant improvements over embeddings learned from scratch Turian et al. ([2010](https://arxiv.org/html/1810.04805#bib.bib45)). To pre-train word embedding vectors, left-to-right language modeling objectives have been used Mnih and Hinton ([2009](https://arxiv.org/html/1810.04805#bib.bib32)), as well as objectives to discriminate correct from incorrect words in left and right context Mikolov et al. ([2013](https://arxiv.org/html/1810.04805#bib.bib31)).
|
| 45 |
+
|
| 46 |
+
These approaches have been generalized to coarser granularities, such as sentence embeddings Kiros et al. ([2015](https://arxiv.org/html/1810.04805#bib.bib25)); Logeswaran and Lee ([2018](https://arxiv.org/html/1810.04805#bib.bib28)) or paragraph embeddings Le and Mikolov ([2014](https://arxiv.org/html/1810.04805#bib.bib26)). To train sentence representations, prior work has used objectives to rank candidate next sentences Jernite et al. ([2017](https://arxiv.org/html/1810.04805#bib.bib23)); Logeswaran and Lee ([2018](https://arxiv.org/html/1810.04805#bib.bib28)), left-to-right generation of next sentence words given a representation of the previous sentence Kiros et al. ([2015](https://arxiv.org/html/1810.04805#bib.bib25)), or denoising auto-encoder derived objectives Hill et al. ([2016](https://arxiv.org/html/1810.04805#bib.bib20)).
|
| 47 |
+
|
| 48 |
+

|
| 49 |
+
|
| 50 |
+
Figure 1: Overall pre-training and fine-tuning procedures for BERT. Apart from output layers, the same architectures are used in both pre-training and fine-tuning. The same pre-trained model parameters are used to initialize models for different down-stream tasks. During fine-tuning, all parameters are fine-tuned. [CLS] is a special symbol added in front of every input example, and [SEP] is a special separator token (e.g. separating questions/answers).
|
| 51 |
+
|
| 52 |
+
ELMo and its predecessor Peters et al. ([2017](https://arxiv.org/html/1810.04805#bib.bib35), [2018a](https://arxiv.org/html/1810.04805#bib.bib36)) generalize traditional word embedding research along a different dimension. They extract _context-sensitive_ features from a left-to-right and a right-to-left language model. The contextual representation of each token is the concatenation of the left-to-right and right-to-left representations. When integrating contextual word embeddings with existing task-specific architectures, ELMo advances the state of the art for several major NLP benchmarks Peters et al. ([2018a](https://arxiv.org/html/1810.04805#bib.bib36)) including question answering Rajpurkar et al. ([2016](https://arxiv.org/html/1810.04805#bib.bib39)), sentiment analysis Socher et al. ([2013](https://arxiv.org/html/1810.04805#bib.bib41)), and named entity recognition Tjong Kim Sang and De Meulder ([2003](https://arxiv.org/html/1810.04805#bib.bib44)). Melamud et al. ([2016](https://arxiv.org/html/1810.04805#bib.bib30)) proposed learning contextual representations through a task to predict a single word from both left and right context using LSTMs. Similar to ELMo, their model is feature-based and not deeply bidirectional. Fedus et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib18)) shows that the cloze task can be used to improve the robustness of text generation models.
|
| 53 |
+
|
| 54 |
+
### 2.2 Unsupervised Fine-tuning Approaches
|
| 55 |
+
|
| 56 |
+
As with the feature-based approaches, the first works in this direction only pre-trained word embedding parameters from unlabeled text Collobert and Weston ([2008](https://arxiv.org/html/1810.04805#bib.bib13)).
|
| 57 |
+
|
| 58 |
+
More recently, sentence or document encoders which produce contextual token representations have been pre-trained from unlabeled text and fine-tuned for a supervised downstream task Dai and Le ([2015](https://arxiv.org/html/1810.04805#bib.bib15)); Howard and Ruder ([2018](https://arxiv.org/html/1810.04805#bib.bib21)); Radford et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib38)). The advantage of these approaches is that few parameters need to be learned from scratch. At least partly due to this advantage, OpenAI GPT Radford et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib38)) achieved previously state-of-the-art results on many sentence-level tasks from the GLUE benchmark Wang et al. ([2018a](https://arxiv.org/html/1810.04805#bib.bib48)). Left-to-right language modeling and auto-encoder objectives have been used for pre-training such models Howard and Ruder ([2018](https://arxiv.org/html/1810.04805#bib.bib21)); Radford et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib38)); Dai and Le ([2015](https://arxiv.org/html/1810.04805#bib.bib15)).
|
| 59 |
+
|
| 60 |
+
### 2.3 Transfer Learning from Supervised Data
|
| 61 |
+
|
| 62 |
+
There has also been work showing effective transfer from supervised tasks with large datasets, such as natural language inference Conneau et al. ([2017](https://arxiv.org/html/1810.04805#bib.bib14)) and machine translation McCann et al. ([2017](https://arxiv.org/html/1810.04805#bib.bib29)). Computer vision research has also demonstrated the importance of transfer learning from large pre-trained models, where an effective recipe is to fine-tune models pre-trained with ImageNet Deng et al. ([2009](https://arxiv.org/html/1810.04805#bib.bib16)); Yosinski et al. ([2014](https://arxiv.org/html/1810.04805#bib.bib53)).
|
| 63 |
+
|
| 64 |
+
3 BERT
|
| 65 |
+
------
|
| 66 |
+
|
| 67 |
+
We introduce BERT and its detailed implementation in this section. There are two steps in our framework: pre-training and fine-tuning. During pre-training, the model is trained on unlabeled data over different pre-training tasks. For fine-tuning, the BERT model is first initialized with the pre-trained parameters, and all of the parameters are fine-tuned using labeled data from the downstream tasks. Each downstream task has separate fine-tuned models, even though they are initialized with the same pre-trained parameters. The question-answering example in Figure[1](https://arxiv.org/html/1810.04805#S2.F1 "Figure 1 ‣ 2.1 Unsupervised Feature-based Approaches ‣ 2 Related Work ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding") will serve as a running example for this section.
|
| 68 |
+
|
| 69 |
+
A distinctive feature of BERT is its unified architecture across different tasks. There is minimal difference between the pre-trained architecture and the final downstream architecture.
|
| 70 |
+
|
| 71 |
+
#### Model Architecture
|
| 72 |
+
|
| 73 |
+
BERT’s model architecture is a multi-layer bidirectional Transformer encoder based on the original implementation described in Vaswani et al. ([2017](https://arxiv.org/html/1810.04805#bib.bib46)) and released in the tensor2tensor library.1 1 1 https://github.com/tensorflow/tensor2tensor Because the use of Transformers has become common and our implementation is almost identical to the original, we will omit an exhaustive background description of the model architecture and refer readers to Vaswani et al. ([2017](https://arxiv.org/html/1810.04805#bib.bib46)) as well as excellent guides such as “The Annotated Transformer.”2 2 2 http://nlp.seas.harvard.edu/2018/04/03/attention.html
|
| 74 |
+
|
| 75 |
+
In this work, we denote the number of layers (i.e., Transformer blocks) as L L, the hidden size as H H, and the number of self-attention heads as A A.3 3 3 In all cases we set the feed-forward/filter size to be 4H 4H, i.e., 3072 for the H=768 H=768 and 4096 for the H=1024 H=1024. We primarily report results on two model sizes: BERT BASE{}_{\textsc{BASE}} (L=12, H=768, A=12, Total Parameters=110M) and BERT LARGE{}_{\textsc{LARGE}} (L=24, H=1024, A=16, Total Parameters=340M).
|
| 76 |
+
|
| 77 |
+
BERT BASE{}_{\textsc{BASE}} was chosen to have the same model size as OpenAI GPT for comparison purposes. Critically, however, the BERT Transformer uses bidirectional self-attention, while the GPT Transformer uses constrained self-attention where every token can only attend to context to its left.4 4 4 We note that in the literature the bidirectional Transformer is often referred to as a “Transformer encoder” while the left-context-only version is referred to as a “Transformer decoder” since it can be used for text generation.
|
| 78 |
+
|
| 79 |
+
#### Input/Output Representations
|
| 80 |
+
|
| 81 |
+
To make BERT handle a variety of down-stream tasks, our input representation is able to unambiguously represent both a single sentence and a pair of sentences (e.g., ⟨\langle Question, Answer ⟩\rangle) in one token sequence. Throughout this work, a “sentence” can be an arbitrary span of contiguous text, rather than an actual linguistic sentence. A “sequence” refers to the input token sequence to BERT, which may be a single sentence or two sentences packed together.
|
| 82 |
+
|
| 83 |
+
We use WordPiece embeddings Wu et al. ([2016](https://arxiv.org/html/1810.04805#bib.bib52)) with a 30,000 token vocabulary. The first token of every sequence is always a special classification token ([CLS]). The final hidden state corresponding to this token is used as the aggregate sequence representation for classification tasks. Sentence pairs are packed together into a single sequence. We differentiate the sentences in two ways. First, we separate them with a special token ([SEP]). Second, we add a learned embedding to every token indicating whether it belongs to sentence A or sentence B. As shown in Figure[1](https://arxiv.org/html/1810.04805#S2.F1 "Figure 1 ‣ 2.1 Unsupervised Feature-based Approaches ‣ 2 Related Work ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"), we denote input embedding as E E, the final hidden vector of the special [CLS] token as C∈ℝ H C\in\mathbb{R}^{H}, and the final hidden vector for the i th i^{\rm th} input token as T i∈ℝ H T_{i}\in\mathbb{R}^{H}.
|
| 84 |
+
|
| 85 |
+
For a given token, its input representation is constructed by summing the corresponding token, segment, and position embeddings. A visualization of this construction can be seen in Figure[2](https://arxiv.org/html/1810.04805#S3.F2 "Figure 2 ‣ Input/Output Representations ‣ 3 BERT ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding").
|
| 86 |
+
|
| 87 |
+

|
| 88 |
+
|
| 89 |
+
Figure 2: BERT input representation. The input embeddings are the sum of the token embeddings, the segmentation embeddings and the position embeddings.
|
| 90 |
+
|
| 91 |
+
### 3.1 Pre-training BERT
|
| 92 |
+
|
| 93 |
+
Unlike Peters et al. ([2018a](https://arxiv.org/html/1810.04805#bib.bib36)) and Radford et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib38)), we do not use traditional left-to-right or right-to-left language models to pre-train BERT. Instead, we pre-train BERT using two unsupervised tasks, described in this section. This step is presented in the left part of Figure[1](https://arxiv.org/html/1810.04805#S2.F1 "Figure 1 ‣ 2.1 Unsupervised Feature-based Approaches ‣ 2 Related Work ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding").
|
| 94 |
+
|
| 95 |
+
#### Task #1: Masked LM
|
| 96 |
+
|
| 97 |
+
Intuitively, it is reasonable to believe that a deep bidirectional model is strictly more powerful than either a left-to-right model or the shallow concatenation of a left-to-right and a right-to-left model. Unfortunately, standard conditional language models can only be trained left-to-right or right-to-left, since bidirectional conditioning would allow each word to indirectly “see itself”, and the model could trivially predict the target word in a multi-layered context.
|
| 98 |
+
|
| 99 |
+
In order to train a deep bidirectional representation, we simply mask some percentage of the input tokens at random, and then predict those masked tokens. We refer to this procedure as a “masked LM” (MLM), although it is often referred to as a Cloze task in the literature Taylor ([1953](https://arxiv.org/html/1810.04805#bib.bib43)). In this case, the final hidden vectors corresponding to the mask tokens are fed into an output softmax over the vocabulary, as in a standard LM. In all of our experiments, we mask 15% of all WordPiece tokens in each sequence at random. In contrast to denoising auto-encoders Vincent et al. ([2008](https://arxiv.org/html/1810.04805#bib.bib47)), we only predict the masked words rather than reconstructing the entire input.
|
| 100 |
+
|
| 101 |
+
Although this allows us to obtain a bidirectional pre-trained model, a downside is that we are creating a mismatch between pre-training and fine-tuning, since the [MASK] token does not appear during fine-tuning. To mitigate this, we do not always replace “masked” words with the actual [MASK] token. The training data generator chooses 15% of the token positions at random for prediction. If the i i-th token is chosen, we replace the i i-th token with (1) the [MASK] token 80% of the time (2) a random token 10% of the time (3) the unchanged i i-th token 10% of the time. Then, T i T_{i} will be used to predict the original token with cross entropy loss. We compare variations of this procedure in Appendix[C.2](https://arxiv.org/html/1810.04805#A3.SS2 "C.2 Ablation for Different Masking Procedures ‣ Appendix C Additional Ablation Studies ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding").
|
| 102 |
+
|
| 103 |
+
#### Task #2: Next Sentence Prediction (NSP)
|
| 104 |
+
|
| 105 |
+
Many important downstream tasks such as Question Answering (QA) and Natural Language Inference (NLI) are based on understanding the relationship between two sentences, which is not directly captured by language modeling. In order to train a model that understands sentence relationships, we pre-train for a binarized next sentence prediction task that can be trivially generated from any monolingual corpus. Specifically, when choosing the sentences A and B for each pre-training example, 50% of the time B is the actual next sentence that follows A (labeled as IsNext), and 50% of the time it is a random sentence from the corpus (labeled as NotNext). As we show in Figure[1](https://arxiv.org/html/1810.04805#S2.F1 "Figure 1 ‣ 2.1 Unsupervised Feature-based Approaches ‣ 2 Related Work ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"), C C is used for next sentence prediction (NSP).5 5 5 The final model achieves 97%-98% accuracy on NSP. Despite its simplicity, we demonstrate in Section[5.1](https://arxiv.org/html/1810.04805#S5.SS1 "5.1 Effect of Pre-training Tasks ‣ 5 Ablation Studies ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding") that pre-training towards this task is very beneficial to both QA and NLI. 6 6 6 The vector C C is not a meaningful sentence representation without fine-tuning, since it was trained with NSP. The NSP task is closely related to representation-learning objectives used in Jernite et al. ([2017](https://arxiv.org/html/1810.04805#bib.bib23)) and Logeswaran and Lee ([2018](https://arxiv.org/html/1810.04805#bib.bib28)). However, in prior work, only sentence embeddings are transferred to down-stream tasks, where BERT transfers all parameters to initialize end-task model parameters.
|
| 106 |
+
|
| 107 |
+
Pre-training data The pre-training procedure largely follows the existing literature on language model pre-training. For the pre-training corpus we use the BooksCorpus (800M words)Zhu et al. ([2015](https://arxiv.org/html/1810.04805#bib.bib56)) and English Wikipedia (2,500M words). For Wikipedia we extract only the text passages and ignore lists, tables, and headers. It is critical to use a document-level corpus rather than a shuffled sentence-level corpus such as the Billion Word Benchmark Chelba et al. ([2013](https://arxiv.org/html/1810.04805#bib.bib9)) in order to extract long contiguous sequences.
|
| 108 |
+
|
| 109 |
+
### 3.2 Fine-tuning BERT
|
| 110 |
+
|
| 111 |
+
Fine-tuning is straightforward since the self-attention mechanism in the Transformer allows BERT to model many downstream tasks—whether they involve single text or text pairs—by swapping out the appropriate inputs and outputs. For applications involving text pairs, a common pattern is to independently encode text pairs before applying bidirectional cross attention, such as Parikh et al. ([2016](https://arxiv.org/html/1810.04805#bib.bib33)); Seo et al. ([2017](https://arxiv.org/html/1810.04805#bib.bib40)). BERT instead uses the self-attention mechanism to unify these two stages, as encoding a concatenated text pair with self-attention effectively includes _bidirectional_ cross attention between two sentences.
|
| 112 |
+
|
| 113 |
+
For each task, we simply plug in the task-specific inputs and outputs into BERT and fine-tune all the parameters end-to-end. At the input, sentence A and sentence B from pre-training are analogous to (1) sentence pairs in paraphrasing, (2) hypothesis-premise pairs in entailment, (3) question-passage pairs in question answering, and (4) a degenerate text-∅\varnothing pair in text classification or sequence tagging. At the output, the token representations are fed into an output layer for token-level tasks, such as sequence tagging or question answering, and the [CLS] representation is fed into an output layer for classification, such as entailment or sentiment analysis.
|
| 114 |
+
|
| 115 |
+
Compared to pre-training, fine-tuning is relatively inexpensive. All of the results in the paper can be replicated in at most 1 hour on a single Cloud TPU, or a few hours on a GPU, starting from the exact same pre-trained model.7 7 7 For example, the BERT SQuAD model can be trained in around 30 minutes on a single Cloud TPU to achieve a Dev F1 score of 91.0%. We describe the task-specific details in the corresponding subsections of Section[4](https://arxiv.org/html/1810.04805#S4 "4 Experiments ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"). More details can be found in Appendix[A.5](https://arxiv.org/html/1810.04805#A1.SS5 "A.5 Illustrations of Fine-tuning on Different Tasks ‣ Appendix A Additional Details for BERT ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding").
|
| 116 |
+
|
| 117 |
+
Table 1: GLUE Test results, scored by the evaluation server ([https://gluebenchmark.com/leaderboard](https://gluebenchmark.com/leaderboard)). The number below each task denotes the number of training examples. The “Average” column is slightly different than the official GLUE score, since we exclude the problematic WNLI set.9 9 9 See question 10 in [https://gluebenchmark.com/faq](https://gluebenchmark.com/faq). BERT and OpenAI GPT are single-model, single task. F1 scores are reported for QQP and MRPC, Spearman correlations are reported for STS-B, and accuracy scores are reported for the other tasks. We exclude entries that use BERT as one of their components.
|
| 118 |
+
|
| 119 |
+
9 9 footnotetext: See (10) in [https://gluebenchmark.com/faq](https://gluebenchmark.com/faq).
|
| 120 |
+
4 Experiments
|
| 121 |
+
-------------
|
| 122 |
+
|
| 123 |
+
In this section, we present BERT fine-tuning results on 11 NLP tasks.
|
| 124 |
+
|
| 125 |
+
### 4.1 GLUE
|
| 126 |
+
|
| 127 |
+
The General Language Understanding Evaluation (GLUE) benchmark Wang et al. ([2018a](https://arxiv.org/html/1810.04805#bib.bib48)) is a collection of diverse natural language understanding tasks. Detailed descriptions of GLUE datasets are included in Appendix[B.1](https://arxiv.org/html/1810.04805#A2.SS1 "B.1 Detailed Descriptions for the GLUE Benchmark Experiments. ‣ Appendix B Detailed Experimental Setup ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding").
|
| 128 |
+
|
| 129 |
+
To fine-tune on GLUE, we represent the input sequence (for single sentence or sentence pairs) as described in Section[3](https://arxiv.org/html/1810.04805#S3 "3 BERT ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"), and use the final hidden vector C∈ℝ H C\in\mathbb{R}^{H} corresponding to the first input token ([CLS]) as the aggregate representation. The only new parameters introduced during fine-tuning are classification layer weights W∈ℝ K×H W\in\mathbb{R}^{K\times H}, where K K is the number of labels. We compute a standard classification loss with C C and W W, i.e., log(softmax(CW T))\log({\rm softmax}(CW^{T})).
|
| 130 |
+
|
| 131 |
+
We use a batch size of 32 and fine-tune for 3 epochs over the data for all GLUE tasks. For each task, we selected the best fine-tuning learning rate (among 5e-5, 4e-5, 3e-5, and 2e-5) on the Dev set. Additionally, for BERT LARGE{}_{\textsc{LARGE}} we found that fine-tuning was sometimes unstable on small datasets, so we ran several random restarts and selected the best model on the Dev set. With random restarts, we use the same pre-trained checkpoint but perform different fine-tuning data shuffling and classifier layer initialization.10 10 10 The GLUE data set distribution does not include the Test labels, and we only made a single GLUE evaluation server submission for each of BERT BASE{}_{\textsc{BASE}} and BERT LARGE{}_{\textsc{LARGE}}.
|
| 132 |
+
|
| 133 |
+
Results are presented in Table[9](https://arxiv.org/html/1810.04805#footnote9 "footnote 9 ‣ Table 1 ‣ 3.2 Fine-tuning BERT ‣ 3 BERT ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"). Both BERT BASE{}_{\textsc{BASE}} and BERT LARGE{}_{\textsc{LARGE}} outperform all systems on all tasks by a substantial margin, obtaining 4.5% and 7.0% respective average accuracy improvement over the prior state of the art. Note that BERT BASE{}_{\textsc{BASE}} and OpenAI GPT are nearly identical in terms of model architecture apart from the attention masking. For the largest and most widely reported GLUE task, MNLI, BERT obtains a 4.6% absolute accuracy improvement. On the official GLUE leaderboard 11 11 11 https://gluebenchmark.com/leaderboard, BERT LARGE{}_{\textsc{LARGE}} obtains a score of 80.5, compared to OpenAI GPT, which obtains 72.8 as of the date of writing.
|
| 134 |
+
|
| 135 |
+
We find that BERT LARGE{}_{\textsc{LARGE}} significantly outperforms BERT BASE{}_{\textsc{BASE}} across all tasks, especially those with very little training data. The effect of model size is explored more thoroughly in Section[5.2](https://arxiv.org/html/1810.04805#S5.SS2 "5.2 Effect of Model Size ‣ 5 Ablation Studies ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding").
|
| 136 |
+
|
| 137 |
+
### 4.2 SQuAD v1.1
|
| 138 |
+
|
| 139 |
+
The Stanford Question Answering Dataset (SQuAD v1.1) is a collection of 100k crowdsourced question/answer pairs Rajpurkar et al. ([2016](https://arxiv.org/html/1810.04805#bib.bib39)). Given a question and a passage from Wikipedia containing the answer, the task is to predict the answer text span in the passage.
|
| 140 |
+
|
| 141 |
+
As shown in Figure[1](https://arxiv.org/html/1810.04805#S2.F1 "Figure 1 ‣ 2.1 Unsupervised Feature-based Approaches ‣ 2 Related Work ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"), in the question answering task, we represent the input question and passage as a single packed sequence, with the question using the A embedding and the passage using the B embedding. We only introduce a start vector S∈ℝ H S\in\mathbb{R}^{H} and an end vector E∈ℝ H E\in\mathbb{R}^{H} during fine-tuning. The probability of word i i being the start of the answer span is computed as a dot product between T i T_{i} and S S followed by a softmax over all of the words in the paragraph: P i=e S⋅T i∑j e S⋅T j P_{i}=\frac{e^{S{\cdot}T_{i}}}{\sum_{j}e^{S{\cdot}T_{j}}}. The analogous formula is used for the end of the answer span. The score of a candidate span from position i i to position j j is defined as S⋅T i+E⋅T j S{\cdot}T_{i}+E{\cdot}T_{j}, and the maximum scoring span where j≥i j\geq i is used as a prediction. The training objective is the sum of the log-likelihoods of the correct start and end positions. We fine-tune for 3 epochs with a learning rate of 5e-5 and a batch size of 32.
|
| 142 |
+
|
| 143 |
+
Table 2: SQuAD 1.1 results. The BERT ensemble is 7x systems which use different pre-training checkpoints and fine-tuning seeds.
|
| 144 |
+
|
| 145 |
+
Table 3: SQuAD 2.0 results. We exclude entries that use BERT as one of their components.
|
| 146 |
+
|
| 147 |
+
Table[2](https://arxiv.org/html/1810.04805#S4.T2 "Table 2 ‣ 4.2 SQuAD v1.1 ‣ 4 Experiments ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding") shows top leaderboard entries as well as results from top published systems Seo et al. ([2017](https://arxiv.org/html/1810.04805#bib.bib40)); Clark and Gardner ([2018](https://arxiv.org/html/1810.04805#bib.bib11)); Peters et al. ([2018a](https://arxiv.org/html/1810.04805#bib.bib36)); Hu et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib22)). The top results from the SQuAD leaderboard do not have up-to-date public system descriptions available,12 12 12 QANet is described in Yu et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib54)), but the system has improved substantially after publication. and are allowed to use any public data when training their systems. We therefore use modest data augmentation in our system by first fine-tuning on TriviaQA Joshi et al. ([2017](https://arxiv.org/html/1810.04805#bib.bib24)) befor fine-tuning on SQuAD.
|
| 148 |
+
|
| 149 |
+
Our best performing system outperforms the top leaderboard system by +1.5 F1 in ensembling and +1.3 F1 as a single system. In fact, our single BERT model outperforms the top ensemble system in terms of F1 score. Without TriviaQA fine-tuning data, we only lose 0.1-0.4 F1, still outperforming all existing systems by a wide margin.13 13 13 The TriviaQA data we used consists of paragraphs from TriviaQA-Wiki formed of the first 400 tokens in documents, that contain at least one of the provided possible answers.
|
| 150 |
+
|
| 151 |
+
### 4.3 SQuAD v2.0
|
| 152 |
+
|
| 153 |
+
The SQuAD 2.0 task extends the SQuAD 1.1 problem definition by allowing for the possibility that no short answer exists in the provided paragraph, making the problem more realistic.
|
| 154 |
+
|
| 155 |
+
We use a simple approach to extend the SQuAD v1.1 BERT model for this task. We treat questions that do not have an answer as having an answer span with start and end at the [CLS] token. The probability space for the start and end answer span positions is extended to include the position of the [CLS] token. For prediction, we compare the score of the no-answer span: s 𝚗𝚞𝚕𝚕=S⋅C+E⋅C s_{\tt null}=S{\cdot}C+E{\cdot}C to the score of the best non-null span s i,j^\hat{s_{i,j}} = 𝚖𝚊𝚡 j≥iS⋅T i+E⋅T j{\tt max}_{j\geq i}S{\cdot}T_{i}+E{\cdot}T_{j}. We predict a non-null answer when s i,j^>s 𝚗𝚞𝚕𝚕+τ\hat{s_{i,j}}>s_{\tt null}+\tau, where the threshold τ\tau is selected on the dev set to maximize F1. We did not use TriviaQA data for this model. We fine-tuned for 2 epochs with a learning rate of 5e-5 and a batch size of 48.
|
| 156 |
+
|
| 157 |
+
The results compared to prior leaderboard entries and top published work Sun et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib42)); Wang et al. ([2018b](https://arxiv.org/html/1810.04805#bib.bib49)) are shown in Table[3](https://arxiv.org/html/1810.04805#S4.T3 "Table 3 ‣ 4.2 SQuAD v1.1 ‣ 4 Experiments ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"), excluding systems that use BERT as one of their components. We observe a +5.1 F1 improvement over the previous best system.
|
| 158 |
+
|
| 159 |
+
### 4.4 SWAG
|
| 160 |
+
|
| 161 |
+
The Situations With Adversarial Generations (SWAG) dataset contains 113k sentence-pair completion examples that evaluate grounded commonsense inference Zellers et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib55)). Given a sentence, the task is to choose the most plausible continuation among four choices.
|
| 162 |
+
|
| 163 |
+
When fine-tuning on the SWAG dataset, we construct four input sequences, each containing the concatenation of the given sentence (sentence A) and a possible continuation (sentence B). The only task-specific parameters introduced is a vector whose dot product with the [CLS] token representation C C denotes a score for each choice which is normalized with a softmax layer.
|
| 164 |
+
|
| 165 |
+
We fine-tune the model for 3 epochs with a learning rate of 2e-5 and a batch size of 16. Results are presented in Table[4](https://arxiv.org/html/1810.04805#S4.T4 "Table 4 ‣ 4.4 SWAG ‣ 4 Experiments ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"). BERT LARGE{}_{\textsc{LARGE}} outperforms the authors’ baseline ESIM+ELMo system by +27.1% and OpenAI GPT by 8.3%.
|
| 166 |
+
|
| 167 |
+
Table 4: SWAG Dev and Test accuracies. †Human performance is measured with 100 samples, as reported in the SWAG paper.
|
| 168 |
+
|
| 169 |
+
5 Ablation Studies
|
| 170 |
+
------------------
|
| 171 |
+
|
| 172 |
+
In this section, we perform ablation experiments over a number of facets of BERT in order to better understand their relative importance. Additional ablation studies can be found in Appendix[C](https://arxiv.org/html/1810.04805#A3 "Appendix C Additional Ablation Studies ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding").
|
| 173 |
+
|
| 174 |
+
### 5.1 Effect of Pre-training Tasks
|
| 175 |
+
|
| 176 |
+
We demonstrate the importance of the deep bidirectionality of BERT by evaluating two pre-training objectives using exactly the same pre-training data, fine-tuning scheme, and hyperparameters as BERT BASE{}_{\textsc{BASE}}:
|
| 177 |
+
|
| 178 |
+
No NSP: A bidirectional model which is trained using the “masked LM” (MLM) but without the “next sentence prediction” (NSP) task.
|
| 179 |
+
|
| 180 |
+
LTR & No NSP: A left-context-only model which is trained using a standard Left-to-Right (LTR) LM, rather than an MLM. The left-only constraint was also applied at fine-tuning, because removing it introduced a pre-train/fine-tune mismatch that degraded downstream performance. Additionally, this model was pre-trained without the NSP task. This is directly comparable to OpenAI GPT, but using our larger training dataset, our input representation, and our fine-tuning scheme.
|
| 181 |
+
|
| 182 |
+
Table 5: Ablation over the pre-training tasks using the BERT BASE{}_{\textsc{BASE}} architecture. “No NSP” is trained without the next sentence prediction task. “LTR & No NSP” is trained as a left-to-right LM without the next sentence prediction, like OpenAI GPT. “+ BiLSTM” adds a randomly initialized BiLSTM on top of the “LTR + No NSP” model during fine-tuning.
|
| 183 |
+
|
| 184 |
+
We first examine the impact brought by the NSP task. In Table[5](https://arxiv.org/html/1810.04805#S5.T5 "Table 5 ‣ 5.1 Effect of Pre-training Tasks ‣ 5 Ablation Studies ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"), we show that removing NSP hurts performance significantly on QNLI, MNLI, and SQuAD 1.1. Next, we evaluate the impact of training bidirectional representations by comparing “No NSP” to “LTR & No NSP”. The LTR model performs worse than the MLM model on all tasks, with large drops on MRPC and SQuAD.
|
| 185 |
+
|
| 186 |
+
For SQuAD it is intuitively clear that a LTR model will perform poorly at token predictions, since the token-level hidden states have no right-side context. In order to make a good faith attempt at strengthening the LTR system, we added a randomly initialized BiLSTM on top. This does significantly improve results on SQuAD, but the results are still far worse than those of the pre-trained bidirectional models. The BiLSTM hurts performance on the GLUE tasks.
|
| 187 |
+
|
| 188 |
+
We recognize that it would also be possible to train separate LTR and RTL models and represent each token as the concatenation of the two models, as ELMo does. However: (a) this is twice as expensive as a single bidirectional model; (b) this is non-intuitive for tasks like QA, since the RTL model would not be able to condition the answer on the question; (c) this it is strictly less powerful than a deep bidirectional model, since it can use both left and right context at every layer.
|
| 189 |
+
|
| 190 |
+
### 5.2 Effect of Model Size
|
| 191 |
+
|
| 192 |
+
In this section, we explore the effect of model size on fine-tuning task accuracy. We trained a number of BERT models with a differing number of layers, hidden units, and attention heads, while otherwise using the same hyperparameters and training procedure as described previously.
|
| 193 |
+
|
| 194 |
+
Results on selected GLUE tasks are shown in Table[6](https://arxiv.org/html/1810.04805#S5.T6 "Table 6 ‣ 5.2 Effect of Model Size ‣ 5 Ablation Studies ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"). In this table, we report the average Dev Set accuracy from 5 random restarts of fine-tuning. We can see that larger models lead to a strict accuracy improvement across all four datasets, even for MRPC which only has 3,600 labeled training examples, and is substantially different from the pre-training tasks. It is also perhaps surprising that we are able to achieve such significant improvements on top of models which are already quite large relative to the existing literature. For example, the largest Transformer explored in Vaswani et al. ([2017](https://arxiv.org/html/1810.04805#bib.bib46)) is (L=6, H=1024, A=16) with 100M parameters for the encoder, and the largest Transformer we have found in the literature is (L=64, H=512, A=2) with 235M parameters Al-Rfou et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib2)). By contrast, BERT BASE{}_{\textsc{BASE}} contains 110M parameters and BERT LARGE{}_{\textsc{LARGE}} contains 340M parameters.
|
| 195 |
+
|
| 196 |
+
Table 6: Ablation over BERT model size. #L = the number of layers; #H = hidden size; #A = number of attention heads. “LM (ppl)” is the masked LM perplexity of held-out training data.
|
| 197 |
+
|
| 198 |
+
It has long been known that increasing the model size will lead to continual improvements on large-scale tasks such as machine translation and language modeling, which is demonstrated by the LM perplexity of held-out training data shown in Table[6](https://arxiv.org/html/1810.04805#S5.T6 "Table 6 ‣ 5.2 Effect of Model Size ‣ 5 Ablation Studies ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"). However, we believe that this is the first work to demonstrate convincingly that scaling to extreme model sizes also leads to large improvements on very small scale tasks, provided that the model has been sufficiently pre-trained. Peters et al. ([2018b](https://arxiv.org/html/1810.04805#bib.bib37)) presented mixed results on the downstream task impact of increasing the pre-trained bi-LM size from two to four layers and Melamud et al. ([2016](https://arxiv.org/html/1810.04805#bib.bib30)) mentioned in passing that increasing hidden dimension size from 200 to 600 helped, but increasing further to 1,000 did not bring further improvements. Both of these prior works used a feature-based approach — we hypothesize that when the model is fine-tuned directly on the downstream tasks and uses only a very small number of randomly initialized additional parameters, the task-specific models can benefit from the larger, more expressive pre-trained representations even when downstream task data is very small.
|
| 199 |
+
|
| 200 |
+
### 5.3 Feature-based Approach with BERT
|
| 201 |
+
|
| 202 |
+
All of the BERT results presented so far have used the fine-tuning approach, where a simple classification layer is added to the pre-trained model, and all parameters are jointly fine-tuned on a downstream task. However, the feature-based approach, where fixed features are extracted from the pre-trained model, has certain advantages. First, not all tasks can be easily represented by a Transformer encoder architecture, and therefore require a task-specific model architecture to be added. Second, there are major computational benefits to pre-compute an expensive representation of the training data once and then run many experiments with cheaper models on top of this representation.
|
| 203 |
+
|
| 204 |
+
In this section, we compare the two approaches by applying BERT to the CoNLL-2003 Named Entity Recognition (NER) task Tjong Kim Sang and De Meulder ([2003](https://arxiv.org/html/1810.04805#bib.bib44)). In the input to BERT, we use a case-preserving WordPiece model, and we include the maximal document context provided by the data. Following standard practice, we formulate this as a tagging task but do not use a CRF layer in the output. We use the representation of the first sub-token as the input to the token-level classifier over the NER label set.
|
| 205 |
+
|
| 206 |
+
To ablate the fine-tuning approach, we apply the feature-based approach by extracting the activations from one or more layers without fine-tuning any parameters of BERT. These contextual embeddings are used as input to a randomly initialized two-layer 768-dimensional BiLSTM before the classification layer.
|
| 207 |
+
|
| 208 |
+
Results are presented in Table[7](https://arxiv.org/html/1810.04805#S5.T7 "Table 7 ‣ 5.3 Feature-based Approach with BERT ‣ 5 Ablation Studies ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"). BERT LARGE{}_{\textsc{LARGE}} performs competitively with state-of-the-art methods. The best performing method concatenates the token representations from the top four hidden layers of the pre-trained Transformer, which is only 0.3 F1 behind fine-tuning the entire model. This demonstrates that BERT is effective for both fine-tuning and feature-based approaches.
|
| 209 |
+
|
| 210 |
+
System Dev F1 Test F1
|
| 211 |
+
ELMo Peters et al. ([2018a](https://arxiv.org/html/1810.04805#bib.bib36))95.7 92.2
|
| 212 |
+
CVT Clark et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib12))-92.6
|
| 213 |
+
CSE Akbik et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib1))-93.1
|
| 214 |
+
Fine-tuning approach
|
| 215 |
+
BERT LARGE{}_{\textsc{LARGE}}96.6 92.8
|
| 216 |
+
BERT BASE{}_{\textsc{BASE}}96.4 92.4
|
| 217 |
+
Feature-based approach (BERT BASE{}_{\textsc{BASE}})
|
| 218 |
+
Embeddings 91.0-
|
| 219 |
+
Second-to-Last Hidden 95.6-
|
| 220 |
+
Last Hidden 94.9-
|
| 221 |
+
Weighted Sum Last Four Hidden 95.9-
|
| 222 |
+
Concat Last Four Hidden 96.1-
|
| 223 |
+
Weighted Sum All 12 Layers 95.5-
|
| 224 |
+
|
| 225 |
+
Table 7: CoNLL-2003 Named Entity Recognition results. Hyperparameters were selected using the Dev set. The reported Dev and Test scores are averaged over 5 random restarts using those hyperparameters.
|
| 226 |
+
|
| 227 |
+
6 Conclusion
|
| 228 |
+
------------
|
| 229 |
+
|
| 230 |
+
Recent empirical improvements due to transfer learning with language models have demonstrated that rich, unsupervised pre-training is an integral part of many language understanding systems. In particular, these results enable even low-resource tasks to benefit from deep unidirectional architectures. Our major contribution is further generalizing these findings to deep _bidirectional_ architectures, allowing the same pre-trained model to successfully tackle a broad set of NLP tasks.
|
| 231 |
+
|
| 232 |
+
References
|
| 233 |
+
----------
|
| 234 |
+
|
| 235 |
+
* Akbik et al. (2018) Alan Akbik, Duncan Blythe, and Roland Vollgraf. 2018. Contextual string embeddings for sequence labeling. In _Proceedings of the 27th International Conference on Computational Linguistics_, pages 1638–1649.
|
| 236 |
+
* Al-Rfou et al. (2018) Rami Al-Rfou, Dokook Choe, Noah Constant, Mandy Guo, and Llion Jones. 2018. Character-level language modeling with deeper self-attention. _arXiv preprint arXiv:1808.04444_.
|
| 237 |
+
* Ando and Zhang (2005) Rie Kubota Ando and Tong Zhang. 2005. A framework for learning predictive structures from multiple tasks and unlabeled data. _Journal of Machine Learning Research_, 6(Nov):1817–1853.
|
| 238 |
+
* Bentivogli et al. (2009) Luisa Bentivogli, Bernardo Magnini, Ido Dagan, Hoa Trang Dang, and Danilo Giampiccolo. 2009. The fifth PASCAL recognizing textual entailment challenge. In _TAC_. NIST.
|
| 239 |
+
* Blitzer et al. (2006) John Blitzer, Ryan McDonald, and Fernando Pereira. 2006. Domain adaptation with structural correspondence learning. In _Proceedings of the 2006 conference on empirical methods in natural language processing_, pages 120–128. Association for Computational Linguistics.
|
| 240 |
+
* Bowman et al. (2015) Samuel R. Bowman, Gabor Angeli, Christopher Potts, and Christopher D. Manning. 2015. A large annotated corpus for learning natural language inference. In _EMNLP_. Association for Computational Linguistics.
|
| 241 |
+
* Brown et al. (1992) Peter F Brown, Peter V Desouza, Robert L Mercer, Vincent J Della Pietra, and Jenifer C Lai. 1992. Class-based n-gram models of natural language. _Computational linguistics_, 18(4):467–479.
|
| 242 |
+
* Cer et al. (2017) Daniel Cer, Mona Diab, Eneko Agirre, Inigo Lopez-Gazpio, and Lucia Specia. 2017. [Semeval-2017 task 1: Semantic textual similarity multilingual and crosslingual focused evaluation](https://doi.org/10.18653/v1/S17-2001). In _Proceedings of the 11th International Workshop on Semantic Evaluation (SemEval-2017)_, pages 1–14, Vancouver, Canada. Association for Computational Linguistics.
|
| 243 |
+
* Chelba et al. (2013) Ciprian Chelba, Tomas Mikolov, Mike Schuster, Qi Ge, Thorsten Brants, Phillipp Koehn, and Tony Robinson. 2013. One billion word benchmark for measuring progress in statistical language modeling. _arXiv preprint arXiv:1312.3005_.
|
| 244 |
+
* Chen et al. (2018) Z.Chen, H.Zhang, X.Zhang, and L.Zhao. 2018. [Quora question pairs](https://data.quora.com/First-Quora-Dataset-Release-Question-Pairs).
|
| 245 |
+
* Clark and Gardner (2018) Christopher Clark and Matt Gardner. 2018. Simple and effective multi-paragraph reading comprehension. In _ACL_.
|
| 246 |
+
* Clark et al. (2018) Kevin Clark, Minh-Thang Luong, Christopher D Manning, and Quoc Le. 2018. Semi-supervised sequence modeling with cross-view training. In _Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing_, pages 1914–1925.
|
| 247 |
+
* Collobert and Weston (2008) Ronan Collobert and Jason Weston. 2008. A unified architecture for natural language processing: Deep neural networks with multitask learning. In _Proceedings of the 25th international conference on Machine learning_, pages 160–167. ACM.
|
| 248 |
+
* Conneau et al. (2017) Alexis Conneau, Douwe Kiela, Holger Schwenk, Loïc Barrault, and Antoine Bordes. 2017. [Supervised learning of universal sentence representations from natural language inference data](https://www.aclweb.org/anthology/D17-1070). In _Proceedings of the 2017 Conference on Empirical Methods in Natural Language Processing_, pages 670–680, Copenhagen, Denmark. Association for Computational Linguistics.
|
| 249 |
+
* Dai and Le (2015) Andrew M Dai and Quoc V Le. 2015. Semi-supervised sequence learning. In _Advances in neural information processing systems_, pages 3079–3087.
|
| 250 |
+
* Deng et al. (2009) J.Deng, W.Dong, R.Socher, L.-J. Li, K.Li, and L.Fei-Fei. 2009. ImageNet: A Large-Scale Hierarchical Image Database. In _CVPR09_.
|
| 251 |
+
* Dolan and Brockett (2005) William B Dolan and Chris Brockett. 2005. Automatically constructing a corpus of sentential paraphrases. In _Proceedings of the Third International Workshop on Paraphrasing (IWP2005)_.
|
| 252 |
+
* Fedus et al. (2018) William Fedus, Ian Goodfellow, and Andrew M Dai. 2018. Maskgan: Better text generation via filling in the_. _arXiv preprint arXiv:1801.07736_.
|
| 253 |
+
* Hendrycks and Gimpel (2016) Dan Hendrycks and Kevin Gimpel. 2016. [Bridging nonlinearities and stochastic regularizers with gaussian error linear units](http://arxiv.org/abs/1606.08415). _CoRR_, abs/1606.08415.
|
| 254 |
+
* Hill et al. (2016) Felix Hill, Kyunghyun Cho, and Anna Korhonen. 2016. Learning distributed representations of sentences from unlabelled data. In _Proceedings of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies_. Association for Computational Linguistics.
|
| 255 |
+
* Howard and Ruder (2018) Jeremy Howard and Sebastian Ruder. 2018. [Universal language model fine-tuning for text classification](http://arxiv.org/abs/1801.06146). In _ACL_. Association for Computational Linguistics.
|
| 256 |
+
* Hu et al. (2018) Minghao Hu, Yuxing Peng, Zhen Huang, Xipeng Qiu, Furu Wei, and Ming Zhou. 2018. Reinforced mnemonic reader for machine reading comprehension. In _IJCAI_.
|
| 257 |
+
* Jernite et al. (2017) Yacine Jernite, Samuel R. Bowman, and David Sontag. 2017. [Discourse-based objectives for fast unsupervised sentence representation learning](http://arxiv.org/abs/1705.00557). _CoRR_, abs/1705.00557.
|
| 258 |
+
* Joshi et al. (2017) Mandar Joshi, Eunsol Choi, Daniel S Weld, and Luke Zettlemoyer. 2017. Triviaqa: A large scale distantly supervised challenge dataset for reading comprehension. In _ACL_.
|
| 259 |
+
* Kiros et al. (2015) Ryan Kiros, Yukun Zhu, Ruslan R Salakhutdinov, Richard Zemel, Raquel Urtasun, Antonio Torralba, and Sanja Fidler. 2015. Skip-thought vectors. In _Advances in neural information processing systems_, pages 3294–3302.
|
| 260 |
+
* Le and Mikolov (2014) Quoc Le and Tomas Mikolov. 2014. Distributed representations of sentences and documents. In _International Conference on Machine Learning_, pages 1188–1196.
|
| 261 |
+
* Levesque et al. (2011) Hector J Levesque, Ernest Davis, and Leora Morgenstern. 2011. The winograd schema challenge. In _Aaai spring symposium: Logical formalizations of commonsense reasoning_, volume 46, page 47.
|
| 262 |
+
* Logeswaran and Lee (2018) Lajanugen Logeswaran and Honglak Lee. 2018. [An efficient framework for learning sentence representations](https://openreview.net/forum?id=rJvJXZb0W). In _International Conference on Learning Representations_.
|
| 263 |
+
* McCann et al. (2017) Bryan McCann, James Bradbury, Caiming Xiong, and Richard Socher. 2017. Learned in translation: Contextualized word vectors. In _NIPS_.
|
| 264 |
+
* Melamud et al. (2016) Oren Melamud, Jacob Goldberger, and Ido Dagan. 2016. context2vec: Learning generic context embedding with bidirectional LSTM. In _CoNLL_.
|
| 265 |
+
* Mikolov et al. (2013) Tomas Mikolov, Ilya Sutskever, Kai Chen, Greg S Corrado, and Jeff Dean. 2013. Distributed representations of words and phrases and their compositionality. In _Advances in Neural Information Processing Systems 26_, pages 3111–3119. Curran Associates, Inc.
|
| 266 |
+
* Mnih and Hinton (2009) Andriy Mnih and Geoffrey E Hinton. 2009. [A scalable hierarchical distributed language model](http://papers.nips.cc/paper/3583-a-scalable-hierarchical-distributed-language-model.pdf). In D.Koller, D.Schuurmans, Y.Bengio, and L.Bottou, editors, _Advances in Neural Information Processing Systems 21_, pages 1081–1088. Curran Associates, Inc.
|
| 267 |
+
* Parikh et al. (2016) Ankur P Parikh, Oscar Täckström, Dipanjan Das, and Jakob Uszkoreit. 2016. A decomposable attention model for natural language inference. In _EMNLP_.
|
| 268 |
+
* Pennington et al. (2014) Jeffrey Pennington, Richard Socher, and Christopher D. Manning. 2014. [Glove: Global vectors for word representation](http://www.aclweb.org/anthology/D14-1162). In _Empirical Methods in Natural Language Processing (EMNLP)_, pages 1532–1543.
|
| 269 |
+
* Peters et al. (2017) Matthew Peters, Waleed Ammar, Chandra Bhagavatula, and Russell Power. 2017. Semi-supervised sequence tagging with bidirectional language models. In _ACL_.
|
| 270 |
+
* Peters et al. (2018a) Matthew Peters, Mark Neumann, Mohit Iyyer, Matt Gardner, Christopher Clark, Kenton Lee, and Luke Zettlemoyer. 2018a. Deep contextualized word representations. In _NAACL_.
|
| 271 |
+
* Peters et al. (2018b) Matthew Peters, Mark Neumann, Luke Zettlemoyer, and Wen-tau Yih. 2018b. Dissecting contextual word embeddings: Architecture and representation. In _Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing_, pages 1499–1509.
|
| 272 |
+
* Radford et al. (2018) Alec Radford, Karthik Narasimhan, Tim Salimans, and Ilya Sutskever. 2018. Improving language understanding with unsupervised learning. Technical report, OpenAI.
|
| 273 |
+
* Rajpurkar et al. (2016) Pranav Rajpurkar, Jian Zhang, Konstantin Lopyrev, and Percy Liang. 2016. Squad: 100,000+ questions for machine comprehension of text. In _Proceedings of the 2016 Conference on Empirical Methods in Natural Language Processing_, pages 2383–2392.
|
| 274 |
+
* Seo et al. (2017) Minjoon Seo, Aniruddha Kembhavi, Ali Farhadi, and Hannaneh Hajishirzi. 2017. Bidirectional attention flow for machine comprehension. In _ICLR_.
|
| 275 |
+
* Socher et al. (2013) Richard Socher, Alex Perelygin, Jean Wu, Jason Chuang, Christopher D Manning, Andrew Ng, and Christopher Potts. 2013. Recursive deep models for semantic compositionality over a sentiment treebank. In _Proceedings of the 2013 conference on empirical methods in natural language processing_, pages 1631–1642.
|
| 276 |
+
* Sun et al. (2018) Fu Sun, Linyang Li, Xipeng Qiu, and Yang Liu. 2018. U-net: Machine reading comprehension with unanswerable questions. _arXiv preprint arXiv:1810.06638_.
|
| 277 |
+
* Taylor (1953) Wilson L Taylor. 1953. “Cloze procedure”: A new tool for measuring readability. _Journalism Bulletin_, 30(4):415–433.
|
| 278 |
+
* Tjong Kim Sang and De Meulder (2003) Erik F Tjong Kim Sang and Fien De Meulder. 2003. Introduction to the conll-2003 shared task: Language-independent named entity recognition. In _CoNLL_.
|
| 279 |
+
* Turian et al. (2010) Joseph Turian, Lev Ratinov, and Yoshua Bengio. 2010. Word representations: A simple and general method for semi-supervised learning. In _Proceedings of the 48th Annual Meeting of the Association for Computational Linguistics_, ACL ’10, pages 384–394.
|
| 280 |
+
* Vaswani et al. (2017) Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N Gomez, Lukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In _Advances in Neural Information Processing Systems_, pages 6000–6010.
|
| 281 |
+
* Vincent et al. (2008) Pascal Vincent, Hugo Larochelle, Yoshua Bengio, and Pierre-Antoine Manzagol. 2008. Extracting and composing robust features with denoising autoencoders. In _Proceedings of the 25th international conference on Machine learning_, pages 1096–1103. ACM.
|
| 282 |
+
* Wang et al. (2018a) Alex Wang, Amanpreet Singh, Julian Michael, Felix Hill, Omer Levy, and Samuel Bowman. 2018a. Glue: A multi-task benchmark and analysis platform for natural language understanding. In _Proceedings of the 2018 EMNLP Workshop BlackboxNLP: Analyzing and Interpreting Neural Networks for NLP_, pages 353–355.
|
| 283 |
+
* Wang et al. (2018b) Wei Wang, Ming Yan, and Chen Wu. 2018b. Multi-granularity hierarchical attention fusion networks for reading comprehension and question answering. In _Proceedings of the 56th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)_. Association for Computational Linguistics.
|
| 284 |
+
* Warstadt et al. (2018) Alex Warstadt, Amanpreet Singh, and Samuel R Bowman. 2018. Neural network acceptability judgments. _arXiv preprint arXiv:1805.12471_.
|
| 285 |
+
* Williams et al. (2018) Adina Williams, Nikita Nangia, and Samuel R Bowman. 2018. A broad-coverage challenge corpus for sentence understanding through inference. In _NAACL_.
|
| 286 |
+
* Wu et al. (2016) Yonghui Wu, Mike Schuster, Zhifeng Chen, Quoc V Le, Mohammad Norouzi, Wolfgang Macherey, Maxim Krikun, Yuan Cao, Qin Gao, Klaus Macherey, et al. 2016. Google’s neural machine translation system: Bridging the gap between human and machine translation. _arXiv preprint arXiv:1609.08144_.
|
| 287 |
+
* Yosinski et al. (2014) Jason Yosinski, Jeff Clune, Yoshua Bengio, and Hod Lipson. 2014. How transferable are features in deep neural networks? In _Advances in neural information processing systems_, pages 3320–3328.
|
| 288 |
+
* Yu et al. (2018) Adams Wei Yu, David Dohan, Minh-Thang Luong, Rui Zhao, Kai Chen, Mohammad Norouzi, and Quoc V Le. 2018. QANet: Combining local convolution with global self-attention for reading comprehension. In _ICLR_.
|
| 289 |
+
* Zellers et al. (2018) Rowan Zellers, Yonatan Bisk, Roy Schwartz, and Yejin Choi. 2018. Swag: A large-scale adversarial dataset for grounded commonsense inference. In _Proceedings of the 2018 Conference on Empirical Methods in Natural Language Processing (EMNLP)_.
|
| 290 |
+
* Zhu et al. (2015) Yukun Zhu, Ryan Kiros, Rich Zemel, Ruslan Salakhutdinov, Raquel Urtasun, Antonio Torralba, and Sanja Fidler. 2015. Aligning books and movies: Towards story-like visual explanations by watching movies and reading books. In _Proceedings of the IEEE international conference on computer vision_, pages 19–27.
|
| 291 |
+
|
| 292 |
+
Appendix for “BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding”
|
| 293 |
+
|
| 294 |
+
We organize the appendix into three sections:
|
| 295 |
+
|
| 296 |
+
* •
|
| 297 |
+
Additional implementation details for BERT are presented in Appendix[A](https://arxiv.org/html/1810.04805#A1 "Appendix A Additional Details for BERT ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding");
|
| 298 |
+
|
| 299 |
+
* •
|
| 300 |
+
Additional details for our experiments are presented in Appendix[B](https://arxiv.org/html/1810.04805#A2 "Appendix B Detailed Experimental Setup ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"); and
|
| 301 |
+
|
| 302 |
+
* •
|
| 303 |
+
Additional ablation studies are presented in Appendix[C](https://arxiv.org/html/1810.04805#A3 "Appendix C Additional Ablation Studies ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding").
|
| 304 |
+
|
| 305 |
+
We present additional ablation studies for BERT including:
|
| 306 |
+
|
| 307 |
+
* –
|
| 308 |
+
Effect of Number of Training Steps; and
|
| 309 |
+
|
| 310 |
+
* –
|
| 311 |
+
Ablation for Different Masking Procedures.
|
| 312 |
+
|
| 313 |
+
Appendix A Additional Details for BERT
|
| 314 |
+
--------------------------------------
|
| 315 |
+
|
| 316 |
+

|
| 317 |
+
|
| 318 |
+
Figure 3: Differences in pre-training model architectures. BERT uses a bidirectional Transformer. OpenAI GPT uses a left-to-right Transformer. ELMo uses the concatenation of independently trained left-to-right and right-to-left LSTMs to generate features for downstream tasks. Among the three, only BERT representations are jointly conditioned on both left and right context in all layers. In addition to the architecture differences, BERT and OpenAI GPT are fine-tuning approaches, while ELMo is a feature-based approach.
|
| 319 |
+
|
| 320 |
+
### A.1 Illustration of the Pre-training Tasks
|
| 321 |
+
|
| 322 |
+
We provide examples of the pre-training tasks in the following.
|
| 323 |
+
|
| 324 |
+
#### Masked LM and the Masking Procedure
|
| 325 |
+
|
| 326 |
+
Assuming the unlabeled sentence is my dog is hairy, and during the random masking procedure we chose the 4-th token (which corresponding to hairy), our masking procedure can be further illustrated by
|
| 327 |
+
|
| 328 |
+
* •
|
| 329 |
+
80% of the time: Replace the word with the [MASK] token, e.g., my dog is hairy →\rightarrow my dog is [MASK]
|
| 330 |
+
|
| 331 |
+
* •
|
| 332 |
+
10% of the time: Replace the word with a random word, e.g., my dog is hairy →\rightarrow my dog is apple
|
| 333 |
+
|
| 334 |
+
* •
|
| 335 |
+
10% of the time: Keep the word unchanged, e.g., my dog is hairy →\rightarrow my dog is hairy. The purpose of this is to bias the representation towards the actual observed word.
|
| 336 |
+
|
| 337 |
+
The advantage of this procedure is that the Transformer encoder does not know which words it will be asked to predict or which have been replaced by random words, so it is forced to keep a distributional contextual representation of every input token. Additionally, because random replacement only occurs for 1.5% of all tokens (i.e., 10% of 15%), this does not seem to harm the model’s language understanding capability. In Section[C.2](https://arxiv.org/html/1810.04805#A3.SS2 "C.2 Ablation for Different Masking Procedures ‣ Appendix C Additional Ablation Studies ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"), we evaluate the impact this procedure.
|
| 338 |
+
|
| 339 |
+
Compared to standard langauge model training, the masked LM only make predictions on 15% of tokens in each batch, which suggests that more pre-training steps may be required for the model to converge. In Section[C.1](https://arxiv.org/html/1810.04805#A3.SS1 "C.1 Effect of Number of Training Steps ‣ Appendix C Additional Ablation Studies ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding") we demonstrate that MLM does converge marginally slower than a left-to-right model (which predicts every token), but the empirical improvements of the MLM model far outweigh the increased training cost.
|
| 340 |
+
|
| 341 |
+
#### Next Sentence Prediction
|
| 342 |
+
|
| 343 |
+
The next sentence prediction task can be illustrated in the following examples.
|
| 344 |
+
|
| 345 |
+
Input=[CLS] the man went to [MASK] store [SEP]\displaystyle=\text{\tt{[CLS] the man went to [MASK] store [SEP]}}
|
| 346 |
+
he bought a gallon [MASK] milk [SEP]
|
| 347 |
+
Label=IsNext\displaystyle=\text{\tt{IsNext}}
|
| 348 |
+
Input=[CLS] the man [MASK] to the store [SEP]\displaystyle=\text{\tt{[CLS] the man [MASK] to the store [SEP]}}
|
| 349 |
+
penguin [MASK] are flight ##less birds [SEP]
|
| 350 |
+
Label=NotNext\displaystyle=\text{\tt{NotNext}}
|
| 351 |
+
|
| 352 |
+
### A.2 Pre-training Procedure
|
| 353 |
+
|
| 354 |
+
To generate each training input sequence, we sample two spans of text from the corpus, which we refer to as “sentences” even though they are typically much longer than single sentences (but can be shorter also). The first sentence receives the A embedding and the second receives the B embedding. 50% of the time B is the actual next sentence that follows A and 50% of the time it is a random sentence, which is done for the “next sentence prediction” task. They are sampled such that the combined length is ≤\leq 512 tokens. The LM masking is applied after WordPiece tokenization with a uniform masking rate of 15%, and no special consideration given to partial word pieces.
|
| 355 |
+
|
| 356 |
+
We train with batch size of 256 sequences (256 sequences * 512 tokens = 128,000 tokens/batch) for 1,000,000 steps, which is approximately 40 epochs over the 3.3 billion word corpus. We use Adam with learning rate of 1e-4, β 1=0.9{\beta}_{1}=0.9, β 2=0.999{\beta}_{2}=0.999, L2 weight decay of 0.01 0.01, learning rate warmup over the first 10,000 steps, and linear decay of the learning rate. We use a dropout probability of 0.1 on all layers. We use a gelu activation Hendrycks and Gimpel ([2016](https://arxiv.org/html/1810.04805#bib.bib19)) rather than the standard relu, following OpenAI GPT. The training loss is the sum of the mean masked LM likelihood and the mean next sentence prediction likelihood.
|
| 357 |
+
|
| 358 |
+
Training of BERT BASE{}_{\textsc{BASE}} was performed on 4 Cloud TPUs in Pod configuration (16 TPU chips total).14 14 14 https://cloudplatform.googleblog.com/2018/06/Cloud-TPU-now-offers-preemptible-pricing-and-global-availability.html Training of BERT LARGE{}_{\textsc{LARGE}} was performed on 16 Cloud TPUs (64 TPU chips total). Each pre-training took 4 days to complete.
|
| 359 |
+
|
| 360 |
+
Longer sequences are disproportionately expensive because attention is quadratic to the sequence length. To speed up pretraing in our experiments, we pre-train the model with sequence length of 128 for 90% of the steps. Then, we train the rest 10% of the steps of sequence of 512 to learn the positional embeddings.
|
| 361 |
+
|
| 362 |
+
### A.3 Fine-tuning Procedure
|
| 363 |
+
|
| 364 |
+
For fine-tuning, most model hyperparameters are the same as in pre-training, with the exception of the batch size, learning rate, and number of training epochs. The dropout probability was always kept at 0.1. The optimal hyperparameter values are task-specific, but we found the following range of possible values to work well across all tasks:
|
| 365 |
+
|
| 366 |
+
* •
|
| 367 |
+
Batch size: 16, 32
|
| 368 |
+
|
| 369 |
+
* •
|
| 370 |
+
Learning rate (Adam): 5e-5, 3e-5, 2e-5
|
| 371 |
+
|
| 372 |
+
* •
|
| 373 |
+
Number of epochs: 2, 3, 4
|
| 374 |
+
|
| 375 |
+
We also observed that large data sets (e.g., 100k+ labeled training examples) were far less sensitive to hyperparameter choice than small data sets. Fine-tuning is typically very fast, so it is reasonable to simply run an exhaustive search over the above parameters and choose the model that performs best on the development set.
|
| 376 |
+
|
| 377 |
+
### A.4 Comparison of BERT, ELMo ,and OpenAI GPT
|
| 378 |
+
|
| 379 |
+
Here we studies the differences in recent popular representation learning models including ELMo, OpenAI GPT and BERT. The comparisons between the model architectures are shown visually in Figure[3](https://arxiv.org/html/1810.04805#A1.F3 "Figure 3 ‣ Appendix A Additional Details for BERT ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"). Note that in addition to the architecture differences, BERT and OpenAI GPT are fine-tuning approaches, while ELMo is a feature-based approach.
|
| 380 |
+
|
| 381 |
+
The most comparable existing pre-training method to BERT is OpenAI GPT, which trains a left-to-right Transformer LM on a large text corpus. In fact, many of the design decisions in BERT were intentionally made to make it as close to GPT as possible so that the two methods could be minimally compared. The core argument of this work is that the bi-directionality and the two pre-training tasks presented in Section[3.1](https://arxiv.org/html/1810.04805#S3.SS1 "3.1 Pre-training BERT ‣ 3 BERT ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding") account for the majority of the empirical improvements, but we do note that there are several other differences between how BERT and GPT were trained:
|
| 382 |
+
|
| 383 |
+
* •
|
| 384 |
+
GPT is trained on the BooksCorpus (800M words); BERT is trained on the BooksCorpus (800M words) and Wikipedia (2,500M words).
|
| 385 |
+
|
| 386 |
+
* •
|
| 387 |
+
GPT uses a sentence separator ([SEP]) and classifier token ([CLS]) which are only introduced at fine-tuning time; BERT learns [SEP], [CLS] and sentence A/B embeddings during pre-training.
|
| 388 |
+
|
| 389 |
+
* •
|
| 390 |
+
GPT was trained for 1M steps with a batch size of 32,000 words; BERT was trained for 1M steps with a batch size of 128,000 words.
|
| 391 |
+
|
| 392 |
+
* •
|
| 393 |
+
GPT used the same learning rate of 5e-5 for all fine-tuning experiments; BERT chooses a task-specific fine-tuning learning rate which performs the best on the development set.
|
| 394 |
+
|
| 395 |
+
To isolate the effect of these differences, we perform ablation experiments in Section[5.1](https://arxiv.org/html/1810.04805#S5.SS1 "5.1 Effect of Pre-training Tasks ‣ 5 Ablation Studies ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding") which demonstrate that the majority of the improvements are in fact coming from the two pre-training tasks and the bidirectionality they enable.
|
| 396 |
+
|
| 397 |
+
### A.5 Illustrations of Fine-tuning on Different Tasks
|
| 398 |
+
|
| 399 |
+
The illustration of fine-tuning BERT on different tasks can be seen in Figure[4](https://arxiv.org/html/1810.04805#A1.F4 "Figure 4 ‣ A.5 Illustrations of Fine-tuning on Different Tasks ‣ Appendix A Additional Details for BERT ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"). Our task-specific models are formed by incorporating BERT with one additional output layer, so a minimal number of parameters need to be learned from scratch. Among the tasks, (a) and (b) are sequence-level tasks while (c) and (d) are token-level tasks. In the figure, E E represents the input embedding, T i T_{i} represents the contextual representation of token i i, [CLS] is the special symbol for classification output, and [SEP] is the special symbol to separate non-consecutive token sequences.
|
| 400 |
+
|
| 401 |
+

|
| 402 |
+
|
| 403 |
+
Figure 4: Illustrations of Fine-tuning BERT on Different Tasks.
|
| 404 |
+
|
| 405 |
+
Appendix B Detailed Experimental Setup
|
| 406 |
+
--------------------------------------
|
| 407 |
+
|
| 408 |
+
### B.1 Detailed Descriptions for the GLUE Benchmark Experiments.
|
| 409 |
+
|
| 410 |
+
#### MNLI
|
| 411 |
+
|
| 412 |
+
Multi-Genre Natural Language Inference is a large-scale, crowdsourced entailment classification task Williams et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib51)). Given a pair of sentences, the goal is to predict whether the second sentence is an entailment, contradiction, or neutral with respect to the first one.
|
| 413 |
+
|
| 414 |
+
#### QQP
|
| 415 |
+
|
| 416 |
+
Quora Question Pairs is a binary classification task where the goal is to determine if two questions asked on Quora are semantically equivalent Chen et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib10)).
|
| 417 |
+
|
| 418 |
+
#### QNLI
|
| 419 |
+
|
| 420 |
+
Question Natural Language Inference is a version of the Stanford Question Answering Dataset Rajpurkar et al. ([2016](https://arxiv.org/html/1810.04805#bib.bib39)) which has been converted to a binary classification task Wang et al. ([2018a](https://arxiv.org/html/1810.04805#bib.bib48)). The positive examples are (question, sentence) pairs which do contain the correct answer, and the negative examples are (question, sentence) from the same paragraph which do not contain the answer.
|
| 421 |
+
|
| 422 |
+
#### SST-2
|
| 423 |
+
|
| 424 |
+
The Stanford Sentiment Treebank is a binary single-sentence classification task consisting of sentences extracted from movie reviews with human annotations of their sentiment Socher et al. ([2013](https://arxiv.org/html/1810.04805#bib.bib41)).
|
| 425 |
+
|
| 426 |
+
#### CoLA
|
| 427 |
+
|
| 428 |
+
The Corpus of Linguistic Acceptability is a binary single-sentence classification task, where the goal is to predict whether an English sentence is linguistically “acceptable” or not Warstadt et al. ([2018](https://arxiv.org/html/1810.04805#bib.bib50)).
|
| 429 |
+
|
| 430 |
+
#### STS-B
|
| 431 |
+
|
| 432 |
+
The Semantic Textual Similarity Benchmark is a collection of sentence pairs drawn from news headlines and other sources Cer et al. ([2017](https://arxiv.org/html/1810.04805#bib.bib8)). They were annotated with a score from 1 to 5 denoting how similar the two sentences are in terms of semantic meaning.
|
| 433 |
+
|
| 434 |
+
#### MRPC
|
| 435 |
+
|
| 436 |
+
Microsoft Research Paraphrase Corpus consists of sentence pairs automatically extracted from online news sources, with human annotations for whether the sentences in the pair are semantically equivalent Dolan and Brockett ([2005](https://arxiv.org/html/1810.04805#bib.bib17)).
|
| 437 |
+
|
| 438 |
+
#### RTE
|
| 439 |
+
|
| 440 |
+
Recognizing Textual Entailment is a binary entailment task similar to MNLI, but with much less training data Bentivogli et al. ([2009](https://arxiv.org/html/1810.04805#bib.bib4)).15 15 15 Note that we only report single-task fine-tuning results in this paper. A multitask fine-tuning approach could potentially push the performance even further. For example, we did observe substantial improvements on RTE from multi-task training with MNLI.
|
| 441 |
+
|
| 442 |
+
#### WNLI
|
| 443 |
+
|
| 444 |
+
Winograd NLI is a small natural language inference dataset Levesque et al. ([2011](https://arxiv.org/html/1810.04805#bib.bib27)). The GLUE webpage notes that there are issues with the construction of this dataset,16 16 16[https://gluebenchmark.com/faq](https://gluebenchmark.com/faq) and every trained system that’s been submitted to GLUE has performed worse than the 65.1 baseline accuracy of predicting the majority class. We therefore exclude this set to be fair to OpenAI GPT. For our GLUE submission, we always predicted the majority class.
|
| 445 |
+
|
| 446 |
+
Appendix C Additional Ablation Studies
|
| 447 |
+
--------------------------------------
|
| 448 |
+
|
| 449 |
+
### C.1 Effect of Number of Training Steps
|
| 450 |
+
|
| 451 |
+
Figure[5](https://arxiv.org/html/1810.04805#A3.F5 "Figure 5 ‣ C.1 Effect of Number of Training Steps ‣ Appendix C Additional Ablation Studies ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding") presents MNLI Dev accuracy after fine-tuning from a checkpoint that has been pre-trained for k k steps. This allows us to answer the following questions:
|
| 452 |
+
|
| 453 |
+
Figure 5: Ablation over number of training steps. This shows the MNLI accuracy after fine-tuning, starting from model parameters that have been pre-trained for k k steps. The x-axis is the value of k k.
|
| 454 |
+
|
| 455 |
+
1. 1.
|
| 456 |
+
Question: Does BERT really need such a large amount of pre-training (128,000 words/batch * 1,000,000 steps) to achieve high fine-tuning accuracy?
|
| 457 |
+
|
| 458 |
+
Answer: Yes, BERT BASE{}_{\textsc{BASE}} achieves almost 1.0% additional accuracy on MNLI when trained on 1M steps compared to 500k steps.
|
| 459 |
+
|
| 460 |
+
2. 2.
|
| 461 |
+
Question: Does MLM pre-training converge slower than LTR pre-training, since only 15% of words are predicted in each batch rather than every word?
|
| 462 |
+
|
| 463 |
+
Answer: The MLM model does converge slightly slower than the LTR model. However, in terms of absolute accuracy the MLM model begins to outperform the LTR model almost immediately.
|
| 464 |
+
|
| 465 |
+
### C.2 Ablation for Different Masking Procedures
|
| 466 |
+
|
| 467 |
+
In Section[3.1](https://arxiv.org/html/1810.04805#S3.SS1 "3.1 Pre-training BERT ‣ 3 BERT ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"), we mention that BERT uses a mixed strategy for masking the target tokens when pre-training with the masked language model (MLM) objective. The following is an ablation study to evaluate the effect of different masking strategies.
|
| 468 |
+
|
| 469 |
+
Note that the purpose of the masking strategies is to reduce the mismatch between pre-training and fine-tuning, as the [MASK] symbol never appears during the fine-tuning stage. We report the Dev results for both MNLI and NER. For NER, we report both fine-tuning and feature-based approaches, as we expect the mismatch will be amplified for the feature-based approach as the model will not have the chance to adjust the representations.
|
| 470 |
+
|
| 471 |
+
Table 8: Ablation over different masking strategies.
|
| 472 |
+
|
| 473 |
+
The results are presented in Table[8](https://arxiv.org/html/1810.04805#A3.T8 "Table 8 ‣ C.2 Ablation for Different Masking Procedures ‣ Appendix C Additional Ablation Studies ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding"). In the table, Mask means that we replace the target token with the [MASK] symbol for MLM; Same means that we keep the target token as is; Rnd means that we replace the target token with another random token.
|
| 474 |
+
|
| 475 |
+
The numbers in the left part of the table represent the probabilities of the specific strategies used during MLM pre-training (BERT uses 80%, 10%, 10%). The right part of the paper represents the Dev set results. For the feature-based approach, we concatenate the last 4 layers of BERT as the features, which was shown to be the best approach in Section[5.3](https://arxiv.org/html/1810.04805#S5.SS3 "5.3 Feature-based Approach with BERT ‣ 5 Ablation Studies ‣ BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding").
|
| 476 |
+
|
| 477 |
+
From the table it can be seen that fine-tuning is surprisingly robust to different masking strategies. However, as expected, using only the Mask strategy was problematic when applying the feature-based approach to NER. Interestingly, using only the Rnd strategy performs much worse than our strategy as well.
|