TL;DR
Contextually Guided Transformers (CGT) learn to extract an ongoing contextual summary vector ($y^\ell$) from an input sequence and use it to dynamically generate low-rank weight updates for subsequent layers. Once a prompt or demonstration prefix is processed, this context vector can be frozen and folded directly into the model’s feed-forward and attention weights. This produces a specialized model tailored to the prefix that operates without prompt tokens in its context window during inference.
What Problem Does This Paper Address?
Large Language Models (LLMs) rely on in-context prompts—such as system instructions or few-shot examples—to guide specialized behaviors. However, repeatedly processing long prompts during inference consumes significant memory and computation.
Existing methods that convert prompts into weight adjustments (e.g., hypernetworks) typically treat the prompt separately from the main input and require an independent, second model to predict parameter updates. The authors set out to integrate prompt interpretation, context condensation, and dynamic parameter generation directly into a single, unified causal Transformer architecture.
Methods
CGT processes tokens using a modified causal Transformer divided into two architectural stages:
- Two-Stream Information Pathway (Layers $\le \ell$): The lower layers maintain two activation streams: a standard local token representation $x^\nu$ and a contextual summary $y^\nu$. While $x$ attends only to previous $x$ activations, $y$ has full visibility over both $x$ and $y$. This ensures $x$ remains clean and independent, while $y^\ell$ aggregates global context across the sequence prefix.
- Low-Rank Weight Modulation (Layers $> \ell$): Beyond layer $\ell$, only $x$ continues forward. The extracted summary $y^\ell$ dynamically parameterizes linear operators $T^\kappa(x; y^\ell) = x + \delta W^\kappa(y^\ell)x$ inserted before self-attention and MLP blocks. Here, $\delta W^\kappa$ is constructed via a low-rank combination of learned template matrices weighted by coefficients computed from $y^\ell$. If $y^\ell$ is frozen, these linear transformations can be permanently folded into the subsequent weight matrices, adding zero latency during inference.
- Auxiliary Loss ($\mathcal{L}_{\text{aux}}$): To ensure that freezing $y^\ell$ at an arbitrary sequence split $s$ yields a capable model, training combines standard autoregressive cross-entropy with an auxiliary loss. This auxiliary loss freezes $y^\ell_{s-1}$ and evaluates continuation tokens $t_{\ge s}$ with the prefix removed.
- Slowness Prior & Element-Wise Regularizers: Context summaries should ideally vary smoothly rather than wildly fluctuate between tokens. While a Variational Autoencoder (VAE) framework with a Gaussian process prior can formalize this, stochastic sampling hurts model accuracy. Instead, the authors derive a deterministic element-wise regularizer:
- $R_C$ (Continuity): Penalizes differences between consecutive normalized context vectors $n_s = y^\ell_s / \|y^\ell_s\|$.
- $R_D$ (Orthogonality): Enforces orthogonality across different sequences in a mini-batch to prevent representation collapse.
Datasets
The authors evaluated CGT across three setups:
- Synthetic In-Context Learning (ICL): Sequences containing multiple arithmetic tasks ($n_{\text{tasks}} = 4$, $n_{\text{ex}} = 4$ examples per task). Tasks require inferring hidden real-valued multipliers $(a, b)$ from rounded linear combinations $C = \lfloor a A + b B \rfloor$.
- Linear Regression: Interleaved synthetic sequences of $(x_k, y_k)$ vectors where $y_k = U x_k + b + \epsilon$, testing the model's ability to update its internal linear mapping on the fly.
- Text Mixture Datasets: Sequences assembled from C4 and Wikipedia (spanning 8 distinct categories, such as Real-time operating systems and Theoretical physics), where multiple document excerpts are concatenated to evaluate topic transitions and text modeling.
Key Insights and Ideas
- Context "Folding": Because the modulation operators are linear in $x$, a frozen context vector $y^\ell$ can be absorbed directly into standard linear layers. A user can run a prompt once, "fold" the resulting $y^\ell$ into the weights, and discard the prompt tokens entirely for subsequent generation.
- Specialization Requires Explicit Objectives: Without the auxiliary loss, freezing $y^\ell$ caused the model to collapse, proving that Transformers do not naturally learn to isolate static task representations unless forced by an objective.
- Emergent Interpretable Latents: With element-wise regularization, $y^\ell$ stabilizes over the course of demonstrations and functions as an explicit task/topic embedding. In the synthetic ICL setup, a simple linear readout applied to $y^\ell$ accurately predicted the underlying parameters $a$ and $b$.
Key Results
- Synthetic ICL Parity: On the synthetic task, a standard baseline Transformer achieved 77.7% accuracy. A specialized CGT model (where $y^\ell$ was frozen after 2 examples and the prefix was removed) reached 77.5% accuracy—effectively matching full in-context performance without prompt retention. In contrast, freezing $y^\ell$ in an unregularized CGT yielded only 15.3% accuracy.
- Smoothness & Latent Quality: Element-wise regularization dropped representation variation across test examples from 0.80 to 0.07 and reduced the linear fit error for recovering task parameters from 0.19 to 0.04.
- Language Modeling (C4 & Wikipedia): On C4, adding a 128-dimensional context stream ($d_y=128$) to a $d_x=128$ model improved cross-entropy loss by 0.23. In topic clustering benchmarks, $y^\ell$ embeddings produced cleanly separated t-SNE clusters matching the 8 Wikipedia topic categories.
Limitations and Future Work
- Topic Drift over Long Sequences: Freezing $y^\ell$ on open-ended text improved language modeling loss over the initial ~200 tokens, after which thematic drift degraded performance relative to a dynamic model (though updating $y^\ell$ via an exponential moving average mitigated this).
- Scale: Experiments were limited to small GPT-2 scale configurations (6 to 12 layers, hidden dimensions $\le 224$); testing at modern LLM parameter scales remains open.
- Layer Sensitivity: Performance depended heavily on the split point $\ell$. For instance, in linear regression, placing $\ell$ too early degraded performance; the summary $y^\ell$ needed sufficient depth to form before being applied to modulate the network.
Summary updated