Continual and lifelong learning
Why this matters: Real-world AI must adapt continuously (new products in recommendation, new diseases in medical imaging, new languages in translation) without retraining from scratch every time. A self-driving car that forgets how to detect pedestrians after learning to recognize new road signs is catastrophic.
The Stability-Plasticity Dilemma
The challenge: standard SGD updates optimize only current task loss , overwriting weights useful for .
Lifelong Learning is used interchangeably, sometimes emphasizing transfer: new tasks benefit from old knowledge (forward transfer), old tasks improve from new knowledge (backward transfer).
Why Catastrophic Forgetting Happens (First Principles)
Let's derive why neural nets forget. Suppose we train task1 to convergence:
At , the gradient (local minimum). Now task 2 arrives. We update:
Why this step? We're moving in the direction that reduces . But this gradient is computed only on . If points in a direction that increases , we're actively making task 1 worse.
Catastrophic forgetting occurs because:
- Parameter overlap: The same weights must serve all tasks. Moving for task 2 disturbs the configuration optimized for task 1.
- No explicit memory: Standard SGD has no mechanism to remember once is gone.
where = accuracy on task after training through task . Negative BWT means forgetting.
Average forgetting across tasks:
Why max? We compare final performance to the best performance achieved on task before learning later tasks (forgetting is relative to peak, not just initial).
Three Families of CL Solutions
1. Regularization-Based (Protect Important Weights)
Idea: Identify which weights are critical for old tasks, then penalize changes to them when learning new tasks.
Why Fisher? It measures how much the log-likelihood changes if we perturb . High → parameter is "important" for the previous task's prediction.
For task , we minimize:
Why this form? The quadratic penalty is a second-order Taylor approximation of around :
where is the Hessian. Fisher approximates the diagonal of for classification (under mild assumptions). So we're saying: "move to minimize , but stay near in dimensions important for ."
Hyperparameter : Controls stability-plasticity trade-off. Large → strong penalty → more stability, less plasticity.
Compute Fisher on : For logistic regression, where .
Say has 100 examples, average , , :
- (important!)
- (less important)
Why this matters? When learning task 2, deviating by 0.1 costs . Deviating by 0.1 costs only . EWC automatically focuses rigidity where it's needed.
Task 2 loss with :
2. Replay-Based (Store and Rehearse Old Data)
Idea: Keep a small memory buffer of old examples and interleave them with new task training. This directly prevents forgetting by continually "reminding" the model of old tasks.
Why this works? Gradients now include from replayed data. Moving to reduce while also satisfying old losses forces a compromise—stability.
Key challenge: Memory size. If is fixed (say 5000 examples), how do we select which examples to store?
Reservoir Sampling: For a stream of total examples, select uniformly. When example arrives:
- If : store it.
- If : replace a random existing example with probability .
Why? This ensures each example has equal probability of being in , regardless of when tasks arrived.
Generative Replay: Instead of storing real data (privacy issues, memory), train a generative model on old tasks and sample "pseudo-examples" from it.
Equal allocation: Keep 200 from each task → 600 total. When sampling a mini-batch (size 32) for task 3, include ~10 task-1 examples, ~10 task-2, ~12 task-3 (weighted by buffer size or uniform).
Why this step? Ensures all tasks get "rehearsal time" proportional to their representation. Without this, if we only sampled task 3, we'd still forget1 and 2.
Alternative: Class-balanced buffer—if tasks have different class distributions, store equal examples per class.
3. Architecture-Based (Dedicate Parameters to Tasks)
Idea: Allocate separate sub-networks or parameters for different tasks, so learning task2 doesn't touch task 1's parameters at all.
Why? are frozen features from old tasks. learns to reuse them. Old parameters are never updated → zero forgetting by construction.
Downside: Model grows linearly with tasks. 10 tasks → 10× parameters.
PackNet: Prune the network after each task, "freezing" the winning lottery ticket for that task. New tasks use the remaining capacity (pruned weights).
Dynamic Expandable Network: Start small, add new neurons/layers only when new task needs more capacity. Freeze neurons important for old tasks.
Task 2: Classify cats (10 classes). Add a parallel 3-layer CNN column (new random init). Lateral connections from dog-column layer1 → cat-column layer 1, etc.
Why this helps? Cat column can reuse edge detectors and texture features learned for dogs (via connections), but has freedom to learn cat-specific features in without destroying dog features.
After task 2: Dog accuracy still 90% (frozen), cat accuracy 88%. Total params: 2× original.
Task 3: Birds (10 classes). Add bird column, connect to dog + cat. Now3× params, but dog still 90%, cat 88%, bird 85%.
Common Scenarios & Metrics
- Class-Incremental Learning (Class-IL): At test time, task ID is unknown. Model must correctly classify over all seen classes.
- Example: "Classify this image (could be dog, cat, or bird, but I won't tell you which task)."
- Harder, requires learning task-agnostic features and output heads.
Forward Transfer (does task help future task ?):
where is random-init accuracy on task . Positive FWT means knowledge from helped.
Ideal CL system: High ACC (good at all tasks), low Forgetting (remembers old tasks), positive FWT (knowledge transfer).
Key Algorithms Detail
Memory-Aware Synapses (MAS)
Similar to EWC, but computes importance without Fisher. For each parameter :
Why output gradient? If changing drastically changes the output , then is important for the learned function, regardless of the loss.
Loss for task :
Learning without Forgetting (LwF)
Knowledge distillation for CL. When learning task , use the old model as a "teacher":
Why this step? KL divergence penalizes the new model if its predictions on old tasks' outputs diverge from the old model. We're saying "on data from task , match your new predictions for old task heads to what the old model would have predicted."
No replay data needed, but requires multi-head output (separate heads for each task).
Task 2: 10-class CIFAR-100 (first 10 classes). Add a new output head .
Training on task 2 data :
- Forward pass with new : Get and .
- Forward pass with old : Get (frozen).
- Loss: .
Why this matters? Even though is from task 2, the KL term forces the task-1 head to maintain the same predictions the old model had. This implicitly preserves task-1 knowledge without seeing task-1 data.
Advanced: Gradient Projection Methods
If violated, project to the feasible region:
Why? This is a convex quadratic program. We're finding the gradient closest to that doesn't hurt old tasks (non-negative dot product means loss doesn't increase in that direction).
Intuition: Think of each task's gradient as defining a "don't go this way" constraint. GEM navigates the intersection of all constraints.
Mistake 1: "Continual learning is the same as transfer learning."
Why it feels right: Both involve learning multiple tasks.
The fix: Transfer learning: train on source task, then fine-tune on target. Source data remains available. Continual learning: sequential tasks, old data discarded, must prevent forgetting. Transfer doesn't address catastrophic forgetting.
Mistake 2: "Just replay all old data—problem solved."
Why it feels right: Rehearsing old examples prevents forgetting.
The fix: In real continual learning, storing all data is often impossible (privacy, memory, streaming). Replay is a compromise with a small buffer. Also, true lifelong learning (millions of tasks) would require massive storage. Replay is a tool, not the complete solution.
Mistake 3: "EWC's Fisher matrix is the Hessian, so it's exact."
Why it feels right: Fisher is often called a Hessian approximation.
The fix: Fisher measures curvature under the model's current predictions, Hessian measures curvature of the true loss surface. They coincide only for correctly specified log-likelihood models. For deep nets, Fisher is a practical approximation (diagonal, easier to compute) but not exact. EWC's quadratic penalty is only locally valid around .
Mistake 4: "In Class-IL, just concatenate all task outputs into one big softmax."
Why it feels right: Unified output seems natural.
The fix: Softmax normalization causes task recency bias: new task classes get higher probability because old task heads are frozen or under-trained. Need cross-entropy balancing, separate task outputs with gating, or specialized architectures (e.g., NCM classifiers).
Connections
- Catastrophic Forgetting: The core problem CL solves.
- Transfer Learning: CL extends transfer to multiple sequential tasks with forgetting prevention.
- Meta-Learning: Overlaps in learning to learn; MAML can adapt quickly with low forgetting.
- Regularization Techniques: EWC is L2 regularization weighted by importance.
- Knowledge Distillation: LwF uses distillation to preserve old task knowledge.
- Neural Architecture Search: Dynamic architecture methods (PackNet, DEN) relate to NAS for capacity allocation.
- Online Learning: CL is a form of online learning with non-stationary distributions.
- Neuroscience - Memory Consolidation: Biological inspiration; complementary learning systems (hippocampus for rapid learning, cortex for slow consolidation).
Recall Explain to a 12-Year-Old
Imagine you have a robot that learns tricks. First, you teach it to fetch a ball—it gets really good! Then you teach it to roll over. But here's the weird part: once it learns to roll over, it forgets how to fetch! That's catastrophic forgetting.
Why does this happen? The robot's brain (its "weights") is like a set of knobs. Turning the knobs one way makes it fetch. Turning them another way makes it roll over. When you train it to roll over, you twist the knobs, but that messes up the fetch settings.
Continual learning is about making the robot remember all its tricks. Three ways:
-
Protect important knobs (EWC): We mark which knobs are super important for fetching (like the "see the ball" knob). When teaching roll-over, we say "don't twist those knobs much."
-
Practice old tricks (Replay): Every day, we randomly make the robot fetch a few times while learning roll-over. It never fully forgets because it keeps rehearsing.
-
Separate controls (Architecture): Give the robot a "fetch brain" and a "roll-over brain." Each trick uses its own knobs, so they never interfere.
The goal? A robot that can learn10, 100, 1000 tricks and remember them all!
For EWC vs MAS: "Fish Eat Food" → Fisher uses Erors/Loss, MAS uses Function (output gradient).
#flashcards/ai-ml
What is catastrophic forgetting? :: When a neural network trained on Task 1, then Task 2, loses performance on Task 1 because parameters optimized for Task 1 are overwritten during Task 2 training. Standard SGD has no memory of old tasks.
EWC formula :: , where is the Fisher information (importance) of parameter for previous tasks. Penalizes changing important weights.
What does the Fisher Information measure in EWC?
Experience Replay objective
Stability-Plasticity Dilemma
Progressive Neural Networks architecture
Backward Transfer (BWT) formula
Learning without Forgetting (LwF)
Task-Incremental vs Class-Incremental
Gradient Episodic Memory (GEM) constraint
Why does catastrophic forgetting occur?
Memory-Aware Synapses (MAS) importance
Average Forgetting metric
Why is Class-IL harder than Task-IL?
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Dekho yaar, is note ka core idea bahut simple hai lekin powerful hai. Socho tum school mein French seekhte ho, phir Spanish, aur achanak French bhool jaate ho — yahi problem neural networks ke saath hoti hai, jise catastrophic forgetting kehte hain. Jab model naya task seekhta hai, toh wo apne purane task ke liye jo weights optimize kiye the, unko overwrite kar deta hai. Continual learning ka goal hai ki model naye tasks seekhe bina purane ko bhoole — bilkul insaan ki tarah jo knowledge accumulate karta hai, replace nahi karta.
Ab ye kyun hota hai, wo bhi samajh lo. Jab task 1 pe model converge ho jaata hai, tab uska gradient almost zero hota hai (minimum pe pahunch gaya). Phir task 2 aata hai, aur SGD sirf ka gradient nikaalta hai — sirf naye data pe. Agar ye direction task 1 ke loss ko badha deti hai, toh model actively task 1 pe kharaab ho jaata hai. Do main wajah hain: ek toh parameter overlap (same weights sabhi tasks ko serve karte hain), aur doosra no explicit memory (purana data chala gaya toh yaad rakhne ka koi mechanism nahi). Isko measure karne ke liye hum backward transfer (BWT) aur average forgetting use karte hain, jahan hum final performance ko peak performance se compare karte hain.
Ye cheez real-world mein bahut zaroori hai — jaise self-driving car agar naye road signs seekhne ke baad pedestrian detect karna bhool jaaye, toh disaster ho jaayega! Recommendation systems mein naye products, medical imaging mein nayi diseases — sab jagah AI ko continuously adapt karna padta hai bina scratch se retrain kiye. Solutions ke teen families hain, jaise regularization-based approach (EWC) jo Fisher Information use karke important weights ko protect karta hai — matlab jo weights purane task ke liye critical hain, unko change karne pe penalty lagti hai. Toh basically, continual learning ka pura khel stability (purana yaad rakhna) aur plasticity (naya seekhna) ke beech balance banane ka hai.