TL;DR
Meta-learning trains a model on many different tasks so that it becomes easy to adapt. Ordinary training learns one answer for one task. Meta-learning instead learns a starting point from which a few gradient steps, on a few labelled examples, give good results on a task the model has never seen. The learning happens at two levels: an inner loop adapts to one task, and an outer loop improves the starting point across tasks.
Builds on: Episodic Training · Leads to: MAML, Few-Shot Learning
Where it's used
Few-shot image classification. A model is shown a new set of object categories with only a handful of labelled photos per category. Meta-learned starting points were tested on image benchmarks such as miniImageNet, where the task is to classify new classes from a few examples each.
Robot control. A robot arm trained on many objects should pick up a new object after a few practice attempts, not after thousands. The MAML paper tests this idea in simulation: policies trained with policy gradient methods adapt to new goals and to simulated robots such as a cheetah and an ant after a few gradient steps.
Learned optimisers. Some systems replace the hand-written update rule of Gradient Descent with a rule learned across many training runs, so the optimiser itself adapts to the kind of problem it is given.
How it works
Take a toy family of tasks. The model has one number . Each task has a target , and its loss is . The gradient of that loss is . We use two tasks, with targets and , and start with . The inner step size is , and the outer step size is .
-
Adapt to task 1 with one inner step. The gradient at is . The adapted value is . Check: 1 is halfway between the start 0 and the target 2.
-
Adapt to task 2 with one inner step. The gradient is , so . Check: 3 is halfway between 0 and 6, as expected for this loss.
-
Score the adapted models on their own tasks. Task 1 gives , and task 2 gives . The meta-loss, which is the sum over tasks, is . Check: the meta-loss is large because one starting value cannot be close to both targets.
-
Update the starting point across tasks. Each adapted value moves by half the distance from to its target. The meta-gradient for task works out to , which is for task 1 and for task 2. Their sum is . One outer step gives . Check: the starting point moved from 0 toward 4, the average of the two targets.
flowchart TD A["Starting point theta"] --> B["Sample a batch of tasks"] B --> C["Inner loop: a few gradient steps on each task's support examples"] C --> D["Score each adapted model on that task's query examples"] D --> E["Outer loop: change theta to lower the total query loss"] E --> A
The math
Let be a distribution over tasks. Each task has a loss . The model has parameters , step size for adaptation, and step size for meta-training. Meta-learning chooses to minimise the expected loss of the adapted parameters over tasks:
Here is the parameter vector after one inner step on task . The outer variable is , and the objective is evaluated at .
Step 1 in symbols: the tasks
Each task is a small problem drawn from , such as a classification problem with a few classes. Each task has two sets of examples. The support set is used for the inner step, and the query set is used to score the adapted model. One sampled task with its two sets is called an episode, and a group of episodes used for one outer update is a meta-batch. In the toy example, the task is the target , and .
Step 2 in symbols: the inner update
In the toy example, , so . With this is , the midpoint between the start and the target.
Step 3 in symbols: the meta-objective
The meta-loss sums the loss of the adapted parameters over the tasks in a batch:
This is the same objective as the displayed definition, with the inner update substituted in. In the toy example, , which is smallest at equal to the average of the .
Step 4 in symbols: the meta-gradient
The outer gradient differentiates through the inner update with the Chain Rule:
Here is the Hessian of the task loss. The Hessian term is the second derivative that the inner step creates. In the toy example it is , so the factor is , which matches . The MAML paper notes that computing this term needs Hessian-vector products. Its first-order approximation drops the term, and on MiniImagenet that version performs nearly the same as the full method.
Step 5 in symbols: the outer update
In the toy example the meta-gradient summed over tasks is , so moves by toward the average target.
Worked examples
A task has target . Start with and use .
- Gradient of the loss at : .
- Inner step: .
- Loss after the step: .
Interpretation: with this step size the single gradient step lands exactly on the target, which is special to this quadratic loss. For a real network one step rarely reaches the answer, which is why meta-learning trains the starting point so that the few steps it does take are useful.
This is the walkthrough at a larger step, with a second starting point to compare.
- Two tasks, targets and . Start at , with and .
- Inner results: and .
- Query losses after adaptation: and . Total 10.
- Meta-gradients: and . Total .
- Outer update: .
- Now try a starting point of . The inner results are and . The query losses are and , so the total is 2, down from 10.
Interpretation: a starting point near the middle of the tasks lets one inner step reach both targets. The outer loop finds that middle by looking at how well the adapted models do, not by fitting either task directly.
A common setup is 5-way 5-shot. Each episode has 5 classes. For each class the model gets 5 labelled support images, and it is then tested on 15 query images per class.
- Support images per episode: . The inner loop adapts to these 25 images only.
- Query images per episode: . The query loss, computed after adaptation, supplies the meta-gradient.
- Images per episode in total: .
Try it: a meta-batch holds 4 episodes, each set up as above. How many images are used in one outer update, and how many of them are support images?
Answer: each episode has 100 images, so the meta-batch uses images. Of these, are support images, and the other 300 are query images.
Common mistakes and tradeoffs
It is tempting to think that meta-learning is the same as transfer learning. In fact transfer learning reuses one trained model on one new task, while meta-learning trains explicitly for fast adaptation across many tasks. The two can be combined, and a meta-learned starting point is one way to make transfer work with very little data.
It is tempting to think that the learning happens when the model sees the new task. In fact the outer loop does the learning, across many tasks, and the inner loop only adapts with a few steps. The new task contributes the adaptation, not the lesson.
It is tempting to think that a meta-learner just overfits its training tasks. In fact the test is on held-out tasks it has never seen, which is why the task distribution must be split so that the meta-learner is judged on tasks it did not train on. Without that split, the scores look good and mean little.
When to use it: when you have many related tasks and only a few examples for each new one, as in few-shot classification and fast robot adaptation. When not to use it: when there is one task with plenty of data, where ordinary training is cheaper and simpler. Full meta-learning is also costly, because each meta-step needs second derivatives or many inner steps. Alternatives: fine-tuning a pretrained model (Transfer Learning), metric-based methods that compare a new example with class averages such as prototypical networks, and In-Context Learning in large language models.
History
Researchers used the phrase learning to learn in the 1990s, for example in a 1998 book edited by Sebastian Thrun and Lorien Pratt. The idea was that a learner could gain experience across tasks, but the methods of the time were hard to apply to deep networks.
In 2017 Chelsea Finn, Pieter Abbeel and Sergey Levine published MAML. Its key move was to train the starting parameters so that a few ordinary gradient steps on a new task work well, and to differentiate through those steps during training. The paper states that the method is model-agnostic in the sense that any model trained with gradient descent can use it.
The method caught on because it needs no special architecture. That made it easy to try on image classification, regression and reinforcement learning, and the few-shot benchmarks gave a common way to compare methods.
Recap
- Meta-learning trains on many tasks so that a model can adapt to a new task with a few examples.
- The inner loop takes a few gradient steps on one task. The outer loop changes the starting point to lower the loss after those steps.
- The meta-gradient differentiates through the inner update, which brings in a second derivative of the task loss.
- Meta-learning is judged on held-out tasks, and it differs from transfer learning in how it is trained.
Read next: Few-Shot Learning for the setting it is most often used in, and MAML for the method in full.
Check yourself
QuestionWhat does the inner loop do, and what does the outer loop change?Show answer
The inner loop takes a few gradient steps on one task's support examples to produce adapted parameters. The outer loop changes the shared starting parameters so that the adapted models score well on the query examples across many tasks.
QuestionWith loss , , and , what is the adapted value ?Show answer
The gradient is . Then . This is the midpoint between 1 and 5.
QuestionWhy must meta-learning be evaluated on held-out tasks?Show answer
A meta-learner trained and tested on the same tasks can look good just by fitting those tasks. Testing on held-out tasks checks whether the learned starting point helps with tasks it has not seen, which is what the method is meant to do.
QuestionA team has 10,000 labelled photos of one product category and wants to recognise a new category from 5 photos. Should it use full meta-learning or fine-tuning a pretrained model? Explain briefly.Show answer
Fine-tuning a pretrained model is the simpler first choice. Meta-learning needs many related tasks to train on, and the team has only one large dataset and one new category. A pretrained model fine-tuned on the 5 photos, possibly with the large dataset, is cheaper and easier to evaluate, and it may be enough.
Sources
- Finn, Abbeel and Levine, Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks (2017), arXiv:1703.03400
- Meta-learning (computer science) (Wikipedia)