AI & machine learning / Pre-training vs fine-tuning

Pre-training vs fine-tuning

Why large AI models are trained in two stages: once on a mountain of raw text to learn language in general, then briefly on a small labelled set to do one job. With real figures for data and cost.

Beginner7 steps~6 min
Raw text — broad, unlabelled data
Labelled example — an input with its right answer
Model — millions of adjustable weights
Task layer — what fine-tuning adds or changes
// THE SHORT VERSION

In 30 seconds

Pre-training teaches a model general knowledge from a huge amount of raw data, such as billions of words of text. It needs no human labels, but a great deal of computing power.

Fine-tuning takes that model and trains it a little more on a small set of examples for one task. It is quick and cheap because the model already knows the language. Reusing knowledge this way is called transfer learning.

With today’s large models, a well-written prompt is often enough, and no training is needed at all.

Pre-training vs fine-tuning, step by step

STEPS01 / 07

Figures are from the BERT paper (2018): BERT-base, the SST-2 review benchmark, Cloud TPU hours. Current large language models are pre-trained on far more data and hardware.

STEP 01 / 07 Training in two stages
THE MATH
1. pre-train: broad data 2. fine-tune: task data stage 2 starts from stage 1
  1. Step 1: Training in two stages. Large language models are usually trained in two stages. First, pre-training on a huge, broad pile of data gives the model general knowledge. Then fine-tuning continues the training on a small set of examples for one job. The second stage does not start again: it builds on everything the first stage learned.
  2. Step 2: Pre-training on raw text. Pre-training needs no human labels, because the text supplies its own answers. Hide a word, let the model guess it, compare with the word that was really there, and adjust the weights. BERT (2018) did this over about 3.3 billion words of books and Wikipedia. GPT-style models predict the next word instead; the idea is the same.
  3. Step 3: Fine-tuning on a task. Fine-tuning runs the same training loop, but on examples of the job you want done, each with the right answer attached by a person. To sort film reviews, a small output layer is added and the model is trained on about 67,000 labelled sentences. That is tiny next to 3.3 billion words, because the model already knows the language.
  4. Step 4: Small nudges, not a restart. Fine-tuning starts from the pre-trained weights and moves them in small steps, so the model keeps what it knows. Full fine-tuning adjusts every weight, all 110 million in BERT-base. Adapter methods such as LoRA freeze the originals and train a small add-on, which is cheaper. Overdo it on narrow data and general skills fade.
  5. Step 5: Transfer learning. Reusing what a model learned on one task to do another is called transfer learning. Grammar, word meanings and everyday facts are needed for almost every language task, so one pre-trained model can be fine-tuned many times. Each task then needs only its own small labelled set: BERT-base got 93.5% of test reviews right.
  6. Step 6: Data and cost of each. Pre-training is the expensive part. BERT-base took 4 days on 4 cloud TPU machines, 384 machine-hours; fine-tuning it took at most 1 hour on one. Fine-tuning needs far less data, but it must be labelled, which costs human time. Today’s large language models widen the gap, so few organisations pre-train and many fine-tune.
  7. Step 7: When prompting is enough. A large pre-trained model can often do a new task with no training at all: describe the job in the prompt, perhaps with a few examples, and the weights stay untouched. Fine-tuning earns its cost when prompting is not reliable enough: a fixed format at high volume, specialised material, or a small model that must do one job well.
VALUES SO FAR
stages2overview
raw text····pre-train
labelled····fine-tune
weights····BERT-base
accuracy····reviews
compute····TPU-hours
prompt····first try

Spotted a mistake on this page?