Contextualizing Enhances Gradient Based Meta Learning

Evan Vogelbaum, Rumen Dangovski, Li Jing, Marin Soljacic

Abstract

Meta learning methods have found success when applied to few shot classification problems, in which they quickly adapt to a small number of labeled examples. Prototypical representations, each representing a particular class, have been of particular importance in this setting, as they provide a compact form to convey information learned from the labeled examples. However, these prototypes are just one method of representing this information, and they are narrow in their scope and ability to classify unseen examples. We propose the implementation of contextualizers, which are generalizable prototypes that adapt to given examples and play a larger role in classification for gradient-based models. We demonstrate how to equip meta learning methods with contextualizers and show that their use can significantly boost performance on a range of few shot learning datasets. We also present figures of merit demonstrating the potential benefits of contextualizers, along with analysis of how models make use of them. Our approach is particularly apt for low-data environments where it is difficult to update parameters without overfitting. Our implementation and instructions to reproduce the experiments are available at https://github.com/naveace/proto-context.

Introduction

Deep learning models are notoriously data-hungry, often requiring thousands of examples to achieve high performance. Few-shot learning (FSL) aims to bridge this gap, allowing models to learn new concepts from just a handful of examples. A popular approach is Meta-Learning, or "learning to learn," where a model like MAML (Model-Agnostic Meta-Learning) is trained to be easily fine-tuned on new tasks via a few gradient updates.

However, standard gradient-based meta-learners face two major hurdles:

  1. Poor Initialization: They often start with a generic classification head for every new task, relying entirely on the "inner loop" gradients to distinguish between classes.
  2. Overfitting: In extreme 1-shot scenarios, taking multiple gradient steps often leads the model to memorize noise rather than learning generalizable features.

We introduce ProtoContext, a framework that equips gradient-based meta-learning with "contextualizers"—generalized prototypes that use self-attention to adapt to specific tasks, providing a superior starting point for adaptation.

Methods

ProtoContext merges the strengths of Prototypical Networks (metric learning) and MAML (gradient-based adaptation). The core innovation is the Contextualizer, which creates task-specific head initializations before any gradient steps are taken.

The Workflow

  1. Feature Extraction: Images pass through a standard backbone to generate feature representations.
  2. Contextualization via Self-Attention: Instead of using raw prototypes (simple averages of features), the model employs a self-attention mechanism. This allows the prototypes and support examples to "attend" to each other, creating contextualized prototypes that are aware of the entire task's distribution.
  3. Task-Specific Head Initialization: These contextualized prototypes are used to initialize the weights and biases of the classification head. This ensures the head is already roughly configured for the specific classes in the current task.
  4. Gradient Adaptation: The model then performs standard MAML-style inner-loop updates to refine its predictions.
The ProtoContext workflow: from support inputs to task-specific head initialization.

Results and Analysis

The model was evaluated on several standard few-shot benchmarks, including Omniglot, Mini-ImageNet, Tiered-ImageNet, FGCV Aircraft, and Quickdraw. ProtoContext significantly outperforms baselines, particularly in the most challenging 1-shot settings. For example, on Omniglot (1-shot), it achieved ~96.7% accuracy, compared to ~75.3% for MAML++. On Tiered-ImageNet (1-shot), it reached ~54.3%, outperforming ProtoMAML (~49.7%).

Test accuracy vs. inner loop steps comparing MAML, ProtoMAML, and ProtoContext variants.

Key Insights

  • Overfitting Resilience: Unlike MAML, which often sees a performance drop if too many gradient steps are taken on a 1-shot task, ProtoContext remains stable. The contextualized initialization provides a "buffer" that prevents the gradients from pulling the model too far astray.
  • Initialization is Crucial: Ablation studies showed that randomizing the head before the inner loop significantly degrades performance, confirming that the meta-learned initialization of the head is doing heavy lifting.
  • Intra-class Similarity: ProtoContext consistently produced lower intra-class similarity (meaning tighter, better-separated clusters) than standard MAML, even before fine-tuning.

Conclusion

ProtoContext demonstrates that incorporating task-specific context into the initialization of gradient-based models can significantly boost performance and stability in few-shot scenarios. While highly effective in 1-shot tasks, future work will focus on scaling these benefits to larger support sets and extending the framework to reinforcement learning and regression tasks.

Summary updated

BibTeX
@inproceedings{vogelbaum2023contextualizing,
  author = {Evan Vogelbaum and Rumen Dangovski and Li Jing and Marin Soljacic},
  title = {{Contextualizing Enhances Gradient Based Meta Learning}},
  booktitle = {HPEC},
  year = {2023},
  doi = {10.1109/hpec58863.2023.10363479},
}
Figure