Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Don’t start from zero
Training a network from scratch needs lots of labelled data. Transfer learning starts instead from a network already trained on a big related task, such as ImageNet photos or web text, and adapts it to yours. You can freeze the pretrained part and train only a new final layer, or gently retrain everything. The demo compares three strategies as the number of target labels grows (illustrative curves).
Labelled data is scarce in aerospace and robotics: defect images, rare failure modes, new sensors. Starting from pretrained models (ImageNet CNNs, foundation models) is the default way to get good results from a few hundred labels.
- 1. Transfer learning starts from…
- 2. Freezing the body and training a new head is called…
- 3. Transfer helps most when target labels are…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Feature extraction (linear probe): freeze all pretrained layers and train only a new head. A 2048 → 10 head has 2048·10 + 10 = 20,490 parameters.
- Full fine-tuning: update everything, with a learning rate about 10× smaller than for pretraining, often with warm-up.
- Partial fine-tuning: unfreeze only the top layers, which hold the most task-specific features. Gradual unfreezing (ULMFiT) unfreezes from the top down.
- Discriminative learning rates: lower layers get smaller rates, for example lr / 2.6^(depth from the top).
- Parameter-efficient fine-tuning: adapters, prefix tuning, or LoRA. LoRA adds a low-rank update BA to a frozen weight: rank 8 on a 4096 × 4096 matrix adds 8·(4096 + 4096) = 65,536 parameters (0.4%).
- Negative transfer: if source and target are unrelated, pretrained features can be worse than training from scratch.
- 1. LoRA rank-8 parameters for a 4096 × 4096 weight:
- 2. Lower layers in discriminative fine-tuning get…
- 3. Pretrained features worse than scratch is called…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Fine-tuning in code
Exercise 1.
- Build freezing masks.
- Compute ULMFiT-style layer-wise learning rates.
- Fit a ridge linear probe on frozen features.
Practice.
- In PyTorch, set
requires_grad=Falseon frozen parameters and pass parameter groups with their own learning rates to the optimiser. - Keep batch-norm layers in eval mode when the target set is tiny.
- Hugging Face
peftprovides LoRA and adapters;timmprovides pretrained vision backbones. - Always compare against a linear probe and a from-scratch baseline. Use the same preprocessing (normalisation, resolution) as in pretraining.
model = timm.create_model("resnet50", pretrained=True, num_classes=5)
for p in model.parameters(): p.requires_grad = False
for p in model.get_classifier().parameters(): p.requires_grad = True # linear probe
opt = torch.optim.AdamW([{"params": model.layer4.parameters(), "lr": 1e-4}, # or unfreeze the top block
{"params": model.get_classifier().parameters(), "lr": 1e-3}])- 1. Frozen parameters in PyTorch have…
- 2. LoRA is provided by…
- 3. Baselines to always run:
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Why it works. Lower layers learn general features (edges, textures, syntax) that many tasks share. Higher layers become task-specific; Yosinski and colleagues measured transferability falling with depth. If the target is a simple function of the source features, a linear probe needs only enough data to fit the head: few parameters, low variance.
Probe versus fine-tune. Fine-tuning can adapt the features but, with few labels, can also distort them and overfit. Kumar and colleagues showed it can even underperform probing out of distribution, and proposed linear probing first, then fine-tuning (LP-FT). With more data, fine-tuning usually wins.
Negative transfer. If the target depends on information the source network discarded, frozen features cannot recover it. Fine-tuning must relearn it, starting from a possibly poor initialisation. Domain similarity and the amount of target data decide which strategy wins.
- 1. Transferability tends to fall with…
- 2. LP-FT means…
- 3. Frozen features fail when the source…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.When does transfer help, and when does it hurt?
History.
- J. Yosinski, J. Clune, Y. Bengio and H. Lipson, “How transferable are features in deep neural networks?” (NeurIPS 2014).
- J. Howard and S. Ruder, “Universal language model fine-tuning” (ACL 2018).
- E. J. Hu et al., “LoRA” (ICLR 2022).
Exercise 2.
- World: inputs x ∈ ℝ²⁰, with shared latent features z = tanh(2Ax), where z has 8 dimensions.
- Tasks:
- source: 10 classes from z;
- related target: 3 classes from other directions of z;
- unrelated target: 3 classes from directions of x orthogonal to A, which z ignores.
- Network: a 20 → 32 → 32 MLP pretrained on 3000 source examples for 300 steps (source accuracy 0.758).
- Strategies for each target and size: from scratch, linear probe (frozen body, new head), and full fine-tuning (learning rate 0.003 vs 0.01). All use Adam for 300 steps.
| target, labels | scratch | linear probe | fine-tune |
|---|---|---|---|
| related, 30 | 0.548 | 0.722 | 0.674 |
| related, 300 | 0.798 | 0.794 | 0.831 |
| unrelated, 30 | 0.586 | 0.357 | 0.454 |
| unrelated, 300 | 0.877 | 0.524 | 0.826 |
- Transfer helps when labels are scarce and the tasks are related: +0.17 for the probe at 30 labels.
- The advantage shrinks with data: at 300 labels all three are within 0.04.
- Frozen features cause negative transfer on an unrelated task: 0.524 against 0.877 from scratch, because the pretrained features threw away the needed directions.
- Fine-tuning recovers most of it (0.826), but still trails scratch.
- Seeds: in seeds 1 and 2 the related 30-label probe scored 0.674 and 0.720 against scratch 0.572 and 0.608. The unrelated 300-label probe scored 0.484 and 0.477 against scratch 0.842 and 0.858.
- Settings were reduced for speed: an earlier version (20 → 64 → 64, 5000 source examples) took 52 s in the browser. It gave the same pattern, but a smaller probe advantage at 30 labels (+0.09).
Transfer learning in AI, robotics and aerospace
- Inspection: fine-tuning ImageNet backbones on a few hundred defect images of turbine blades or composites.
- Remote sensing: adapting pretrained models to new satellites or spectral bands.
- Robotics: fine-tuning vision-language-action foundation models on a new robot with limited demonstrations.
- Design lesson: try a linear probe first; fine-tune when you have enough labels or the domain differs.
References
- J. Yosinski, J. Clune, Y. Bengio and H. Lipson (2014). “How transferable are features in deep neural networks?” NeurIPS.
- J. Howard and S. Ruder (2018). “Universal language model fine-tuning for text classification.” Proc. ACL.
- A. Kumar et al. (2022). “Fine-tuning can distort pretrained features and underperform out-of-distribution.” Proc. ICLR.
- E. J. Hu et al. (2022). “LoRA: low-rank adaptation of large language models.” Proc. ICLR.