Concepts / Pretraining and Fine-Tuning Language Models

Pretraining and Fine-Tuning Language Models

GPT was introduced by Radford et al. from OpenAI in the paper Improving Language Understanding by Generative Pre-Training.

  • Programming

Where the GPT Story Begins

GPT is a family of language models, and this article follows that family from its first version to the models used in ChatGPT. The family starts with one named paper. GPT stands for Generative Pre-Training, and it was introduced by Radford et al. from OpenAI in a paper titled Improving Language Understanding by Generative Pre-Training. That paper is the starting point of the family. Every later model in this article is described relative to it.

The word pre-training in that title points to the central idea of this article. A model is first trained on a general task, and later it is adjusted for more specific work. The first stage is called pretraining, and the adjustment stage is called fine-tuning. Pretraining happens before any later specialization, so it comes first in the story.

A Plain Objective With Surprising Reach

Imagine a system whose only training goal is to guess the next word in a piece of text. That sounds like a narrow skill. Yet the GPT models can be pointed at a surprisingly wide range of jobs, including spelling correction, classification, and language translation. The question this article answers is how a model built around such a plain objective ends up being useful for so much more.

The Next-Word Prediction Task

GPT models are pretrained on a relatively simple next-word prediction task. The model is given a passage of text and must predict the word that comes next. The source describes this task as simple, and that simplicity is what makes its later results notable. The same pretrained model can then be used as a text completion model, because completing a passage is a direct extension of guessing the next word.

A single passage yields many training examples. The model does not see the whole passage as one question. Instead, it reads a window of text, predicts the word after that window, and then the window moves one word forward. The diagram below traces this movement on a short sentence. The sentence used here is an invented illustration, not a passage from the source.

Worked example

Turning One Sentence Into Training Examples

Take the sentence The cat sat on the mat. List the input the model sees and the word it must predict at each step, using the next-word prediction task.

  1. 1
    Choose the first window

    The first window contains only the word The. The word that must be predicted next is cat.

  2. 2
    Extend the window by one word

    The window now contains The cat. The word that must be predicted next is sat.

  3. 3
    Continue moving the window

    The window grows to The cat sat, and the target becomes on. Then the window becomes The cat sat on, and the target becomes the.

  4. 4
    Reach the last prediction

    The final window is The cat sat on the, and the target word is mat. One sentence has produced five separate prediction tasks.

Result

The sentence yields five training examples. Each example pairs a piece of preceding text with the single word that comes next.

How GPT-3 Scales Up the Original

GPT-3 is a scaled-up version of the original model. The source describes scaling along two dimensions. First, GPT-3 has more parameters than the original GPT. Second, GPT-3 was trained on a larger dataset than the original GPT. The source does not give specific parameter counts or dataset sizes, so the useful takeaway is the direction of change rather than exact numbers.

A helpful way to hold this in mind is to treat GPT-3 as the same design with a bigger capacity to learn and more text to learn from. The source does not describe GPT-3 as a different kind of system. That is why it introduces GPT-3 as a scaled-up version of the original model rather than as a new invention.

FeatureOriginal GPTGPT-3
Relationship to the familyStarting point, introduced in the Radford et al. paperScaled-up version of the original GPT
Number of parametersFewer than GPT-3More than the original GPT
Training datasetSmaller than GPT-3Larger than the original GPT
Training objectiveNext-word predictionBuilt on the same design, described as the same kind of system

Scale comparison as described in the source. Exact counts are not given in the source.

From GPT-3 to the ChatGPT Model

The next link in the chain is how GPT-3 became the model offered in ChatGPT. According to the source, the original model offered in ChatGPT was created by fine-tuning GPT-3 on a large instruction dataset. The fine-tuning followed a method from OpenAI's InstructGPT paper. Fine-tuning is the adjustment stage that comes after pretraining, so the chain runs from pretraining in the original GPT, through scaling in GPT-3, to fine-tuning that produces the ChatGPT model.

Read this as a two-stage story after scaling. GPT-3 is the base that already exists. InstructGPT describes how that base is adjusted, using a large instruction dataset, to produce the model that appeared in ChatGPT. The source names the method and the dataset type. It does not describe the internal details of the fine-tuning procedure, so this article does not go beyond those facts.

Why One Objective Supports Many Tasks

The source presents the central surprise plainly. A model pretrained on a simple next-word prediction task can also carry out tasks such as spelling correction, classification, and language translation. These tasks look different from one another, yet all of them are reached from the same pretrained model. The diagram below shows how the named tasks relate back to the single objective.

Common Misreadings of the GPT Lineage

  • Common mistake

    Treating GPT-3 as a completely different kind of system from the original GPT

    Why it fails

    The source describes GPT-3 as a scaled-up version of the original model, with more parameters and a larger training dataset.

    Do this instead

    Think of GPT-3 as the same design with greater capacity and more training text.

  • Common mistake

    Assuming the ChatGPT model is the same thing as GPT-3

    Why it fails

    The source says the original model offered in ChatGPT was created by fine-tuning GPT-3 on a large instruction dataset using a method from the InstructGPT paper.

    Do this instead

    Place fine-tuning as a separate stage that comes after GPT-3.

  • Common mistake

    Believing the next-word objective only produces next-word guesses

    Why it fails

    The source states that the pretrained models can also carry out tasks such as spelling correction, classification, and language translation.

    Do this instead

    Recognize next-word prediction as the pretraining objective, while the uses of the model extend beyond it.

  • Common mistake

    Quoting exact parameter counts or dataset sizes from memory

    Why it fails

    The source gives the direction of change, more parameters and a larger dataset, but not specific numbers.

    Do this instead

    State the direction of scaling, and avoid inventing figures the source does not provide.

Tracing the Training Window

EASY

Using the sentence The model reads text carefully, list every window and the single word the model must predict next. Write each training example as a pair of input text and target word.

Hints
  • Start with a window containing only the first word.
  • Each new window adds exactly one word from the sentence.
  • The last window has no target word after it, so stop one word before the end.
MEDIUM

Explain in two or three sentences how the original GPT, GPT-3, and the ChatGPT model are related, naming the stage that changes each model.

Hints
  • The original GPT is the starting point, and GPT-3 is its scaled-up version.
  • Fine-tuning on a large instruction dataset is the stage that produces the ChatGPT model.

Key Takeaways

  • GPT, short for Generative Pre-Training, was introduced by Radford et al. from OpenAI in the paper Improving Language Understanding by Generative Pre-Training.
  • GPT models are pretrained on a simple next-word prediction task, in which the model predicts the word that follows a passage of text.
  • GPT-3 is a scaled-up version of the original GPT, with more parameters and a larger training dataset.
  • The original model offered in ChatGPT was created by fine-tuning GPT-3 on a large instruction dataset using a method from OpenAI's InstructGPT paper.
  • A model trained only on next-word prediction can also carry out tasks such as spelling correction, classification, and language translation, which the source presents as the remarkable result.

Related concepts

More concepts starting with P