AI
Linear Recurrent Networks Learn From Context Like Gradient Descent
Researchers show how state-space models can implement in-context learning through a windowed cross-product mechanism, bridging the gap between transformer and recurrent architectures.
A new paper from arXiv demonstrates how linear recurrent neural networks (LRNNs) can perform in-context learning—adapting to new tasks from examples in their input—through a mechanism that mirrors gradient descent. This bridges a significant gap between the efficiency of recurrent models and the learning flexibility of transformers.
The Problem#
Transformers with self-attention have been shown to implement gradient descent during their forward pass, allowing them to solve new tasks by learning from examples provided as input. However, state-space models and other LRNNs are far more efficient for sequence modeling, operating at linear time cost. The question remained: could these faster recurrent architectures achieve the same kind of in-context learning without the quadratic complexity of attention?
The Solution: GRIL#
The authors introduce Gradient-based Recurrent In-context Learner (GRIL), a diagonal LRNN that decomposes a supervised gradient step into two parts. First, a short-window cross-product write updates an internal matrix state. Second, a multiplicative readout applies that accumulated gradient to new queries in the forward pass. For linear regression specifically, the model accumulates context gradients in a matrix state and deploys them efficiently, requiring only $O(f^2)$ learned parameters (where $f$ is feature dimension).
Extending the Approach#
The same design principle scales beyond linear regression. GRIL handles multi-step updates and cross-entropy classification, and the team demonstrate a limited MLP-based extension to non-linear regression as well. This modularity suggests the windowed cross-product mechanism is a general inductive bias that recurrent networks can exploit.
Validation and Performance#
On synthetic in-context learning tasks, trained GRIL models recover both the predicted behavior and the specific parameters that theory suggests they should learn. The architecture also generalizes to real-world benchmarks—Long Range Arena (efficient sequence modeling), language modeling, and associative recall—suggesting the approach is not merely a theoretical curiosity but a practical tool for building efficient learners.

