From Markov to Laplace: How Mamba In-Context Learns Markov Chains

Marco Bondaschi, Nived Rajaraman, Xiuying Wei, Razvan Pascanu, Caglar Gulcehre, Michael Gastpar, Ashok Makkuva

International Conference on Learning Representations 2026 · Oral

Overview

This talk, presented by Ashok Makkuva and Marco Bondaschi, delves into the fascinating capabilities of Mamba, a novel State Space Model (SSM), in performing in-context learning (ICL). Specifically, the research investigates how Mamba can learn Markov chains directly from sequences, demonstrating a profound connection between its architectural design and the mathematically optimal Laplacian smoothing estimator. This work is critical as Mamba has emerged as a promising alternative to Transformers, offering significant computational efficiency by replacing the quadratic complexity of attention mechanisms with a linear recurrent operation.

Watch on SlidesLive

Visual summary for From Markov to Laplace: How Mamba In-Context Learns Markov Chains by Marco Bondaschi, Nived Rajaraman, Xiuying Wei, Razvan Pascanu, Caglar Gulcehre, Michael Gastpar, Ashok Makkuva
Visual summary for From Markov to Laplace: How Mamba In-Context Learns Markov Chains by Marco Bondaschi, Nived Rajaraman, Xiuying Wei, Razvan Pascanu, Caglar Gulcehre, Michael Gastpar, Ashok Makkuva

Key moments

  1. 0:00 Introduction to Mamba and its computational efficiency
  2. 0:30 Detailed explanation of the Mamba block architecture
  3. 1:00 In-context learning task: Markov chains and optimal estimator
  4. 2:00 Mamba's performance tracking optimal Laplacian estimator
  5. 2:30 Key architectural components enabling Mamba's learning
  6. 3:00 Mamba's limitations and comparison with Transformers
  7. 3:30 Discussion: Laplacian estimator and Bayesian context
  8. 4:00 Why Markov chains are a good testbed

From Markov to Laplace: How Mamba In-Context Learns Markov Chains

Speakers: Marco Bondaschi, Nived Rajaraman, Xiuying Wei, Razvan Pascanu, Caglar Gulcehre, Michael Gastpar, Ashok Makkuva

Conference: ICLR 2026

YouTube: https://slideslive.com/39062065

Overview

This talk, presented by Ashok Makkuva and Marco Bondaschi, delves into the fascinating capabilities of Mamba, a novel State Space Model (SSM), in performing in-context learning (ICL). Specifically, the research investigates how Mamba can learn Markov chains directly from sequences, demonstrating a profound connection between its architectural design and the mathematically optimal Laplacian smoothing estimator. This work is critical as Mamba has emerged as a promising alternative to Transformers, offering significant computational efficiency by replacing the quadratic complexity of attention mechanisms with a linear recurrent operation.

The core of the presentation unravels the internal mechanisms that enable Mamba to effectively capture and generalize transition probabilities from diverse Markov sequences. By meticulously analyzing Mamba's recurrent block and its interaction with convolutional components, the researchers reveal how the model implicitly constructs an optimal Bayesian estimator for conditional probabilities. This theoretical understanding not only illuminates Mamba's strengths in sequence modeling but also provides a concrete, interpretable context for its in-context learning prowess, a capability often observed in large language models but rarely explained with such mathematical precision.

The significance of this research extends beyond theoretical curiosity. As AI models grow in scale and complexity, understanding the computational and statistical underpinnings of their learning mechanisms becomes paramount. By demonstrating Mamba's ability to efficiently and accurately learn fundamental statistical patterns like Markov chains, this work contributes to a broader effort to develop more interpretable, efficient, and robust sequence models. It offers insights into when and why Mamba might be preferred over Transformers, particularly in scenarios where capturing local dependencies and precise statistical counts is crucial.

Background

▶ Watch: Introduction to Mamba and its computational efficiency (0:00)

The landscape of sequence modeling in machine learning has been largely dominated by Transformers over the past few years. Their success, particularly in natural language processing, stems from their attention mechanism, which allows them to weigh the importance of different parts of the input sequence when processing each token. However, this mechanism comes with a significant computational cost: its complexity scales quadratically with the sequence length. As input sequences grow longer, the computational demands and memory footprint of Transformers become prohibitive, posing a major challenge for applications requiring very long contexts.

This limitation spurred the development of alternative architectures, among which State Space Models (SSMs) have gained considerable traction. Mamba, in particular, stands out as a recent and highly effective SSM that addresses the quadratic complexity issue. Mamba replaces the attention block with a linear recurrent operation, enabling it to process sequences with complexity that scales linearly with sequence length. This efficiency makes Mamba a compelling candidate for tasks where Transformers struggle, such as processing very long documents, genomic sequences, or high-resolution time series data.

A crucial capability observed in modern large language models, including Transformers, is in-context learning (ICL). ICL refers to the phenomenon where a model can learn a new task or adapt to new patterns simply by observing examples provided within its input prompt, without requiring explicit weight updates or fine-tuning. While ICL is empirically powerful, the precise mechanisms by which models achieve it are often opaque, making it a subject of intense research. Understanding how models perform ICL, especially in architectures like Mamba, is vital for designing more predictable and robust AI systems.

To provide a mathematically tractable setting for studying ICL, this research focuses on Markov chains. A K-th order Markov chain is a stochastic process where the probability of the next state depends only on the K preceding states. These chains are fundamental models for sequence data, widely studied in probability theory and statistics, and offer a clear, well-defined framework for analyzing sequence dependencies. The task set for Mamba is to learn the underlying transition probabilities of multiple distinct Markov chains from example sequences and then apply this learned knowledge to predict tokens in a new test sequence.

Within this context, the notion of an optimal estimator for conditional probabilities becomes relevant. For Markov chains, especially when dealing with unseen events or sparse data, a technique known as Laplacian smoothing (or the add-beta estimator) is often employed. This estimator assigns a small, non-zero probability to events that have not yet occurred, preventing zero probabilities and ensuring a more robust estimation. Mathematically, for a given context, the Laplacian smoothing estimator adds a pseudo-count (typically +1, hence "add-one smoothing") to observed event counts before normalizing, effectively smoothing the probability distribution. This estimator is known to be optimal in certain Bayesian settings, making it an excellent benchmark for evaluating a model's ability to learn and generalize statistical dependencies in context. The central question addressed by this talk is whether Mamba, with its unique architecture, can effectively implement and leverage this optimal Laplacian smoothing estimator for in-context learning of Markov chains.

Key Findings

▶ Watch: In-context learning task: Markov chains and optimal estimator (1:00)

The research presents several pivotal findings that shed light on Mamba's in-context learning capabilities for Markov chains and its underlying mechanisms:

  1. Mamba In-Context Learns Optimal Laplacian Estimators: The most significant discovery is that the full Mamba architecture, when trained on various K-th order Markov chains, effectively learns to implement the optimal Laplacian smoothing estimator for predicting the next token. This means Mamba can accurately capture and generalize the conditional probabilities of Markov transitions, even for unseen events, closely matching the predictions of this mathematically optimal estimator.
  1. Crucial Role of Convolution and Recurrence: The study highlights that the interplay between Mamba's convolutional layer and its recurrent mechanism is absolutely essential for this capability. Experiments showed that a modified Mamba architecture without convolution failed to learn the optimal estimator, underscoring the convolution's critical role in processing and extracting relevant features from the input sequence.
  1. Convolution Window Size Matters: For Mamba to successfully implement the Laplacian estimator for a K-th order Markov chain, the convolution window size (W) within the Mamba block must be at least K+1. This specific window size allows the model to effectively consider the full context required by a K-th order Markov process for accurate probability estimation.
  1. Hidden State as a Count Tracker: The research found that the hidden state of the Mamba model at any given time step T implicitly functions as a tracker for the counts of the K+1 tokens in the recent past. This is a key insight into how Mamba stores and processes contextual information relevant for Markov chain transitions.
  1. Skip Connection for Smoothing: The skip connection (represented by the gating mechanism CT in Mamba's output) plays a crucial role in implementing the "+1" smoothing factor of the Laplacian estimator. This element enables Mamba to assign non-zero probabilities to events that haven't explicitly occurred in the immediate context, thereby facilitating robust generalization.
  1. Comparison with Transformers: While two-layer Transformers also showed an ability to track the Laplacian estimator, they exhibited significantly higher variance in their predictions. Conversely, one-layer Transformers were found to be largely incapable of capturing in-context transitions effectively, suggesting that depth and the complexity of the attention mechanism are critical for Transformers' ICL, whereas Mamba achieves similar accuracy with a more efficient, linear-scaling architecture in this specific task.

These findings collectively provide a concrete, interpretable explanation for Mamba's in-context learning abilities in a well-defined mathematical setting, revealing how its architectural components collaboratively implement a sophisticated statistical estimator.

Technical Deep Dive

▶ Watch: Key architectural components enabling Mamba's learning (2:30)

The core of Mamba's efficiency lies in its departure from the attention mechanism of Transformers, adopting a State Space Model (SSM) architecture that processes sequences linearly. The talk meticulously explains how the Mamba block is structured and, more importantly, how its components enable the in-context learning of Markov chains through the implementation of the Laplacian smoothing estimator.

A standard Mamba block processes an input sequence $x_1, \dots, x_T$ of length $T$ using two key steps:

  1. Convolutional Feature Extraction: At each time instant $T$, the model applies a convolution window of size $W$ over the input sequence. This convolution computes several vectors, notably $X_T$, $A_T$, and $B_T$. The vector $A_T$ is particularly important as it controls "how much information from the past goes to the current state." The size of this convolution window, $W$, is a critical parameter, discovered to be $K+1$ for effectively learning K-th order Markov chains.
  1. Linear Recurrence and Gating: Following the convolution, Mamba employs a linear recurrence to update its hidden state $H_T$. The hidden state at time $T$ is updated by taking the outer product of $X_T$ and $B_T$ and adding it to the past state. The output at each time step is then extracted from this hidden state using another gating mechanism, $C_T$, which is also a result of a convolution function. This $C_T$ vector acts as a selector, determining which parts of the hidden state are relevant for the current output.

The task for Mamba in this research is to perform in-context learning for K-th order Markov chains. Given $N$ different Markov sequences, each generated from a unique K-th order transition matrix, Mamba's goal is to learn these $N$ transition matrices in-context. Then, for a new test sequence, it must estimate the transitions and predict the next token based on the learned patterns.

The Laplacian smoothing estimator is the target for Mamba's in-context learning. For predicting the probability of the next token $M$ given a context $S$ of length $K$ (i.e., $S = s_{T-K}, \dots, s_{T-1}$), the Laplacian estimator is defined as:

$P(M | S) \propto \text{count}(S, M) + 1$

where $\text{count}(S, M)$ is the number of times the sequence $S$ followed by $M$ has occurred in the training data, and the "+1" term is the smoothing factor. This estimator effectively assigns non-zero probabilities to events that have not been observed, preventing issues with sparse data. The "effective context length" for this estimator is $K+1$ tokens (the $K$ tokens of the context plus the predicted token $M$).

The researchers identified how Mamba's architecture implements this optimal estimator:

  • Interplay of Convolution and Recurrence: The study found that Mamba's ability to learn the Laplacian estimator hinges on the synergistic relationship between its convolution and recurrence. The convolution provides the necessary local context, while the recurrence integrates this information over time.
  • Convolution Window for Contextual Counts: The convolution window of size $W = K+1$ is crucial. It ensures that Mamba processes exactly the $K+1$ tokens required to form a complete $K$-th order transition (the $K$ context tokens and the potential next token). This window allows the model to compute outer products that effectively represent transition matrices and their counts.
  • Hidden State as a Sum of Past Outer Products: The hidden state $H_T$ in Mamba is effectively a weighted sum of outer products of vectors $X_i$ and $B_i$ from the past. For the Laplacian estimator, this hidden state acts as a memory accumulator, storing information about the counts of all observed $K+1$ token sequences. The speaker notes that the weights are "equal for the part in the model which stores transition information," implying a uniform aggregation of counts.
  • The Role of $A_T$ and $C_T$: The $A_T$ vector controls how much past information is incorporated, while the $C_T$ vector (from the skip connection) is where the "magic happens" for the smoothing factor. The $C_T$ effectively introduces the "+1" term into the probability estimation, ensuring non-zero probabilities for unobserved transitions. This is a critical component for implementing the Laplacian smoothing.
  • Linear Scaling of Hidden State: The hidden state dimension in Mamba needs to scale linearly with $K$ to implement the optimal estimator, as it needs to track the counts of all possible $K+1$ token combinations. While Mamba generally offers linear complexity in sequence length, this specific requirement for optimal Laplacian estimation introduces a dependency on the context order $K$ for the hidden state size.

In contrast, Transformers handle long-term dependencies by "denoising" the past signal through the attention mechanism, effectively selecting the most important information. While this allows Transformers to model very long contexts, Mamba's approach, particularly for Markov chains with small $K$, is more direct and computationally efficient for capturing precise statistical counts.

Experimental Setup & Results

▶ Watch: Mamba's limitations and comparison with Transformers (3:00)

The experimental validation of Mamba's in-context learning capabilities focused on its ability to emulate the Laplacian smoothing estimator for Markov chains. The setup was designed to directly compare Mamba against Transformer architectures and to dissect the contribution of Mamba's individual components.

Task:

The primary task involved in-context learning of K-th order Markov chains. The model was presented with a sequence composed of multiple distinct Markov chains (N different chains). For each chain, the model observed a series of tokens generated according to its specific K-th order transition matrix. The objective was for the model to learn these N transition matrices implicitly and then, when presented with a new test sequence from one of these chains, accurately predict the next token's conditional probability based on the K preceding tokens. The "optimal" behavior was defined by the predictions of the Laplacian smoothing estimator.

Baselines:

To understand the relative performance and specific advantages of Mamba, the researchers compared it against:

  1. Two-layer Transformers: Representing a standard, capable Transformer architecture.
  2. One-layer Transformers: To assess the impact of architectural depth on Transformer's ICL.
  3. Mamba without convolution: A modified Mamba block where the convolutional component was removed, to isolate its contribution.

Hardware and Software:

While specific hardware (e.g., GPU types) and framework versions were not explicitly detailed in the transcript, the experiments were conducted in a standard ML research environment, likely utilizing modern GPUs and deep learning frameworks like PyTorch or TensorFlow, given the ICLR conference context.

Metrics:

The primary metric for evaluation was how closely the predictions of the tested models (Mamba, Transformers) tracked the Laplacian smoothing estimator's predictions. This involved plotting and comparing the predicted conditional probabilities. The goal was to assess accuracy and consistency in emulating the optimal statistical estimator.

Headline Numbers & Key Observations:

  • Full Mamba's Superiority: The full Mamba architecture (with both convolution and recurrence) demonstrated a remarkable ability to learn the optimal Laplacian estimator. Its predictions "track the Laplacian estimator super sharply," almost perfectly matching its behavior. This was the strongest result, indicating Mamba's high fidelity in capturing the underlying statistical properties.
  • Transformer Performance:
  • Two-layer Transformers also showed an ability to track the Laplacian estimator "quite close." However, a significant caveat was observed: they suffered from "a huge bit main error high variance" compared to the optimal estimator. This implies less stable or consistent predictions.
  • One-layer Transformers were found to be "not able to capture in-context transitions well." This suggests that the attention mechanism's complexity and depth are crucial for Transformers to perform effective ICL, even in this constrained setting.
  • Ablation Studies on Mamba:
  • Mamba without convolution: This variant "doesn't learn the optimal estimator." This was a critical finding, definitively proving that the convolutional component is indispensable for Mamba's ICL capabilities in this domain.
  • Convolution window size: The experiments confirmed that the convolution window W must be of size K+1 for a K-th order Markov chain. If W was smaller, Mamba could not accurately learn the estimator. This highlights a specific architectural requirement for Mamba to correctly extract the necessary contextual information.
  • Skip Connection's Role: The skip connection (via the C_T gating mechanism) was identified as the component responsible for implementing the "+1" smoothing factor in the Laplacian estimator. Without this, the model would only learn raw counts, not the smoothed probabilities.

These results provide strong empirical evidence for Mamba's unique strengths, particularly its efficiency and accuracy in learning specific statistical structures like Markov chains, and underscore the precise roles of its architectural components in achieving this.

Practical Implications

▶ Watch: Why Markov chains are a good testbed (4:00)

This research offers several significant practical implications for practitioners, infrastructure teams, model builders, and deployers working with sequence models:

  1. Mamba for Specific Task Types: The findings suggest that Mamba is particularly well-suited for tasks that involve learning and applying precise, localized statistical dependencies, such as those found in Markov chains. For applications where the "optimal thing to do is next token prediction in order K language models" (i.e., when $K$ is small and fixed), Mamba's efficiency and accuracy in emulating the Laplacian smoothing estimator make it a strong candidate. This could include specific types of time-series forecasting, genomic sequence analysis, or certain code generation tasks where local patterns are paramount.
  1. Efficiency vs. Generality Trade-offs: While Mamba offers superior computational efficiency (linear complexity in sequence length) compared to Transformers (quadratic complexity), this work highlights a nuanced trade-off. For Mamba to implement the optimal Laplacian estimator, its hidden state dimension needs to scale linearly with the context length $K$. If $K$ becomes very large, this linear scaling of the hidden state could become a bottleneck, potentially offsetting some of Mamba's efficiency gains. Transformers, by contrast, can "denoise" the past signal through attention, allowing them to model very long-term dependencies with a fixed hidden state size, albeit at a higher computational cost. Practitioners must weigh this trade-off: Mamba for efficient, precise local pattern learning with manageable $K$; Transformers for extremely long-range, diffuse dependencies where a fixed hidden state is crucial.
  1. Architectural Design Principles: The detailed analysis of Mamba's components (convolution window, recurrence, skip connection) provides valuable architectural design principles. It emphasizes that for models to perform specific forms of in-context learning, their internal structure must inherently support the computational steps required by the target estimator. The necessity of a convolution window of size $K+1$ and the role of the skip connection for smoothing are concrete examples of how architectural choices directly impact a model's learning capabilities. Model builders can use these insights to design more interpretable and purpose-built architectures.
  1. Interpretability and Trust: By demonstrating how Mamba explicitly implements a known, optimal statistical estimator, this research contributes to the broader goal of interpretable AI. Understanding why a model makes certain predictions, rather than just what it predicts, is crucial for building trust and ensuring reliability, especially in high-stakes applications. This work provides a concrete example of a neural network whose in-context learning can be theoretically grounded and explained.
  1. Benchmarking and Evaluation: The use of Markov chains and the Laplacian estimator provides a robust, mathematically well-defined benchmark for evaluating in-context learning capabilities. This framework can be adopted by researchers to test other novel architectures and gain deeper insights into their ICL mechanisms, moving beyond purely empirical observations.
  1. Future Research Directions: The findings open avenues for future research, such as investigating if Mamba can emulate other known optimal estimators for different data distributions or how its internal mechanisms adapt to more complex, non-Markovian dependencies. It also prompts questions about how to optimize Mamba's hidden state scaling for very large $K$ values.

In summary, this talk positions Mamba as a highly capable and efficient model for specific types of in-context learning, particularly when dealing with well-defined statistical patterns like Markov chains. It provides a theoretical backbone to Mamba's observed performance, offering practical guidance on its application, architectural understanding, and the crucial trade-offs involved in selecting between Mamba and Transformer architectures.

Key Takeaways

  • Mamba excels at in-context learning of Markov chains, precisely emulating the behavior of the optimal Laplacian smoothing estimator.
  • The interplay between convolution and recurrence is fundamental to Mamba's ability to capture and generalize Markov transitions.
  • A convolution window size of K+1 is critical for Mamba to learn a K-th order Markov chain, allowing it to accurately accumulate contextual counts.
  • Mamba's hidden state effectively tracks token counts, while the skip connection (via CT) implements the +1 smoothing factor of the Laplacian estimator.
  • While two-layer Transformers can also track the Laplacian estimator, they exhibit higher variance; one-layer Transformers struggle significantly with this task.
  • Mamba offers computational efficiency (linear complexity) for sequence length, but its hidden state dimension needs to scale linearly with the Markov order K for optimal Laplacian estimation, posing a potential trade-off for very large K.

About the Speaker(s)

The talk was presented by Ashok Makkuva and Marco Bondaschi. They are part of a larger research team including Nived Rajaraman, Xiuying Wei, Razvan Pascanu, Caglar Gulcehre, and Michael Gastpar. While specific titles and affiliations for each speaker were not detailed in the transcript, their collective work focuses on advancing the understanding and capabilities of AI/ML models, particularly in the domain of sequence modeling and in-context learning, as evidenced by this deep dive into Mamba's theoretical underpinnings. The presentation suggests a strong background in machine learning theory, neural network architectures, and statistical modeling.

Reviews

  • Maya Iyer (Theoretical ML Researcher) — MUST SEE ★★★★★
  • Chen Zhao (Applied ML Researcher & Empiricist) — MUST SEE ★★★★★

→ Top-rated talks at International Conference on Learning Representations 2026

All talks from International Conference on Learning Representations 2026