{"notes":[{"id":"transformers/gpt_2","category":"transformers","legacyPath":"transformers/1902-gpt_2","legacySlug":"1902-gpt_2","legacyPaths":[],"title":"GPT-2","subtitle":"Forty-Eight Layers of Decoders","author":"Z. Yuan","paperDate":"2019","publishedOn":"2024-05-24","paperTitle":"Language models are unsupervised multitask learners","paperUrl":"https://openai.com/index/better-language-models/","bibliography":{"title":"Language models are unsupervised multitask learners","authors":["Alec Radford","Jeffrey Wu","Rewon Child","David Luan","Dario Amodei","Ilya Sutskever"],"url":"https://openai.com/index/better-language-models/","pdfUrl":"https://cdn.openai.com/better-language-models/language_models_are_unsupervised_multitask_learners.pdf","codeUrl":"https://github.com/openai/gpt-2","preprint":null,"publication":{"venue":"OpenAI","year":2019,"kind":"report","url":"https://openai.com/index/better-language-models/"},"citation":"@techreport{transformersgpt22019,\n  title = {{Language models are unsupervised multitask learners}},\n  author = {Alec Radford and Jeffrey Wu and Rewon Child and David Luan and Dario Amodei and Ilya Sutskever},\n  year = {2019},\n  institution = {OpenAI},\n  url = {https://openai.com/index/better-language-models/}\n}\n","citationPath":"/content/papers/citations/transformers/gpt_2.f680e2d5a366.bib"},"thumbnail":{"src":"/content/papers/assets/e9f22b4511e15494c184fe4b81e763a07d74e80f1f8dcb9c4619d8c0ddff9866.jpg","width":804,"height":312},"locale":"en","path":"/content/papers/en/transformers/gpt_2.8bce4934551e.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"fragility","text":"Fragility","depth":3},{"id":"limitations-of-narrow-experts","text":"Limitations of Narrow Experts","depth":3},{"id":"lack-of-generalization","text":"Lack of Generalization","depth":3},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"model-design","text":"Model Design","depth":3},{"id":"multitask-learning","text":"Multitask Learning","depth":3},{"id":"diverse-data","text":"Diverse Data","depth":3},{"id":"optimized-bpe-encoding","text":"Optimized BPE Encoding","depth":3},{"id":"byte-level-bpe","text":"Byte-Level BPE","depth":4},{"id":"discussion","text":"Discussion","depth":2},{"id":"model-sizes","text":"Model Sizes","depth":3},{"id":"zero-shot-performance","text":"Zero-Shot Performance","depth":3},{"id":"various-experiments","text":"Various Experiments","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"transformers/gpt_1","relation":"background","topic":"From language pretraining to in-context learning"},{"id":"transformers/gpt_3","relation":"next","topic":"From language pretraining to in-context learning"}]},{"id":"transformers/gpt_1","category":"transformers","legacyPath":"transformers/1806-gpt_1","legacySlug":"1806-gpt_1","legacyPaths":[],"title":"GPT-1","subtitle":"Twelve-Layer Decoder","author":"Z. Yuan","paperDate":"2018","publishedOn":"2024-05-05","paperTitle":"Improving Language Understanding by Generative Pre-Training","paperUrl":"https://openai.com/index/language-unsupervised/","bibliography":{"title":"Improving Language Understanding by Generative Pre-Training","authors":["Alec Radford","Karthik Narasimhan","Tim Salimans","Ilya Sutskever"],"url":"https://openai.com/index/language-unsupervised/","pdfUrl":"https://cdn.openai.com/research-covers/language-unsupervised/language_understanding_paper.pdf","codeUrl":"https://github.com/openai/finetune","preprint":null,"publication":{"venue":"OpenAI","year":2018,"kind":"report","url":"https://openai.com/index/language-unsupervised/"},"citation":"@techreport{transformersgpt12018,\n  title = {{Improving Language Understanding by Generative Pre-Training}},\n  author = {Alec Radford and Karthik Narasimhan and Tim Salimans and Ilya Sutskever},\n  year = {2018},\n  institution = {OpenAI},\n  url = {https://openai.com/index/language-unsupervised/}\n}\n","citationPath":"/content/papers/citations/transformers/gpt_1.634f01e1da35.bib"},"thumbnail":{"src":"/content/papers/assets/09638f2c9f2ddf16a7510c19cd888dd53d93ebd8746b94742b311fdb192fc66a.jpg","width":1224,"height":620},"locale":"en","path":"/content/papers/en/transformers/gpt_1.d7c445890019.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"1-lack-of-labeled-data","text":"1. Lack of Labeled Data","depth":3},{"id":"2-task-inconsistency","text":"2. Task Inconsistency","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":"why-is-the-transformer-effective","text":"Why is the Transformer Effective?","depth":3},{"id":"which-part-is-effective","text":"Which Part is Effective?","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"transformers/transformer","relation":"background","topic":"From language pretraining to in-context learning"},{"id":"transformers/gpt_2","relation":"next","topic":"From language pretraining to in-context learning"}]},{"id":"transformers/gpt_3","category":"transformers","legacyPath":"transformers/2005-gpt_3","legacySlug":"2005-gpt_3","legacyPaths":[],"title":"GPT-3","subtitle":"Ninety-Six Layer Decoder","author":"Z. Yuan","paperDate":"2020-05-28","publishedOn":"2024-06-04","paperTitle":"Language Models are Few-Shot Learners","paperUrl":"https://arxiv.org/abs/2005.14165","bibliography":{"title":"Language Models are Few-Shot Learners","authors":["Tom B. Brown","Benjamin Mann","Nick Ryder","Melanie Subbiah","Jared Kaplan","Prafulla Dhariwal","Arvind Neelakantan","Pranav Shyam","Girish Sastry","Amanda Askell","Sandhini Agarwal","Ariel Herbert-Voss","Gretchen Krueger","Tom Henighan","Rewon Child","Aditya Ramesh","Daniel M. Ziegler","Jeffrey Wu","Clemens Winter","Christopher Hesse","Mark Chen","Eric Sigler","Mateusz Litwin","Scott Gray","Benjamin Chess","Jack Clark","Christopher Berner","Sam McCandlish","Alec Radford","Ilya Sutskever","Dario Amodei"],"url":"https://arxiv.org/abs/2005.14165","pdfUrl":"https://arxiv.org/pdf/2005.14165","codeUrl":null,"preprint":{"id":"2005.14165","submittedOn":"2020-05-28","url":"https://arxiv.org/abs/2005.14165"},"publication":{"venue":"NeurIPS","year":2020,"kind":"conference","url":"https://proceedings.neurips.cc/paper_files/paper/2020/hash/1457c0d6bfcb4967418bfb8ac142f64a-Abstract.html"},"citation":"@misc{transformersgpt32020,\n  title = {{Language Models are Few-Shot Learners}},\n  author = {Tom B. Brown and Benjamin Mann and Nick Ryder and Melanie Subbiah and Jared Kaplan and Prafulla Dhariwal and Arvind Neelakantan and Pranav Shyam and Girish Sastry and Amanda Askell and Sandhini Agarwal and Ariel Herbert-Voss and Gretchen Krueger and Tom Henighan and Rewon Child and Aditya Ramesh and Daniel M. Ziegler and Jeffrey Wu and Clemens Winter and Christopher Hesse and Mark Chen and Eric Sigler and Mateusz Litwin and Scott Gray and Benjamin Chess and Jack Clark and Christopher Berner and Sam McCandlish and Alec Radford and Ilya Sutskever and Dario Amodei},\n  year = {2020},\n  eprint = {2005.14165},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2005.14165}\n}\n","citationPath":"/content/papers/citations/transformers/gpt_3.e117d4f773ec.bib"},"thumbnail":{"src":"/content/papers/assets/7cf129fba1be78b1b43198edc35c44063ba70cb8fc082136055a265ee022b092.jpg","width":1204,"height":1080},"locale":"en","path":"/content/papers/en/transformers/gpt_3.091cea326188.md","headings":[{"id":"problem-definition","text":"Problem Definition","depth":2},{"id":"diverse-language-task-requirements","text":"Diverse Language Task Requirements","depth":3},{"id":"dependence-on-large-supervised-datasets","text":"Dependence on Large Supervised Datasets","depth":3},{"id":"over-specialization-and-generalization-issues","text":"Over-Specialization and Generalization Issues","depth":3},{"id":"human-learning-efficiency-vs-model-efficiency","text":"Human Learning Efficiency vs. Model Efficiency","depth":3},{"id":"solution","text":"Solution","depth":2},{"id":"model-architecture","text":"Model Architecture","depth":3},{"id":"dataset-setup","text":"Dataset Setup","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"lambada","text":"LAMBADA","depth":3},{"id":"closed-book-question-answering","text":"Closed Book Question Answering","depth":3},{"id":"conclusion","text":"Conclusion","depth":2},{"id":"1-gender-bias","text":"1. Gender Bias","depth":3},{"id":"2-racial-bias","text":"2. Racial Bias","depth":3},{"id":"3-religious-bias","text":"3. Religious Bias","depth":3}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"transformers/gpt_2","relation":"background","topic":"From language pretraining to in-context learning"},{"id":"transformers/scaling_laws","relation":"next","topic":"Trading model size against training data"},{"id":"model-evaluation/jev-evaluation","relation":"comparison","topic":"Adapting to a task through prompts or structured decisions"}]}],"text":"The first GPT stacked twelve Transformer decoder layers. OpenAI apparently thought that was not enough, so they stacked forty-eight in the largest GPT-2 model. The paper also trains smaller variants; forty-eight layers refers only to the largest one.\n\n## Defining the Problem\n\nThe authors believe that existing machine learning systems, despite their excellent performance, are fraught with issues. The paper briefly outlines several areas of concern:\n\n### Fragility\n\n- Machine learning systems exhibit fragility when there are slight changes in data distribution and task specifications.\n- These systems lack stability in handling input diversity and variations, leading to unstable behaviors.\n\n### Limitations of Narrow Experts\n\n- Current machine learning systems function more like narrow experts rather than general-purpose systems, limiting their application scope.\n- These systems rely on manually building and annotating training datasets for each specific task, a tedious and non-generalizable process.\n\n### Lack of Generalization\n\n- The prevalence of single-task training on single-domain datasets results in systems that lack generalization capabilities.\n- To achieve robust systems, training and evaluation need to span a broader range of domains and tasks.\n\n## Solving the Problem\n\nThis paper keeps GPT-1's decoder-only architecture, scales up the model, and changes the normalization, initialization, and tokenization.\n\n### Model Design\n\nFirst, the authors moved LayerNorm to the input of each sub-block, similar to pre-activation residual networks. Additionally, they added an extra layer normalization after the final self-attention block.\n\nA modified initialization method was used, considering the cumulative effect on the residual path as model depth increases. The residual layers' weights were scaled by a factor of 1/√N during initialization, where N is the number of residual layers.\n\nTo enhance the model's capabilities, the vocabulary size was expanded to 50,257, the context size increased from 512 to 1024 tokens, and a larger batch size of 512 was used.\n\n\n> [!TIP]\n> \n> If you have trained a model like this, you know a batch size of 512 is a big number. Here it means 512 sequences per update: with a 1024-token context, that can be up to about 524,000 tokens. Memory use also depends on model size and the training implementation.\n\n\n### Multitask Learning\n\nA general-purpose system should be capable of performing many different tasks. This means modeling P(output|input, task) rather than just modeling the conditional distribution of a single task P(output|input).\n\nHere, the authors propose a method of specifying all inputs and outputs as symbol sequences and training the model using language modeling. For example, a translation training example might be represented as (translate to French, English text, French text), while a reading comprehension training example might be (answer the question, document, question, answer).\n\nText can express the task. GPT-2 does not jointly train on manually labeled versions of all these tasks; it learns next-token prediction on WebText, then tests whether naturally occurring demonstrations support task transfer.\n\n### Diverse Data\n\nMost prior language model training focused on single text domains, such as news articles, Wikipedia, or book novels. The authors' approach encourages constructing the largest and most diverse dataset possible to cover a broader range of natural language contexts and demonstrations.\n\nThe authors considered Common Crawl for its scale, but their preliminary experiments ran into serious data-quality problems. So they built **WebText separately**; GPT-2 was not trained directly on Common Crawl.\n\n- **Solution**:\n\n  - **New Web Scraping**: Use Reddit outbound links with at least 3 karma as a heuristic quality signal.\n  - **WebText Dataset**: The resulting dataset, WebText, includes a subset of texts from these 45 million links. The initial version of WebText excludes links created after December 2017, and after deduplication and heuristic cleaning, it contains just over 8 million documents, totaling 40 GB of text.\n  - **Wikipedia Exclusion**: Wikipedia documents were removed from WebText to reduce overlap with evaluations that use Wikipedia and ease analysis.\n\n\n> [!TIP]\n> \n> December 2017 is the link cutoff for this preliminary version of WebText. Still, identifying generated material in training data is a question worth watching.\n> \n> If a model repeatedly learns from generated text, errors or biases might carry into later training. That is a possible risk beyond this paper; the authors did not test whether such training would cause a model to collapse.\n\n\n### Optimized BPE Encoding\n\nThe advantage of byte-level BPE lies in its flexibility and generality, as it can decompose any character into a sequence of bytes. However, directly applying BPE to byte sequences can result in suboptimal merges due to BPE's greedy frequency algorithm.\n\nTo address this, the authors restrict merges across character categories so variants of a word with different punctuation do not consume too many vocabulary slots. Spaces are an exception; the paper says this improves compression efficiency with little word fragmentation.\n\n\n> [!TIP]\n> \n> Perhaps the easiest way to picture this is a jigsaw puzzle.\n> \n> Ordinary BPE is like joining puzzle pieces that often occur together: you make larger pieces of sky and grass, then use those to assemble the picture more quickly.\n> \n> But imagine a much more complicated picture with many kinds of patterns, like the variety of Unicode characters. Remembering every useful combination would require an unwieldy number of pieces.\n> \n> #### Byte-Level BPE\n> \n> Byte-level BPE starts with the smallest pieces instead. In the puzzle analogy, you look at the color or shape of each little piece rather than memorizing every complete pattern. There are just 256 starting byte values; after learning merges, GPT-2's final vocabulary still contains 50,257 tokens.\n> \n> There is a catch: if you join those small pieces indiscriminately, you may combine a bit of sky with a bit of grass and end up with pieces that are less useful for assembling either region.\n> \n> The authors therefore stop BPE from merging across character categories, with an exception for spaces. In our puzzle, that is like keeping different kinds of patterns apart while allowing a useful boundary piece to stay attached. The exception concerns which existing pieces may merge; it does not add spaces to the original text.\n> \n> This combines the flexibility of small starting pieces with the efficiency of larger, frequently used ones, without needing to memorize every possible pattern.\n> \n\n\n## Discussion\n\n### Model Sizes\n\n![Paper Table 2: parameter count, layer count, and d_model for four GPT-2 sizes](/content/papers/assets/e9f22b4511e15494c184fe4b81e763a07d74e80f1f8dcb9c4619d8c0ddff9866.jpg \"Language Models are Unsupervised Multitask Learners, Table 2\")\n\nThe report lists 117M/12 layers, 345M/24, 762M/36, and 1542M/48. The forty-eight layers in the subtitle refer only to the largest model. Table 2 also shows d_model rising from 768 through 1024 and 1280 to 1600, so results cannot be attributed to depth alone.\n\n### Zero-Shot Performance\n\n![Paper Table 3: zero-shot language-model evaluation on eight datasets with ten metric columns](/content/papers/assets/505052f8463529931e71acaf17ebd516beb0f9564afac79d068019b9cbbdffcd.jpg \"Language Models are Unsupervised Multitask Learners, Table 3\")\n\nZero-shot here means no task-specific parameter update. The paper separately analyzes pretraining overlap.\n\nIn Table 3's zero-shot language-model evaluation, the largest model sets a then-best result on seven of eight datasets. **1BW is the exception**: its perplexity of 42.16 remains worse than the prior 21.8. There are ten metric columns because LAMBADA and CBT each contribute two. Gains are especially visible on Penn Treebank and WikiText-2. Those datasets' own training splits contain about one to two million tokens, but GPT-2 did not train on them for this evaluation.\n\nThe dataset for measuring long-term dependencies, such as LAMBADA and the Children's Book Test, also showed substantial progress.\n\n| Metric | Meaning | Interpretation |\n| --- | --- | --- |\n| **PPL** | **Perplexity**: exponentiated mean negative log probability of a test sequence. | Lower means the model predicts that sequence better; compare under the same data and processing. |\n| **ACC** | **Accuracy**: proportion correct under specified candidates or answer rules. | Higher is better, with task constraints in view. |\n| **BPB** | **Bits per byte**: model-derived information content averaged per byte. | Lower means less prediction loss on this test set. |\n| **BPC** | **Bits per character**: the same information content normalized by character count. | Lower means less prediction loss on this test set. |\n\nCompare PPL under consistent tokenization and evaluation conditions. BPB/BPC are not the original file's fixed storage width. Table 3 also uses reversible detokenization to lessen differences introduced by benchmark preprocessing.\n\n### Various Experiments\n\nThe authors conducted experiments on various tasks, including language modeling, machine translation, question answering, text summarization, and text generation.\n\nHere's a summary table to quickly understand GPT-2's performance on various tasks:\n\n| **Test Name**                    | **Purpose**                                                       | **Test Method**                                                | **Results**                                                                                                                                                                   |\n| -------------------------------- | ----------------------------------------------------------------- | -------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| **Children's Book Test (CBT)**   | Check model performance on different word categories.             | Choose the missing word from 10 candidates on the validation set, which had no significant WebText overlap. | 93.3% accuracy on common nouns, 89.1% accuracy on named entities.                                                                                                             |\n| **LAMBADA**                      | Test modeling long-range dependencies.                             | Predict a sentence's final word.                               | Prior perplexity 99.8 falls to 8.6, and unfiltered accuracy rises from a prior 19% to 52.66%. A stopword filter gives 63.24%, a different setting. |\n| **Winograd Schema Challenge**    | Measure resolution of text ambiguity.                              | Compare candidate interpretations.                             | 70.70% on only 273 examples; the paper cautions against overinterpreting the small sample. |\n| **Reading Comprehension (CoQA)** | Answer questions that depend on dialogue history.                  | Generate answers given a document and conversation history.    | 55 F1 on the development set, matching or beating three of four supervised baselines, but below stronger supervised systems. |\n| **Summarization**                | Test summarization ability.                                        | Add `TL;DR:` after an article, sample with top-k=2, and take the first three generated sentences. | Average ROUGE is 21.40, only slightly above 20.98 for three random sentences; generated summaries sometimes confuse details. |\n| **Translation**                  | Test translation ability.                                         | Use English-French sentence translation.                       | Achieved 5 BLEU on English-French test set; 11.5 BLEU on French-English test set, lower than the best unsupervised methods' 33.5 BLEU.                                        |\n| **Question Answering**           | Test factual short-answer generation.                              | Prompt with example Q&A pairs; evaluate Natural Questions exact match. | 4.1% overall, answering 5.3 times as many questions as the smallest model. Accuracy is 63.1% on the top 1% by confidence, still far below contemporaneous retrieval-plus-extraction systems' 30–50%. |\n\n## Conclusion\n\nThis study explores what unsupervised task learning might do for NLP: can GPT-2 carry out different tasks directly, without supervised adaptation or a task-specific model change?\n\nThe results suggest that a large language model trained on sufficiently varied text can perform well across many domains and datasets, and can begin to handle tasks without explicit task supervision. The seven then-best results in Table 3 are for **language-model transfer across datasets**; translation, summarization, and question answering are still much weaker. The authors also found a small but consistent benefit from WebText/test-set overlap.\n\nThese findings opened up new possibilities for unsupervised learning and further improvements to language models. They also give us a reason to keep checking which abilities actually appear when we describe a task in text.\n","imageSizes":{"/content/papers/assets/e9f22b4511e15494c184fe4b81e763a07d74e80f1f8dcb9c4619d8c0ddff9866.jpg":{"width":804,"height":312},"/content/papers/assets/505052f8463529931e71acaf17ebd516beb0f9564afac79d068019b9cbbdffcd.jpg":{"width":1586,"height":376}}}
