BERT (Bidirectional Encoder Representations from Transformers) is a language model that stacks only the encoder of the Transformer and learns word representations using the context on both sides of a sentence. It was proposed by Devlin et al. at Google in 2018. It is "pre-trained" on large amounts of unlabeled text and then "fine-tuned" on a small amount of labeled data for tasks such as sentence classification and question answering.
Earlier pre-trained models had the following limitations.
- GPT: as a language model that predicts the next word from left to right, each word can only see the words to its left.
- ELMo: it trains left-to-right and right-to-left language models separately and only concatenates their outputs, so the context in both directions cannot be used at the same time inside the layers.
BERT is pre-trained on a task called the masked language model, which hides some of the input words and predicts the original words, so that every layer can use the context on both sides at once. It is also trained on next sentence prediction, which predicts whether two sentences are consecutive.
In the paper, simply adding one output layer to the pre-trained model and fine-tuning it produced state-of-the-art results on 11 natural language processing tasks at the time.

![Structure of BERT. Left: the overall flow of pre-training (input of [CLS], sentence A, [SEP], sentence B; the sum of three embeddings; repeated encoder layers; the two outputs for next sentence prediction and the masked language model) and the range of bidirectional attention, which can see every position. Right: the inside of an encoder layer (self-attention and feed-forward)](/note/images/articles/architectures/bert.en.png)