BERT:Bidirectional Encoder Representations from Transformers
BERT: Bidirectional Encoder Representations from Transformers
Motivation
- Unidirectional pre-training that fails to fully leverage the advantages of pre-trained representations
- For certain tasks, is a Transformer-based decoder really necessary?
- Is there a way to replace models that are task-specific, large, and complex in structure?
Proposal
⇒ Bidirectional Pre-training
: Proposes “deep Bidirectional” learning rather than the simple concatenation-based bidirectionality of ELMo
- MLM + NSP
⇒ Proposes an approach that achieves sufficient performance without a decoder, through autoencoder-style and bidirectional learning for context modeling
⇒ Proposes a method that enables simple fine-tuning based on a generalized pre-trained model
Model Architecture

- The input embedding is the sum of token embedding + segmentation embedding + position embedding.
- The model architecture is identical to the Transformer encoder, except that the input embedding is customized in the manner described above, and unlike the conventional approach, the position embedding becomes a learnable hyperparameter.
- Two special tokens are utilized:
- [CLS]: A token that comes at the beginning of the sequence, whose corresponding final hidden state is interpreted as the representation of the entire sequence in classification tasks.
- [SEP]: A token for distinguishing between sentences; based on this token, different segment embeddings are applied to separate the sentences from each other.
Pre-training
The pre-training process is carried out through two tasks conducted via unsupervised learning:
-
Masked Language Model (MLM)
: Randomly changes 15% of the input to [mask] tokens.
-
Next Sentence Prediction (NSP)
: Many downstream tasks are based on the relationship between two sentences. Representative examples include QA and Natural Language Inference. This is a task of determining whether two sentences separated by [sep] within a single sequence are consecutive sentences.
Fine-tuning
In the fine-tuning process, the self-attention mechanism of the Transformer-based architecture plays a major role. In short, fine-tuning becomes possible simply by “appropriately swapping the inputs and outputs.”
For tasks involving text pairs, the previous fine-tuning approach consisted of two steps: 1) independently encoding the text pair, and 2) applying bidirectional cross attention. BERT, however, attempts an approach that unifies these two steps by leveraging self-attention.
This is because BERT’s input structure, examined earlier, takes a text pair concatenated into a single sequence, and applying self-attention to it produces effectively the same result as applying bidirectional cross attention between the two sentences.
For each downstream task, the sentence pairs grouped into a single pair are distinguished as follows:
The paper also demonstrates how BERT can be fine-tuned for four types of downstream tasks:

- Sentence Pair Classification
- Entailment Classification Task (3 classes are entailment, contradiction, neutral)
- Natural Language Inference Task
- Paraphrasing Task
- Single Sentence Classification
- Determining whether a sentence is linguistically acceptable or not
- Sentiment analysis
- Q&A
- Sentence Tagging (classifying words within a sentence, e.g., Person, Location, …)
These four tasks differ slightly in their input/output form depending on whether they are Sequence-level tasks, Token-level tasks, or Q&A. In (a) and (b), which are Sequence-level tasks, the final hidden state of the [cls] token is fed as input to the classification layer.
In the case of (d), a Token-level task, it differs from the previous structure in that the output of the final hidden state of each token becomes the prediction for that token.
In the case of the Q&A task, in the input the question and answer are embedded as a single sequence separated by [sep], and in the output BERT predicts the start position and end position of the answer within the sequence. Here, the prediction is made by scoring, for each token, the likelihood that the answer starts or ends at that token.
References
https://happy-obok.tistory.com/23
https://medium.com/@hugmanskj/가장-성공적인-트랜스포머의-변형-bert와-gpt-소개-0b18fb7e563b