Transfer learning reuses knowledge a model already learned on one task or dataset to help it learn a new, related task faster and with far less data โ a pattern that quietly underlies almost every practical deep learning system covered throughout this entire hub, from fine-tuning BERT to adapting a pretrained CNN.
The Core Idea
Training a large model from scratch requires enormous data and compute (recall LLM Pretraining's trillions of tokens, or ImageNet's millions of labeled images). Transfer learning sidesteps this: start from a model already trained on a large, general dataset, then adapt it to your specific, often much smaller, target task โ reusing the general knowledge already captured, rather than rediscovering it from nothing.
Why This Works โ What Early Layers Actually Learn
| Domain | What Early/General Layers Learn | What Later/Task-Specific Layers Learn |
|---|---|---|
| Computer vision (CNNs) | Edges, textures, simple shapes โ useful for almost any visual task | Complex, task-specific object parts and categories |
| NLP (Transformers) | Grammar, general word/sentence relationships | Task-specific patterns (sentiment cues, domain vocabulary) |
This general-to-specific pattern is exactly why transfer learning works so well: the early, general-purpose knowledge transfers cleanly to a new task, while only the later, more specialized parts genuinely need to be relearned or adjusted.
Diagram
General knowledge from pretraining transfers directly; only task-specific layers need substantial retraining on the new data.
Code โ The General Pattern
import torchvision.models as models
import torch.nn as nn
pretrained_model = models.resnet50(weights="IMAGENET1K_V2") # trained on 1.2M+ ImageNet images
# Replace only the final classification layer for a NEW task (e.g. 10 classes instead of 1000)
pretrained_model.fc = nn.Linear(pretrained_model.fc.in_features, 10)
# Everything before this final layer retains its ImageNet-learned general visual knowledge
Common Mistakes
- Assuming transfer learning is a niche technique โ it's the practical default for the vast majority of real-world deep learning projects, since training genuinely from scratch is rarely justified given how effective and data-efficient starting from a pretrained model is.
- Applying transfer learning between tasks that share very little underlying structure โ the more different the source and target domains are, the less the general knowledge actually transfers usefully (a concern explored fully in Domain Adaptation).
Interview Relevance
Q: "Why does transfer learning work โ why would knowledge from one task actually help with a completely different one?" Many tasks within the same broad domain (images, text) share underlying general structure โ edges and textures for vision, grammar and word relationships for language โ that a model naturally learns early in training, before specializing toward its specific original task. This general knowledge transfers cleanly to new, related tasks, letting a new task start from an already-informed representation rather than random initialization.
Practice Question
Why would transfer learning from an ImageNet-trained model likely help more for a new "classify dog breeds" task than for a "classify types of financial fraud from transaction data" task?