Episode 4: Transfer Learning — Reusing Existing Knowledge
Table of contents
Where does it come from?
Someone who knows how to play tennis doesn't learn badminton from zero. They reuse their reflexes. In the same way, a model that has learned to recognize cats doesn't need to relearn what an edge or a texture is.
In AI, the idea took off with deep networks around 2012, then with LLMs in 2018. The key observation: the first layers learn generic things, the last ones learn specific things.
Why do we do it?
- Saves time: training from scratch costs millions. Fine-tuning takes a few hours.
- Saves data: a model pre-trained on 10M images has already "understood" what an image is.
- Better performance: a fine-tuned model often beats a model trained from scratch on the same data.
The 3 strategies
1. Feature Extraction
You freeze all the layers and train only a new final layer. The model acts as a "feature detector".
2. Fine-Tuning
You unfreeze all or part of the model and retrain it with a very low learning rate.
3. LoRA (Low-Rank Adaptation)
You add small matrices next to the existing ones and train only those: often less than 1% of the model's parameters. Combined with a model loaded in 4-bit (QLoRA, 2023), you can even fine-tune a 70-billion-parameter model on a single high-end GPU.
The link with attention
- You keep the first layers (spelling, grammar, relationships)
- You retrain the last ones (your specific task)
Like a building: you keep the structure (everything the model has already learned) and adjust only a small part of it. Either you redo the top floors (fine-tuning the last layers), or you add a few partitions on top (LoRA).
Key takeaways
- Reuse existing knowledge to learn faster and better
- Three strategies: feature extraction, fine-tuning, LoRA
- Without transfer learning, only the giants could train models
Read next
- Step 6 of 7•2 minEpisode 5: The Key Concepts Around Transfer Learning
Pre-training, fine-tuning, catastrophic forgetting, freezing, domain shift and learning rate: the transfer learning terms you hear all the time, explained simply with an analogy for each.
- Step 7 of 7•3 minEpisode 6: Embeddings and Vector Databases
- Step 1 of 7•2 minEpisode 0: Why Code LLMs From Scratch