TRANSFORMERS · IN-CONTEXT LEARNING · 2024
Can a model learn a new task from its prompt?
A model may see examples of a new task in its prompt and then answer a new question. Its weights do not change during this process. What did training teach it that makes this possible?
Each sequence is a particular linear combination task.
Exact modulo-seven examples illustrate the prompt format; model weights do not change during in-context learning.
A controlled version of a familiar capability
We study in-context learning using a family of modular arithmetic tasks. Each task has the form z = ax + by, with the result taken modulo a prime number. Changing the coefficients gives a different task.
We train a GPT-style transformer on some tasks and reserve others for testing. The comparison separates success on new examples of familiar tasks from success on genuinely new coefficient pairs.
Task diversity changes what the model learns
As the number of training tasks grows, the model can move from solving familiar tasks to generalizing across tasks. We examine the representations in its attention heads and feed-forward layers to understand the computations behind this behavior.
The transition depends on architecture and training. In the deeper models we study, generalization to unseen tasks can be transient. Training longer is not always better; early stopping can matter.
Reading the little example
The animation shows three modular tasks in sequence. Each prompt contains three completed examples and a query. Earlier sequences shrink as the next task appears. Green coefficients mark the first two rules; red coefficients mark the third. The completed examples use exact arithmetic. The research question is when a trained network learns to perform this kind of inference.
The takeaway
We can identify the precise ways transformers compose skills to perform in-context learning in modular arithmetic setup.
A few useful terms
- In-context learning. Using examples in a prompt to perform a task without updating model weights.
- Modular arithmetic. Arithmetic in which results wrap around after a fixed integer.
- Out-of-distribution task. A task excluded from the set of tasks used for training.
THE PAPER
Learning to grok: Emergence of in-context learning and skill composition in modular arithmetic tasks
Tianyu He, Darshil Doshi, Aritra Das, Andrey Gromov
NeurIPS 2024
NEXT PROJECT