Back to paper library
OpenAI 2018Language & TransformersPaper notes

GPT-1

Twelve-Layer Decoder

Original paper

Improving Language Understanding by Generative Pre-Training

Paper authors

Alec Radford · Karthik Narasimhan · Tim Salimans · Ilya Sutskever

Publication
OpenAI 2018Technical report
Cite this paper · BibTeX

The citation identifies the linked source version. It cites the original paper and its authors.

@techreport{transformersgpt12018,
  title = {{Improving Language Understanding by Generative Pre-Training}},
  author = {Alec Radford and Karthik Narasimhan and Tim Salimans and Ilya Sutskever},
  year = {2018},
  institution = {OpenAI},
  url = {https://openai.com/index/language-unsupervised/}
}
On this page

The original Transformer architecture has two parts: an encoder and a decoder.

OpenAI took a different route from that starting point: a decoder-only architecture.

Defining the Problem

The authors identified several issues with current NLP models:

1. Lack of Labeled Data

In the field of NLP, while data is abundant, labeled data is scarce. This is particularly problematic when working on specific tasks such as specialized domain question answering (QA) or machine translation (MT), where the lack of corresponding labeled data makes training difficult.

One way around the shortage of labels is a kind of “text continuation”: predict the next token. The targets come from the text itself, so this is commonly called self-supervised learning today, though not all unsupervised learning is self-supervision. You can keep collecting text without manually labeling every example. But that leads to another problem: the pre-training task and the eventual target task differ.

2. Task Inconsistency

In NLP models, there are typically two stages: pre-training and fine-tuning. Pre-training involves letting the model learn from large amounts of text data, while fine-tuning involves training the model further on specific tasks. The inconsistency between these two stages is problematic.

In pre-training, the model learns to predict the next token, but in fine-tuning it may need to answer a question or compare two sentences. Earlier transfer methods often added a separate architecture and parameters for each target task, making the process cumbersome to manage.

The authors instead pre-train one Transformer decoder and transform sentence pairs or multiple-choice problems into sequences it can read. Fine-tuning adds a linear output layer and delimiter-token embeddings, with few task-specific architectural changes.

Solving the Problem

Model Architecture

Figure 1 shows the shared 12-layer decoder and its language-model and task-classification outputs on the left. On the right, classification, entailment, similarity and multiple-choice inputs become token sequences. Entailment places a delimiter between the two sentences; similarity evaluates both orders and adds their representations; multiple-choice questions score each candidate answer. The configuration is as follows:

  • 12 decoder-only blocks with causal self-attention and FFNs, without encoder–decoder cross-attention.
  • Each decoder layer has 768 feature dimensions and 12 attention heads.
  • The hidden layer in the feed-forward network (FFN) uses 3072 neurons.
  • Sequence length is 512.
  • Dropout rate is 0.1.
  • Modified L2 regularization with coefficient 0.01 is applied to non-bias, non-gain weights.
  • Gelu activation function is used.
  • Position encoding uses learnable positional embeddings.
  • Text is pre-tokenized with the spaCy tokenizer, then represented with BPE using 40,000 merges.

Training was conducted using:

  • Adam optimizer.
  • Maximum learning rate of 2.5e-4, linearly increasing over the first 2000 steps, then using cosine annealing to 0.
  • Training runs for 100 epochs on batches of 64 contiguous 512-token sequences.

Pre-training Strategy

Training uses unlabeled pretraining followed by supervised task-specific fine-tuning. GPT-1 pretrains on BooksCorpus; the 1B Word Benchmark below is discussed as an alternative corpus, not mixed into GPT-1 training.

  1. BooksCorpus: It contains over 7,000 unique unpublished books covering various genres like adventure, fantasy, and romance. Importantly, it includes long stretches of contiguous text, allowing the model to learn long-range dependencies.

  2. 1B Word Benchmark: Similar to methods used by ELMo, this dataset is roughly the same size but reorganized at the sentence level to disrupt long-range structure.

Fine-tuning Strategy

The authors did not build an elaborate new architecture for each fine-tuning task. Instead, as Figure 1 shows, they turn each task's input into a token sequence: entailment joins a premise and hypothesis with a delimiter; semantic similarity evaluates both sentence orders and combines their representations; multiple choice scores each candidate answer. A linear classifier is then added. The same decoder is reused across these layouts, rather than training four different model architectures.

During fine-tuning, the supervised task objective is accompanied by an auxiliary next-token language-model objective weighted 0.5. Unless otherwise specified, pre-training hyperparameters are reused. Classifier dropout is 0.1; most tasks use a learning rate of 6.25e-5 and batch size 32.

Discussion

The complete method achieved the then-best result on 9 of 12 evaluated datasets. Overall RACE accuracy was 59.0%, versus the previous 53.3%, but RTE accuracy was 56.0%, below the previous 61.7%. These results support the combination of language-model pre-training, input transformations and supervised fine-tuning; they do not isolate the decoder architecture as the only cause. The authors also examined zero-shot behavior.

Why is the Transformer Effective?

Figure 2 (left) compares RACE and MultiNLI as more pre-trained layers are transferred. Solid lines are development scores and dashed lines are training scores. Both development curves generally rise with transfer depth, supporting the authors' interpretation that embeddings and successive layers help on these tasks.


Figure 2 (right) is a different experiment: task-specific heuristics use language-model scores without supervised fine-tuning. The horizontal axis counts pre-training updates; scores are normalized between random guessing and the then-best single model. Solid lines represent the Transformer, dashed lines the LSTM. Most curves rise, but vary substantially by task. They are not the fine-tuned accuracies plotted on the left.

Which Part is Effective?

To identify which components contributed most to the model's performance, the authors conducted three different ablation studies. Results are shown in Table 5 of the paper:

  1. Impact of the Auxiliary Language Model Objective:

    • Removing the auxiliary language-model objective lowers the MNLI, QNLI, RTE and QQP scores. QQP tests semantic equivalence of question pairs, not question answering.
    • The authors saw a greater benefit on larger datasets, yet the unweighted eight-metric average is 75.0 without the auxiliary objective versus 74.7 for the full model. It does not improve every metric or the reported average.
  2. Comparison Between Transformer and LSTM:

    • Replacing the Transformer with a single-layer, 2048-unit LSTM lowers Table 5's unweighted average from 74.7 to 69.1, a 5.6-point difference.
    • LSTM outperformed the Transformer only on the MRPC dataset.
  3. Importance of Pre-training:

    • Without pre-training, every listed task score falls. Table 5’s eight-metric average drops from 74.7 to 59.9, a loss of 14.8 score points, not a relative decline of 14.8%.

Conclusion

This was OpenAI's first large-scale pre-trained Transformer language model. By learning from long stretches of unlabeled BooksCorpus text and then fine-tuning on specific tasks, it showed how one reusable model could achieve strong language-understanding results. The paper reports then-best results on 9 of 12 datasets, while RTE falls short and the auxiliary objective does not help every metric.

GPT-1's success showed the promise of pre-training followed by fine-tuning across different NLP tasks. Figure 1's input transformations are as important to this story as the 12-layer decoder: the experiments do not attribute every gain to the decoder alone. This line of work laid groundwork for later, larger GPT-2 and GPT-3 models, and for using general representations across a wider range of language tasks.