TL;DR
Transfer learning means reusing a model trained on one task as the starting point for a different task. The early layers have already learned general patterns such as edges, textures and word shapes, so the new task only has to teach the model what is specific to it. This works with far less labelled data and compute than training from scratch.
Where you'll see it: almost every practical vision and language system. A network pretrained on ImageNet is adapted to spot defects on a factory line, and a language model pretrained on web text is adapted to answer customer emails.
Intuition
Think of someone who already plays the piano and then learns the organ. They do not relearn what a note is, how rhythm works or how to read music. They only learn the new instrument's keys and pedals. Most of the knowledge carries over, and only the instrument-specific part is new.
A neural network has the same structure. Its early layers respond to simple, general things, and later layers combine those into task-specific things. Training on a large dataset teaches the network a set of features, called a representation, that stay useful well beyond the original task. Transfer learning keeps those features and retrains only the part that is specific to the new task.
It exists because labelled data is expensive. A medical imaging team might have 2,000 labelled scans. A vision model started from random weights usually needs hundreds of thousands of examples to learn good features from nothing. Starting from weights someone else already paid for turns a data problem into a small adaptation problem.
flowchart LR A[Large source dataset] --> B[Pretrain: learn general features] B --> C[Keep the feature layers] C --> D[Small target dataset] D --> E[Train a new head, optionally fine-tune all layers] E --> F[Model for the target task]
The curves below are illustrative, not measured data. They plot test accuracy against the number of labelled target examples, in thousands. The pretrained model starts near its ceiling and needs only a few thousand labels to get close to it.
- trained from scratch
- pretrained, then adapted
The math
Write a model as a composition of two parts. The feature extractor has parameters and maps an input to a feature vector. The head has parameters and maps features to a prediction: .
Let be a large source dataset and a much smaller target dataset. Transfer learning first finds feature parameters by minimising a loss on . It then trains on starting from rather than from random values.
Two ways to adapt
- Feature extraction. Freeze at its pretrained value and train only the head:
- Fine-tuning. Update all parameters on , usually with a smaller learning rate so the pretrained features are not destroyed.
For classification the loss is usually cross-entropy. Both options use the same update rule as Gradient Descent, , where is the learning rate. Training usually runs in mini-batches, as in Stochastic Gradient Descent.
Why starting point matters
Optimisation is a search, and where it starts decides where it can end up. Pretrained weights already sit in a region where the features are useful, so the search for the target task only has to make small moves. Yosinski and colleagues measured this in image networks. They found that the first layers learn generic filters, similar across tasks, while the last layers become specific to the source task. That is why the usual recipe keeps the early layers and replaces the top.
Worked examples
Frozen features , head weights , bias , label , learning rate . The output is with , and the loss is .
- Forward pass: .
- Probability: . Loss: .
- Gradient: for sigmoid with cross-entropy, . So and .
- Update with : and .
- New output: , so and .
Interpretation: one step on the head alone cut the loss from 0.854 to 0.535. The feature extractor never changed. Only the mapping from features to output moved.
Suppose the pretrained extractor outputs 512 numbers per image, and the new task has 10 classes. The backbone has 25 million parameters.
- Weights: one weight for each pair of feature and class, so 512 × 10 = 5120.
- Biases: one per class, so 10.
- Trainable total with feature extraction: 5120 + 10 = 5130.
- Share of the model: 5130 / 25,000,000 ≈ 0.02%.
Interpretation: feature extraction fits about five thousand numbers, which is why it can work with a few hundred labels per class. Fine-tuning all 25 million parameters on the same small set is far more likely to overfit.
Tradeoffs and failure modes
Transfer learning pays off when the target data is small and the source task is related. It helps least when the target data is large and the compute budget is generous, since training from scratch then has enough data to find good features on its own.
The main failure mode is negative transfer: the pretrained features are a poor fit, and starting from them is worse than starting from random weights. A second is catastrophic forgetting, where aggressive fine-tuning erases the general features. A third is overfitting the small target set, which the usual guard, early stopping and regularisation, addresses. Finally, a model adapted on one set of inputs can still fail in production when the inputs shift, which is the problem of Covariate Shift.
| Situation | Problem | Better choice |
|---|---|---|
| Small target set, similar domain | Full fine-tuning overfits | Freeze the backbone and train the head |
| Medium target set, similar domain | Frozen features miss target details | Fine-tune the top layers with a small learning rate |
| Very different domain, such as X-rays vs photos | Features partly mismatched, negative transfer | Fine-tune more layers, or pretrain on in-domain data first |
| Large target set and large compute | Pretraining adds little | Train from scratch, or pretrain on a larger in-domain set |
| Very large model, little compute | Full fine-tuning is too costly | Parameter-efficient methods such as Low-Rank Adaptation (LoRA) |
If there are no labels for the target task at all, Zero-Shot Learning and pretraining with Self-Supervised Learning are the alternatives to try.
History
Transfer ideas predate deep learning. Rich Caruana's 1997 work on multitask learning argued that training one network on related tasks at once helps each of them, which is the same intuition in another form. Pan and Yang's 2010 survey gave the field its vocabulary of source and target domains. The practical turn came in computer vision around 2014, when networks pretrained on ImageNet, a large labelled image collection, were reused as feature extractors for other tasks. Yosinski and colleagues then measured which layers transfer, and found the early ones generic and the later ones specific.
In language, ULMFiT and BERT, both published in 2018, showed that pretraining a large model on unlabelled text and then fine-tuning it beat task-specific models on many benchmarks. That recipe, pretrain on a large corpus and then adapt, is now the default for language models and for much of the work on transformers.
Check yourself
QuestionName the two standard ways to adapt a pretrained model, and say what each one changes.Show answer
Feature extraction freezes the pretrained feature extractor and trains only a new head, so the general features are kept exactly. Fine-tuning updates all parameters, usually with a smaller learning rate, so the features adapt to the new task. Feature extraction suits small target sets; fine-tuning suits larger ones.
QuestionA head maps 256 features to 4 classes and includes a bias for each class. How many trainable parameters does it have?Show answer
Weights: 256 × 4 = 1024. Biases: one per class, so 4. Total: 1028.
QuestionIn the worked example, why did the loss fall after one update when the features never changed?Show answer
The features are fixed inputs, but the head weights are not. The gradient pointed toward a larger weight on the positive feature and a larger bias, which pushes the output toward the label 1. Moving the head in that direction lowers the loss for this example.
QuestionYour model was pretrained on natural photos and performs poorly on medical X-rays. Name a likely cause and a fix.Show answer
A likely cause is a domain gap, with early features that do not match the new images, possibly causing negative transfer. A fix is to fine-tune more layers, or to pretrain on unlabelled in-domain X-rays before adapting. Check the test inputs against the training inputs as well, since Covariate Shift can lower accuracy even after adaptation.
Sources
- Transfer learning (Wikipedia): https://en.wikipedia.org/wiki/Transfer_learning
- Yosinski, Clune, Bengio, Lipson, How transferable are features in deep neural networks? (2014): https://arxiv.org/abs/1411.1792
- Devlin et al., BERT: Pre-training of Deep Bidirectional Transformers (2018): https://arxiv.org/abs/1810.04805
- Howard and Ruder, Universal Language Model Fine-tuning for Text Classification (2018): https://arxiv.org/abs/1801.06146