{"notes":[{"id":"transformers/bert","category":"transformers","legacyPath":"transformers/1810-bert","legacySlug":"1810-bert","legacyPaths":[],"title":"BERT","subtitle":"Twelve Layers of Encoders","author":"Z. Yuan","paperDate":"2018-10-11","publishedOn":"2024-05-12","paperTitle":"BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding","paperUrl":"https://arxiv.org/abs/1810.04805","bibliography":{"title":"BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding","authors":["Jacob Devlin","Ming-Wei Chang","Kenton Lee","Kristina Toutanova"],"url":"https://arxiv.org/abs/1810.04805","pdfUrl":"https://arxiv.org/pdf/1810.04805","codeUrl":null,"preprint":{"id":"1810.04805","submittedOn":"2018-10-11","url":"https://arxiv.org/abs/1810.04805"},"publication":{"venue":"NAACL-HLT","year":2019,"kind":"conference","url":"https://doi.org/10.18653/v1/n19-1423"},"citation":"@misc{transformersbert2018,\n  title = {{BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding}},\n  author = {Jacob Devlin and Ming-Wei Chang and Kenton Lee and Kristina Toutanova},\n  year = {2018},\n  eprint = {1810.04805},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/1810.04805}\n}\n","citationPath":"/content/papers/citations/transformers/bert.d9bf47a21c5f.bib"},"thumbnail":{"src":"/content/papers/assets/57ed95afec24d2732e290d4fcb5633e14a2bbe74b83c6b6cdee90ef44ac89411.jpg","width":1224,"height":396},"locale":"en","path":"/content/papers/en/transformers/bert.75ec0229da6b.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"unidirectionality","text":"Unidirectionality","depth":3},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"model-architecture","text":"Model Architecture","depth":3},{"id":"pre-training-strategy","text":"Pre-training Strategy","depth":3},{"id":"fine-tuning-strategy","text":"Fine-tuning Strategy","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"ablation-study","text":"Ablation Study","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"tags":["transformers","self-supervised-learning","model-tuning","google-research"],"relatedReading":[{"id":"transformers/transformer","relation":"background","topic":"Pretraining bidirectional language representations"},{"id":"transformers/roberta","relation":"next","topic":"Pretraining bidirectional language representations"},{"id":"transformers/albert","relation":"comparison","topic":"Training and compressing BERT"}]},{"id":"transformers/transformer","category":"transformers","legacyPath":"transformers/1706-transformer","legacySlug":"1706-transformer","legacyPaths":[],"title":"Transformer","subtitle":"The Dawn of a New Era","author":"Z. Yuan","paperDate":"2017-06-12","publishedOn":"2024-05-05","paperTitle":"Attention Is All You Need","paperUrl":"https://arxiv.org/abs/1706.03762","bibliography":{"title":"Attention Is All You Need","authors":["Ashish Vaswani","Noam Shazeer","Niki Parmar","Jakob Uszkoreit","Llion Jones","Aidan N. Gomez","Lukasz Kaiser","Illia Polosukhin"],"url":"https://arxiv.org/abs/1706.03762","pdfUrl":"https://arxiv.org/pdf/1706.03762","codeUrl":null,"preprint":{"id":"1706.03762","submittedOn":"2017-06-12","url":"https://arxiv.org/abs/1706.03762"},"publication":{"venue":"NeurIPS (NIPS)","year":2017,"kind":"conference","url":"https://proceedings.neurips.cc/paper_files/paper/2017/hash/3f5ee243547dee91fbd053c1c4a845aa-Abstract.html"},"citation":"@misc{transformerstransformer2017,\n  title = {{Attention Is All You Need}},\n  author = {Ashish Vaswani and Noam Shazeer and Niki Parmar and Jakob Uszkoreit and Llion Jones and Aidan N. Gomez and Lukasz Kaiser and Illia Polosukhin},\n  year = {2017},\n  eprint = {1706.03762},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/1706.03762}\n}\n","citationPath":"/content/papers/citations/transformers/transformer.86c0068d96fd.bib"},"thumbnail":{"src":"/content/papers/assets/29a55cb05497bdd9bbb3f3a96b7ed6656fda3552fa6a0fa5eb29e8e899c1acc1.jpg","width":756,"height":1080},"locale":"en","path":"/content/papers/en/transformers/transformer.420ab06f9af4.md","headings":[{"id":"problem-definition","text":"Problem Definition","depth":2},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"model-design","text":"Model Design","depth":3},{"id":"input-layer","text":"Input Layer","depth":3},{"id":"positional-encoding","text":"Positional Encoding","depth":3},{"id":"self-attention-mechanism","text":"Self-Attention Mechanism","depth":3},{"id":"multi-head-attention-mechanism","text":"Multi-Head Attention Mechanism","depth":3},{"id":"cross-attention-mechanism","text":"Cross-Attention Mechanism","depth":3},{"id":"feed-forward-network","text":"Feed-Forward Network","depth":3},{"id":"layer-normalization","text":"Layer Normalization","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"why-use-self-attention","text":"Why Use Self-Attention?","depth":3},{"id":"experimental-results-machine-translation","text":"Experimental Results: Machine Translation","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"tags":["transformers","position-encoding","attention-mechanisms","google-brain"],"relatedReading":[{"id":"transformers/flashattention","relation":"next","topic":"Attention memory and computation"},{"id":"transformers/bert","relation":"next","topic":"Pretraining bidirectional language representations"},{"id":"transformers/gpt_1","relation":"next","topic":"From language pretraining to in-context learning"}]},{"id":"transformers/roberta","category":"transformers","legacyPath":"transformers/1907-roberta","legacySlug":"1907-roberta","legacyPaths":[],"title":"RoBERTa","subtitle":"A Guide to Training BERT","author":"Z. Yuan","paperDate":"2019-07-26","publishedOn":"2024-09-26","paperTitle":"RoBERTa: A Robustly Optimized BERT Pretraining Approach","paperUrl":"https://arxiv.org/abs/1907.11692","bibliography":{"title":"RoBERTa: A Robustly Optimized BERT Pretraining Approach","authors":["Yinhan Liu","Myle Ott","Naman Goyal","Jingfei Du","Mandar Joshi","Danqi Chen","Omer Levy","Mike Lewis","Luke Zettlemoyer","Veselin Stoyanov"],"url":"https://arxiv.org/abs/1907.11692","pdfUrl":"https://arxiv.org/pdf/1907.11692","codeUrl":null,"preprint":{"id":"1907.11692","submittedOn":"2019-07-26","url":"https://arxiv.org/abs/1907.11692"},"publication":null,"citation":"@misc{transformersroberta2019,\n  title = {{RoBERTa: A Robustly Optimized BERT Pretraining Approach}},\n  author = {Yinhan Liu and Myle Ott and Naman Goyal and Jingfei Du and Mandar Joshi and Danqi Chen and Omer Levy and Mike Lewis and Luke Zettlemoyer and Veselin Stoyanov},\n  year = {2019},\n  eprint = {1907.11692},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/1907.11692}\n}\n","citationPath":"/content/papers/citations/transformers/roberta.704870f708c1.bib"},"thumbnail":{"src":"/content/papers/assets/cbf2bba8a99ec32ddf52a845f831eada66fc53f6337cd22a4fff68e4fc6bb2e4.jpg","width":1064,"height":452},"locale":"en","path":"/content/papers/en/transformers/roberta.20a92ad248ef.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"optimization-of-implementation-details","text":"Optimization of Implementation Details","depth":3},{"id":"optimizing-the-training-data","text":"Optimizing the Training Data","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"static-masking-vs-dynamic-masking","text":"Static Masking vs. Dynamic Masking","depth":3},{"id":"next-sentence-prediction-nsp","text":"Next Sentence Prediction (NSP)","depth":3},{"id":"large-batch-training","text":"Large Batch Training","depth":3},{"id":"tokenization","text":"Tokenization","depth":3},{"id":"training-data-size","text":"Training Data Size","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"tags":["transformers","self-supervised-learning","training-data","meta"],"relatedReading":[{"id":"transformers/bert","relation":"background","topic":"Pretraining bidirectional language representations"}]},{"id":"transformers/albert","category":"transformers","legacyPath":"transformers/1909-albert","legacySlug":"1909-albert","legacyPaths":[],"title":"ALBERT","subtitle":"A Compact Version of BERT","author":"Z. Yuan","paperDate":"2019-09-26","publishedOn":"2024-10-06","paperTitle":"ALBERT: A Lite BERT for Self-supervised Learning of Language Representations","paperUrl":"https://arxiv.org/abs/1909.11942","bibliography":{"title":"ALBERT: A Lite BERT for Self-supervised Learning of Language Representations","authors":["Zhenzhong Lan","Mingda Chen","Sebastian Goodman","Kevin Gimpel","Piyush Sharma","Radu Soricut"],"url":"https://arxiv.org/abs/1909.11942","pdfUrl":"https://arxiv.org/pdf/1909.11942","codeUrl":null,"preprint":{"id":"1909.11942","submittedOn":"2019-09-26","url":"https://arxiv.org/abs/1909.11942"},"publication":{"venue":"ICLR","year":2020,"kind":"conference","url":"https://openreview.net/pdf?id=H1eA7AEtvS"},"citation":"@misc{transformersalbert2019,\n  title = {{ALBERT: A Lite BERT for Self-supervised Learning of Language Representations}},\n  author = {Zhenzhong Lan and Mingda Chen and Sebastian Goodman and Kevin Gimpel and Piyush Sharma and Radu Soricut},\n  year = {2019},\n  eprint = {1909.11942},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/1909.11942}\n}\n","citationPath":"/content/papers/citations/transformers/albert.3c09dcfbefc4.bib"},"thumbnail":{"src":"/content/papers/assets/6c13f0edeaab781b103842ccb55907fe32c1e36e4e4de20c74f47071ea9039fd.jpg","width":1438,"height":484},"locale":"en","path":"/content/papers/en/transformers/albert.741bdf4eb55c.md","headings":[{"id":"the-problem","text":"The Problem","depth":2},{"id":"the-solution","text":"The Solution","depth":2},{"id":"factorized-embedding-parameterization","text":"Factorized Embedding Parameterization","depth":3},{"id":"cross-layer-parameter-sharing","text":"Cross-layer Parameter Sharing","depth":3},{"id":"sentence-order-prediction-loss-sop","text":"Sentence-Order Prediction Loss (SOP)","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"bert-vs-albert-overall-comparison","text":"BERT vs. ALBERT: Overall Comparison","depth":3},{"id":"embedding-parameter-factorization","text":"Embedding Parameter Factorization","depth":3},{"id":"cross-layer-parameter-sharing-1","text":"Cross-layer Parameter Sharing","depth":3},{"id":"the-effectiveness-of-sentence-order-prediction","text":"The Effectiveness of Sentence-Order Prediction","depth":3},{"id":"state-of-the-art-results-on-nlu-tasks","text":"State-of-the-art Results on NLU Tasks","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"tags":["transformers","self-supervised-learning","lightweight","google-research"],"relatedReading":[{"id":"transformers/bert","relation":"comparison","topic":"Training and compressing BERT"},{"id":"transformers/xlnet","relation":"comparison","topic":"Training and compressing BERT"}]}],"text":"After the introduction of the Transformer architecture, many researchers began exploring ways to better utilize it. GPT-1, discussed previously, opted for a decoder-only architecture. In contrast, BERT chose an encoder-only approach.\n\n\n> [!TIP]\n> \n> About half a year before BERT, there was a model called ELMo. Following the naming of BERT, researchers started a trend of naming models after Sesame Street characters. Initially, researchers seriously used titles to find acronyms, but later, they let their creativity fly, naming models whatever they liked...\n\n\n## Defining the Problem\n\nThere are generally two strategies for applying pre-trained language models to downstream tasks:\n\n1. **Feature-based methods:**\n\n   - Examples like ELMo ([Peters et al., 2018a](https://arxiv.org/abs/1802.05365)) use task-specific architectures that include pre-trained representations as additional features.\n\n2. **Fine-tuning methods:**\n   - Examples like OpenAI GPT introduce minimal task-specific parameters and train on the downstream tasks by simply fine-tuning all pre-trained parameters.\n\n---\n\nGPT uses a left-to-right language model; ELMo concatenates separately trained directional representations. They are not the same single language model, and neither jointly conditions every layer on both sides as BERT does.\n\n### Unidirectionality\n\nIn OpenAI GPT, a left-to-right architecture is used, where each token can only attend to previous tokens in the Transformer’s self-attention layers. This limitation is not ideal for sentence-level tasks and can be particularly detrimental when applying fine-tuning methods to token-level tasks, such as question answering, where incorporating context from both directions can significantly enhance performance.\n\n## Solving the Problem\n\n### Model Architecture\n\n![BERT input representation sums token, segment and position embeddings; original paper Figure 2](/content/papers/assets/57ed95afec24d2732e290d4fcb5633e14a2bbe74b83c6b6cdee90ef44ac89411.jpg)\n\n*Original paper [Figure 2](https://arxiv.org/pdf/1810.04805v2) shows the input representation, not the number of encoder layers: “my dog is cute” and “he likes playing” form segments A and B, and every position sums token, segment and position embeddings.*\n\nBERT itself is a bidirectional Transformer encoder. Base has 12 layers and Large has 24; BERT is not limited to the 12-layer configuration.\n\n- **BERT-Base:**\n\n  - 12 encoder layers, each following the basic Transformer structure.\n  - Each encoder layer has 768 hidden dimensions and 12 attention heads.\n  - Total parameter count is 110M.\n\n- **BERT-Large:**\n  - 24 encoder layers, each following the basic Transformer structure.\n  - Each encoder layer has 1024 hidden dimensions and 16 attention heads.\n  - Total parameter count is 340M.\n\nFor input data, BERT uses several strategies:\n\n1. **Flexible definition of input sequences:** In BERT, a \"sentence\" can refer to any range of continuous text, and \"sequence\" refers to the input token sequence BERT processes, which may include one or two sentences.\n\n2. **WordPiece embeddings:** Using a 30,000-token WordPiece vocabulary ([**Wu et al., 2016**](https://arxiv.org/abs/1609.08144)) to handle unknown or rare words effectively.\n\n3. **Special tokens:**\n\n   - **[CLS] token:** The first token of every sequence, used as the representation for classification tasks.\n   - **[SEP] token:** Used to separate pairs of sentences, helping BERT distinguish and process information from different sentences.\n   - **[MASK] token:** Used in pre-training to randomly mask some tokens for the model to predict.\n\n4. **Sentence separation features:** Besides the [SEP] token, BERT adds a learned segment embedding to each token to indicate whether it belongs to sentence A or B. The position embedding shown in the figure is added as well.\n\n### Pre-training Strategy\n\n![BERT MLM and NSP pre-training and downstream fine-tuning; original paper Figure 1](/content/papers/assets/d10b890e1a78a3e5e250f27d666182eb1018e6f281aab0362fca16693d45f07a.jpg)\n\n*Original paper [Figure 1](https://arxiv.org/pdf/1810.04805v2): the left side trains with MLM and NSP; the right shows separate fine-tuning for MNLI, NER and SQuAD from the same pre-trained weights.*\n\nThe left side is pre-training and the right is fine-tuning. Both stages use the encoder; the output layer and parameter updates depend on the task. BERT's pre-training strategy influenced many subsequent models.\n\nPre-training uses BooksCorpus and English Wikipedia. The model learns the following two objectives together.\n\n- **Masked Language Model (MLM):**\n\n  - BERT uses the masked language model (also known as the cloze task) to train deep bidirectional representations. In this task, a certain percentage of input tokens are randomly masked, and the goal is to predict these masked tokens.\n  - **Random masking strategy:** About 15% of WordPiece tokens in each input sequence are randomly selected for masking. In 80% of cases, selected tokens are replaced with the [MASK] token, in 10% of cases with random tokens, and in the remaining 10% of cases, they are kept unchanged.\n  - **Predicting masked tokens:** For each masked token, BERT uses the corresponding final hidden vector through an output softmax layer to predict the original token, similar to traditional language models.\n  - **Mitigating pre-training and fine-tuning mismatch:** Since [MASK] tokens are used during pre-training but not during fine-tuning, this creates a theoretical mismatch. BERT mitigates this by not always replacing selected tokens with actual [MASK] tokens but instead using a random strategy.\n\n- **Next Sentence Prediction (NSP):**\n  - To help the model better understand and capture sentence relationships, BERT introduces the next sentence prediction pre-training task.\n  - Half the examples use the actual next segment B after A (**IsNext**); the other half use a randomly sampled B (**NotNext**). The model predicts this label from [CLS]. NSP supervises adjacency under that sampling scheme, not logical entailment or general semantic relatedness.\n  - The paper's ablation finds a benefit for some downstream evaluations under this setup.\n\n### Fine-tuning Strategy\n\n![BERT pre-training and fine-tuning for SQuAD and other tasks; original paper Figure 1](/content/papers/assets/d10b890e1a78a3e5e250f27d666182eb1018e6f281aab0362fca16693d45f07a.jpg)\n\nLook again at the right half of Figure 1: each downstream model starts from the same pre-trained weights and then updates those weights along with its task-specific output layer. That output is not always a classification layer: classification reads [CLS], while question answering uses token representations.\n\n- **Question Answering (SQuAD):**\n\n  - In question answering tasks, BERT processes the question and the paragraph containing the answer as a single sequence, using different embeddings to identify the question and paragraph parts. During fine-tuning, BERT introduces specific start and end vectors to predict the answer's position within the paragraph.\n\n- **Natural Language Inference (NLI):**\n  - NLI packs both sentences into `[CLS] A [SEP] B [SEP]` and classifies from the final `[CLS]` representation, rather than independently encoding and concatenating two sentence vectors.\n\nThe paper reports that fine-tuning its downstream experiments from the same pre-trained checkpoint took at most about one hour on a single Cloud TPU, or a few hours on a GPU. That is fine-tuning time under the paper's conditions; it does not include pre-training.\n\n## Discussion\n\n![BERT versus GPT and other models on GLUE test; original paper Table 1](/content/papers/assets/8dfb86b24c336357cd753d6cfbe7be6b5e8e6481ea28dd81dd04d17a633c0225.jpg)\n\n*Original paper [Table 1](https://arxiv.org/pdf/1810.04805v2) gives per-task **GLUE test** results. Its Average column excludes WNLI and is distinct from the official leaderboard score.*\n\nRead the last column first: **82.1** for BERT-Large and **75.1** for GPT are the **table averages excluding WNLI**. For MNLI-m, the scores are **86.7%** and **82.1%**, respectively. The text separately reports official GLUE leaderboard scores of **80.5** and **72.8** at the time; those are not MNLI scores either. Large beats Base on the tasks in the table, including those with fewer labels. Fine-tuning Large on small datasets was sometimes unstable, however, and the authors selected the best development result from multiple random restarts.\n\nMoreover, BERT set new state-of-the-art results on 11 different NLP tasks, demonstrating its versatility and effectiveness across various tasks.\n\n### Ablation Study\n\n![BERT-Base pre-training task ablation; original paper Table 5](/content/papers/assets/f1530ee9531460abc59ca58666332208e0b33bc7fa03f469f8442eb23b52dc8f.jpg)\n\n*Original paper [Table 5](https://arxiv.org/pdf/1810.04805v2) reports **development-set** ablations for BERT-Base, separate from the test results in Table 1.*\n\nThe authors compare pre-training objectives and directional constraints under the same architecture. Which scores change?\n\n1. **Without NSP:**\n\n   - This remains a bidirectional MLM, but removes NSP. Against full BERT-Base, QNLI drops **88.4→84.9**, MNLI-m **84.4→83.9**, and SQuAD 1.1 F1 **88.5→87.9**. These are results under the paper's training and data setup, not a requirement that every later model use NSP.\n\n2. **LTR & Without NSP:**\n\n   - A model trained with a left-to-right (LTR) language model without MLM or NSP, retaining its left-only attention restriction during fine-tuning. Against bidirectional MLM without NSP, all listed task scores drop; MRPC **86.5→77.5** and SQuAD F1 **87.9→77.8** show the largest gaps.\n   - On SQuAD, the LTR model’s token prediction performance was significantly worse due to the lack of right-side context support.\n\n3. **Adding BiLSTM:**\n\n   - A randomly initialized BiLSTM is added to the LTR system **during fine-tuning**. SQuAD F1 rises **77.8→84.9**, still below bidirectional MLM without NSP at **87.9**; all four listed GLUE development scores fall.\n\n4. **Comparison with ELMo’s Strategy:**\n   - The authors discuss separately training and concatenating LTR/RTL models, as in ELMo. This is an alternative they analyze, not an additional measured ablation in the table. It needs two directional models and does not jointly mix both contexts at every layer.\n\n## Conclusion\n\nBERT drew attention through strong results across many benchmarks. Reading those results at the time felt like watching a clean sweep. It helped shift NLP research toward Transformers, without making LSTMs disappear from every research area or application.\n\nThe paper makes a more specific point: with its data and tasks, bidirectional MLM followed by fine-tuning lets the same pre-trained weights serve different language-understanding tasks. The benefits of NSP and model size still need to be read with their evaluation conditions.\n","imageSizes":{"/content/papers/assets/57ed95afec24d2732e290d4fcb5633e14a2bbe74b83c6b6cdee90ef44ac89411.jpg":{"width":1224,"height":396},"/content/papers/assets/d10b890e1a78a3e5e250f27d666182eb1018e6f281aab0362fca16693d45f07a.jpg":{"width":1224,"height":488},"/content/papers/assets/8dfb86b24c336357cd753d6cfbe7be6b5e8e6481ea28dd81dd04d17a633c0225.jpg":{"width":1224,"height":280},"/content/papers/assets/f1530ee9531460abc59ca58666332208e0b33bc7fa03f469f8442eb23b52dc8f.jpg":{"width":968,"height":414}}}
