In-Context Learning Under Regime Change

Carson Dudley, Yutong Bi, Xiaofeng Liu, Samet Oymak

TL;DR

This paper demonstrates that Transformers are mathematically capable of detecting and adapting to sudden "regime shifts" (change-points) within a single sequence without retraining. By formalizing this as an in-context change-point detection problem, the authors prove that Transformers can approximate optimal Bayesian predictors and show that providing simple "hints" via positional encodings significantly boosts forecasting accuracy in real-world financial and epidemiological data.

What Problem Does This Paper Address?

Most research on In-Context Learning (ICL) assumes that the "task" or data-generating process remains stationary throughout a prompt. However, real-world data is rarely that well-behaved. Markets crash, government policies change transmission dynamics of diseases, and sensors fail. These are "regime shifts"—abrupt changes where old data becomes obsolete or even misleading.

The challenge is: can a Transformer detect these shifts on the fly, decide which parts of its context to ignore, and adapt its predictions to the new "normal"? The authors tackle this by bridging the gap between classical statistical change-point detection and modern Transformer theory.

Methods

The authors approach the problem from three angles:

  1. Theoretical Construction: They provide a formal proof (Theorem 1) showing that a causal Transformer can approximate Bayesian Model Averaging (BMA). Their specific construction uses a 4-layer architecture:
  2. Layer 1: Computes "prefix sums" (running averages of the data).
  3. Layer 2: Uses attention heads to "retrieve" statistics from specific segments (isolating data before and after a potential shift).
  4. Layers 3-4: Use MLPs to compute the posterior probability of different change-points and output a weighted prediction.
  5. Information Hierarchy: They define four levels of "side information" provided to the model:
  6. No information: The model must detect the shift purely from data.
  7. Support known: The model knows the window when a shift might happen.
  8. Known in advance: The model is told exactly when a shift will occur before it happens.
  9. Known afterward: The model is told a shift happened only after the fact.
  10. Positional Encoding (PE) Hacks: Instead of retraining models, they use linear and sinusoidal positional encodings to "signal" the distance to a known event (like a policy change or a scheduled meeting), allowing the model to anticipate or react to shifts.

Datasets

  • Synthetic Linear Regression: Piecewise-linear sequences where the underlying weights ($w$) change abruptly at a stochastic point.
  • Thailand Infectious Disease Data (1980–2021): A real-world dataset containing multiple policy-driven shifts in disease transmission.
  • Financial Series (FRED): Daily data for the Effective Federal Funds Rate and the S&P 500 index, paired with FOMC (Federal Open Market Committee) statement dates as known regime-change triggers.

Key Insights and Ideas

  • Complexity vs. Information: The paper establishes a "capability–complexity tradeoff." If a model has no idea when a shift might occur, it needs more attention heads (scaling with the number of possible change-points) to track all hypotheses. If the timing is known, the model can be much leaner.
  • Transformers as Bayesian Reasoners: The results reinforce the idea that ICL isn't just "pattern matching"—it's a form of implicit Bayesian inference. The Transformer maintains a "posterior" over where the change-point might be and averages its predictions accordingly.
  • Don't Discard, Transfer: In cases where regimes are related (e.g., $w_2 = -w_1$), the Transformer doesn't just throw away old data; it learns to "transfer" knowledge from the old regime to the new one, matching the performance of a Transfer Ridge Regression baseline.

Key Results

  • Matching Optimality: In synthetic tests, trained GPT-2 style Transformers almost perfectly matched the performance of the mathematically optimal Bayesian baselines across all information levels.
  • Disease Forecasting: Adding positional information about policy changes reduced the Mean Absolute Error (MAE) by 25% during the critical transition periods compared to a standard model.
  • Financial Adaptation: For both interest rates and stock indices, simply encoding the "distance to the next FOMC meeting" via linear positional encoding consistently outperformed models that lacked this event-time information.

Limitations and Future Work

  • Piecewise-Linear Assumption: The theoretical proof relies on piecewise-linear dynamics. While many real-world shifts are abrupt, others are gradual (drifts), which this framework doesn't explicitly cover.
  • Single Change-Point: The current study focuses primarily on a single regime shift within a context window. Future work could explore sequences with multiple, frequent "jumps."
  • Construction vs. Training: The paper proves a Transformer can represent these algorithms, but it doesn't guarantee that standard SGD training will always find this specific, optimal configuration in more complex, non-linear tasks.

Summary updated

BibTeX
@inproceedings{dudley2026context,
  author = {Carson Dudley and Yutong Bi and Xiaofeng Liu and Samet Oymak},
  title = {{In-Context Learning Under Regime Change}},
  booktitle = {FMSD @ ICML},
  year = {2026},
  url = {https://openreview.net/forum?id=o3dwy5pDAJ},
}
Figure