General-Purpose In-Context Learning by Meta-Learning Transformers

Louis Kirsch, James Harrison, Jascha Sohl-Dickstein, Luke Metz · OpenReview

Abstract

Modern machine learning requires system designers to specify aspects of the learning pipeline, such as losses, architectures, and optimizers. Meta-learning, or learning-to-learn, instead aims to learn those aspects, and promises to unlock greater capabilities with less manual effort. One particularly ambitious goal of meta-learning is to train general-purpose in-context learning algorithms from scratch, using only black-box models with minimal inductive bias. Such a model takes in training data, and produces test-set predictions across a wide range of problems, without any explicit definition of an inference model, training loss, or optimization algorithm. In this paper we show that Transformers and other black-box models can be meta-trained to act as general-purpose in-context learners. We characterize phase transitions between algorithms that generalize, algorithms that memorize, and algorithms that fail to meta-train at all, induced by changes in model size, number of tasks, and meta-optimization. We further show that the capabilities of meta-trained algorithms are bottlenecked by the accessible state size (memory) determining the next prediction, unlike standard models which are thought to be bottlenecked by parameter count. Finally, we propose practical interventions such as biasing the training distribution that improve the meta-training and meta-generalization of general-purpose learning algorithms.

Introduction

Traditional machine learning relies heavily on human-engineered components like backpropagation and specific architectural priors. Meta-learning seeks to automate the discovery of these learning mechanisms. However, many existing approaches still incorporate significant human bias by hard-coding gradient-based updates or specific structural constraints. This research investigates whether a "vanilla" black-box model, such as a standard Transformer, can discover a general-purpose learning algorithm from scratch. The goal is to develop a General-Purpose In-Context Learner (GPICL) that can solve entirely novel tasks—such as classifying CIFAR10 images—after being trained only on a diverse distribution of synthetic tasks.

Methodology

The GPICL framework utilizes a standard Transformer architecture that processes a sequence of data points $(x_1, y_1, x_2, y_2, ... x_n)$ to predict the subsequent label $y_n$. In this setup, "learning" occurs entirely within the model's forward pass (in-context), without any gradient updates at test time.

To facilitate the emergence of a general algorithm, the researchers employed extensive Task Augmentation. Base datasets like MNIST were transformed into an nearly infinite supply of distinct classification tasks through random linear projections of images and random permutations of labels. The model was then meta-trained to minimize prediction error across this vast task distribution. To navigate training plateaus, the authors implemented interventions including increased batch sizes, optimized Adam stability parameters, and a curriculum that initially biases the model toward task memorization before transitioning to general learning.

Taxonomy of learning algorithms. A general-purpose learning algorithm is characterized by its ability to both learn (improve performance with more examples) and generalize to unseen tasks.

Results and Analysis

The Three Phases of Meta-Learning

The research identified three distinct behavioral phases determined by the number of tasks encountered during training:

  1. Task Memorization: The model stores specific task solutions in its weights.
  2. Task Identification: The model recognizes a previously seen task and retrieves the appropriate solution.
  3. General Learning-to-Learn: The model discovers a general-purpose rule that applies to entirely unseen datasets. This transition typically occurs when the number of training tasks exceeds a critical threshold (approximately 8,192 tasks).

Memory as the Primary Bottleneck

A key finding is that for in-context learners, state size (the information held in working memory/activations) is a more critical bottleneck than total parameter count. Models with fewer parameters but larger accessible state sizes often outperformed larger, more "forgetful" models.

Heatmaps illustrating accuracy on seen and unseen tasks for MLPs and Transformers. Transformers exhibit a clear phase transition toward generalization as both model size and the number of training tasks increase.

Generalization and Transfer

The GPICL demonstrated robust out-of-distribution generalization. A model trained solely on augmented MNIST variants successfully classified FashionMNIST and KMNIST images. In zero-shot dataset transfer tests, a model trained on MNIST achieved ~19% accuracy on CIFAR10 raw pixels—significantly above the 10% chance level. Furthermore, when integrated with pre-trained CLIP embeddings, the model's performance on CIFAR10 reached ~45% after only 100 examples, showing it can effectively leverage domain-specific knowledge.

Discussion and Limitations

While Transformers can successfully meta-learn general algorithms, they face constraints. The current reliance on random projections limits the model to fixed-size inputs and outputs. Additionally, the quadratic scaling of Transformers with sequence length makes learning from millions of examples computationally expensive compared to traditional SGD-based methods. Future work will focus on scaling these learners to more complex domains like natural language and robotics by developing more sophisticated task generation techniques.

Summary updated

BibTeX
@inproceedings{kirsch2022general,
  author = {Louis Kirsch and James Harrison and Jascha Sohl-Dickstein and Luke Metz},
  title = {{General-Purpose In-Context Learning by Meta-Learning Transformers}},
  booktitle = {MetaLearn @ NeurIPS},
  year = {2022},
  url = {https://openreview.net/forum?id=t6tA-KB4dO},
}
Figure