GPT Fine-Tuning

Machine Learning
Introduced by
Radford, A. et al. (OpenAI)
Year
2019
Type
Fine-tuning of pretrained autoregressive language models

What does it do?

GPT fine-tuning continues training a pretrained autoregressive language model, such as a GPT-family model, on task- or domain-specific text so that it performs better on a particular application.

It is also used to align models with instructions through reinforcement learning from human feedback (RLHF). The method is applied to text generation and, when the target can be written as text, to classification and prediction.

The intuition behind the method

A large language model has already learned grammar, facts and reasoning patterns from a large text corpus, so it is rarely necessary to train one from scratch. Fine-tuning starts from that pretrained model and shifts it toward a specific task, such as a domain's vocabulary, a preferred answer style or a set of instructions. It does this by continuing training on a much smaller set of task-specific prompt-completion examples.

History

The GPT-family pretrained models that fine-tuning adapts are cited here to Radford et al. (2019), the report 'Language Models are Unsupervised Multitask Learners'. Fine-tuning is not attributed on this page to a single originator. Ouyang et al. (2022) describe fine-tuning GPT-3 first with supervised learning on labeler demonstrations and then with reinforcement learning from human feedback, producing InstructGPT. Their abstract reports that, in human evaluation, outputs from a 1.3B-parameter InstructGPT model were preferred to outputs from the 175B GPT-3 model.

When to use it

Choose GPT fine-tuning for text classification, prediction or generation when you have a pretrained GPT-family model, your data can be arranged as prompt-completion pairs, and GPU or TPU compute is available. It is a poor fit when the dataset is very small, such as around 50 examples or fewer; in that case fine-tuning is often unreliable and simpler models such as random forest or XGBoost are the safer choice. If the goal is instruction following, be prepared to collect rankings of model outputs for the alignment step, because supervised fine-tuning alone does not provide that behaviour. The method is designed for text inputs, so it is not the natural choice for purely numeric or tabular problems.

Limitations and considerations

  • Requires a pretrained GPT-family model and usually GPU or TPU compute, which limits use on modest hardware.
  • Output quality depends heavily on how training data is formatted into prompt-completion pairs; inconsistent formatting weakens what the model learns.
  • On small datasets the model can overfit, and generative quality may degrade.
  • RLHF alignment needs rankings of model outputs as training data, which is an additional data cost beyond the prompt-completion set.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Starts from weights that already encode broad language knowledge, so the task data only needs to shift an existing model rather than teach language from scratch.
  • One autoregressive objective covers generation and, through prompt-completion formatting, classification and prediction on text.
  • Because the inputs are token sequences rather than numeric features, the method involves no feature-distribution assumptions such as normality for its inputs.
  • RLHF alignment, as described by Ouyang et al. (2022), provides a route to instruction following and preference matching that the language-modelling loss alone does not give.

Applications

  • Domain adaptation of a general language model to specialised text.
  • Instruction following and assistant-style generation, using RLHF alignment.
  • Text classification and prediction on textual data, where labels or targets are expressed as text completions and examples are formatted as prompt-completion pairs.
  • Generative tasks where fluent output in a required style is needed.

How it works

How it works

1

The process starts from a pretrained GPT-family model whose weights already encode broad language knowledge from large-scale pretraining. The task data is arranged as prompt-completion pairs, each giving an input prompt and the output the model should produce. Training of this kind is compute-intensive, so a GPU or TPU is usually needed.

2

The model is trained further on the prompt-completion data with the autoregressive objective in the mechanics formula, which is the negative log-likelihood of each token given the tokens before it. Because training starts from the pretrained weights, the updates move the model toward the target domain rather than teaching it language from scratch.

Formula
\mathcal{L} = -\sum_{t} \log P(x_t \mid x_{<t})
3

For instruction following, the adapted model can be further tuned with human feedback. In the approach described by Ouyang et al. (2022), the base model was GPT-3, which was first fine-tuned with supervised learning on labeler demonstrations of the desired behaviour. It was then fine-tuned further with reinforcement learning from human feedback, using a dataset of rankings of model outputs. The resulting models are called InstructGPT.

Common pitfalls

  • Judging quality from fluent-looking output alone; a model trained on few examples can overfit and still read well.
  • Training on prompt-completion data that mixes formats or contains inconsistent completions, so the model learns those inconsistencies.
  • Treating alignment as optional when instruction following is the goal; the language-modelling loss alone does not produce the preference behaviour that RLHF targets.
  • Using GPT fine-tuning on a small dataset where random forest or XGBoost, both listed as related methods, would be more reliable.
  • Reporting results without a held-out evaluation set or a baseline. Measure performance on examples not used in training, using a task metric such as accuracy or F1 for classification, and compare against a simple model before concluding that fine-tuning helped.

Frequently asked questions

How much data do I need to fine-tune a GPT model?

More is generally better. Very small sets, around 50 examples or fewer, are often insufficient for reliable results, and a simpler model such as random forest or XGBoost may be safer. There is no fixed threshold that guarantees success, so judge sufficiency by performance on examples held out from training, compared with a simple baseline. Small training sets also risk overfitting.

What is the difference between fine-tuning and RLHF?

Fine-tuning continues training on domain or task data to minimise the language-modelling loss. RLHF is an alignment step that further tunes the model to human feedback, so that it follows instructions and produces the expected style of answer.

Do I need a GPU?

Often yes. Fine-tuning large autoregressive models is compute-heavy, and a GPU or TPU may be required depending on the model size and task.

How should I format my data?

Prepare it in prompt-completion format, where each example pairs an input prompt with the desired model output, before fine-tuning.

Related methods

Sources

  1. Radford, A., Wu, J., Child, R., Luan, D., Amodei, D. & Sutskever, I. (2019). Language Models are Unsupervised Multitask Learners. OpenAI Technical Report.

    Open publication reference
  2. Ouyang, L. et al. (2022). Training Language Models to Follow Instructions with Human Feedback. NeurIPS.

    Open DOI reference