MAML for Classification and Regression
What you'll learn: How to implement MAML for supervised learning tasks, adapting the algorithm for both few-shot classification and regression problems.
The Core Idea
While MAML's inner/outer loop structure stays the same, the implementation details differ between classification and regression. The key differences lie in the loss function, output layer, and evaluation metrics you use during both the inner loop (task-specific adaptation) and outer loop (meta-update).
Classification Implementation
For few-shot classification (e.g., 5-way 1-shot):
- Output layer: Softmax over N classes
- Loss function: Cross-entropy loss
- Inner loop: Compute gradients on support set, update model parameters
- Outer loop: Evaluate adapted model on query set using cross-entropy, compute meta-gradients
The model learns an initialization that can quickly specialize to new classes with just a few labeled examples per class.
Regression Implementation
For few-shot regression:
- Output layer: Single continuous value (or multiple for multi-output)
- Loss function: Mean squared error (MSE) or L1 loss
- Inner loop: Same gradient update on support samples
- Outer loop: Evaluate on query points using regression loss
Here, the model learns to adapt quickly to new functions or prediction tasks from limited data points.
Key Implementation Details
Both tasks follow MAML's two-loop structure but differ in:
- Task sampling (classification: sample classes; regression: sample functions)
- Loss computation (categorical vs continuous)
- Evaluation metrics (accuracy vs MSE/MAE)
Key Takeaway: MAML adapts to both classification and regression by keeping the inner/outer loop structure intact while swapping the loss function and output layer to match the supervised learning task type.