Large Language Models as Markov Chains

## Abstract

Abstract Large language models (LLMs) have proven to be remarkably efficient, both across a wide range of natural language processing tasks and well beyond them. However, a comprehensive theoretical analysis of the origins of their impressive performance remains elusive. In this paper, we approach this challenging task by drawing an equivalence between generic autoregressive language models with vocabulary of size T 𝑇 T italic_T and context window of size K 𝐾 K italic_K and Markov chains defined on a finite state space of size 𝒪 ⁢ ( T K ) 𝒪 superscript 𝑇 𝐾 \mathcal{O}(T^{K}) caligraphic_O ( italic_T start_POSTSUPERSCRIPT italic_K end_POSTSUPERSCRIPT ) . We derive several surprising findings related to the existence of a stationary distribution of Markov chains that capture the inference power of LLMs, their speed of convergence to it, and the influence of the temperature on the latter. We then prove pre-training and in-context generalization bounds and show how the drawn equivalence allows us to enrich their interpretation. Finally, we illustrate our theoretical guarantees with experiments on several recent LLMs to highlight how they capture the behavior observed in practice.

## 1 Introduction

The fields of machine learning and artificial intelligence have recently seen significant progress with the introduction of large language models (LLMs) (Brown et al., ; Touvron et al., ), built on the transformer architecture (Vaswani et al., ). These models, trained on vast amounts of data, have been applied in many natural language processing tasks, including machine translation (Brown et al., ), text generation, question answering (Roberts et al., ), and sentiment analysis (Zhang et al., ). Although successful in practice, the origins of the impressive performance of LLMs remain elusive, as there is no widely accepted agreement in the scientific community on how they achieve remarkable reasoning capabilities that go far beyond their training data (Brown et al., ).

This work takes a step towards bridging the knowledge gap mentioned above by providing an explicit characterization of the LLM’s inference capabilities. For this, we adopt an intuitive, yet overlooked, approach that interprets LLMs as Markov chains operating on a finite state space of sequences and tokens (see Fig. 1). A key insight is that despite the seeming infinity of LLMs generating capacity, they have a limited vocabulary and context window making all their possible input and output sequences enumerable. We show that despite the prohibitively large size of the latter set, it exhibits a structure that makes it amenable to theoretical analysis. We further generalize recent theoretical advances on the generalization of LLMs and leverage our proposed point of view to provide a more insightful interpretation of them.

Figure: Figure 1: LLM as a Markov chain. An autoregressive model with vocabulary size $T$ and context window $K$ is equivalent to a Markov chain with a sparse and block-structured transition matrix of size $\smash{\sum_{i\leq K}T^{i}\sim\mathcal{O}(T^{K})}$. The latter captures all possible outputs of a given LLM for all possible input sequences allowed by its vocabulary and context window.
Refer to caption: x1.png

##### Markov chains and Large Language Models.

While none of the prior works considered the equivalence between autoregressive models and Markov chains presented in this work(^1^11We note, however, a recent blog post (Nardo, ) discussing a similar idea on a high level without analyzing it at the level of details of this work.), some used the Markovian generative process to better understand the intrinsic capabilities of the transformer architecture. Makkuva et al. () assume that the input data is generated by an unknown high-order Markov chain to analyze the learning dynamics of the self-attention mechanism in a single-layer single-head transformer. Similarly, Edelman et al. () study in-context learning of a transformer model trained on samples drawn from a bi-gram Markov chain. Ildiz et al. () establish an equivalence between context-conditioned Markov chains and the self-attention mechanism in transformers to show that self-attention weights can be learned, under certain conditions, by prompting the model. In contrast to this prior work, we seek to model any autoregressive model regardless of its exact architecture as a Markov chain. Our analysis provides insights into LLMs beyond understanding the self-attention mechanism in simplified transformers.

##### In-Context Learning (ICL).

ICL is the ability of LLMs to adapt their predictions during inference by leveraging examples or prompts directly without updating their parameters.  Xie et al. () provide a theoretical guarantee for ICL by showing its equivalence to implicit Bayesian inference, while Jeon et al. () study ICL in the Bayesian setup by adopting a point of view that relates it to meta-learning from non-independent and identically distributed (i.i.d.) data. Their guarantees introduce a desirable dependence on the length of the input sequence and the number of sequences seen, yet their data generative process assumes that each sequence is outputted by a transformer model drawn from a prior distribution. A follow-up work by Wies et al. () generalizes this analysis within a broader Probably Approximately Correct (PAC) framework and sheds light on the few-shot nature of ICL. Li et al. () studied the generalization error of trained ICL transformers from a stability viewpoint and provided generalization guarantees for temporally dependent prompts that can be seen as Markov chains of different orders. The closest work on ICL to our analysis is (Zhang et al., ) upon which we improve by relaxing many assumptions and, most importantly, by providing stronger interpretations and experimental observations.

##### Generalization bounds for LLMs.

Deriving generalization bounds for neural networks is inherently difficult due to the complexity of the operations performed by the model. This can require expressing it as a continuous process (Marion, ). For LLMs, an avenue to obtain such bounds is to rely on the PAC-Bayes framework. Lotfi et al. (; ) leverage compression techniques in combination with PAC-Bayes type bounds to obtain tight generalization bounds both at the document and token level. These works are connected to the existing literature on compressibility and the intrinsic dimension of neural networks (Aghajanyan et al., ; Yaras et al., ) and typically focus on fine-tuning LLMs with LoRA (Hu et al., ) inspired adapters. The work of Zhang et al. () considers the Bayesian framework to derive generalization bounds for pre-training where the data is assumed to be a Markov chain. Our theoretical analysis of pre-training is done *without* relying on Bayesian modeling and under realistic data generating assumption covering many common types of data used to train LLMs.

##### Summary of our contributions.

Our main contributions are summarized as follows.

- 1)
We provide an explicit characterization of LLM’s inference mechanism by showing its equivalence to a finite-state Markov chain. We analyze the transition matrix of the latter and prove the existence and uniqueness of its stationary distribution. We give a rate of convergence to this distribution that depends on the vocabulary and context window sizes, and the model’s temperature.
- 2)
By leveraging concentration inequalities for *dependent* random variables, we obtain generalization bounds for LLMs in both pretraining and in-context inference. Our bounds are proved under minimal assumptions on the model and data and depend on the model’s depth, dictionary, and dataset sizes, as well as the intrinsic properties of the temporally-dependent sequences it was trained on. We highlight the insights that stem from these bounds by relating them to the minimax bounds of Markov chain learning.
- 3)
We experimentally show that the most recent LLMs dating from 2023-2024 obey the in-context scaling laws predicted by our theoretical results. One highlight is that LLMs are better Markov chains learners than the minimax optimal frequentist approach (Wolfer & Kontorovich, ).

##### Organization of the paper.

Section 2 provides background material on autoregressive models and Markov chains. We formalize an equivalence between these two models in Section 3 and illustrate it on a toy example. In Section 4, we derive generalization bounds for LLMs trained on *non-iid* data and prompted on Markov chains. Our results are empirically verified in Section 5.

## 2 Background Knowledge

We recall some elementary facts about Markov chains (Roberts & Rosenthal, ; Paulin, ) and LLMs. More notations and background materials are available in Appendices A, B and C.

##### Markov chains.

Let $\Omega$ be a discrete finite set of size $\lvert\Omega\rvert$. A discrete-time, time-homogeneous Markov chain $\text{MC}(\Omega,\mathbf{Q})$ defined on a state space $\Omega=\{x_{i}\}_{i=1}^{\lvert\Omega\rvert}$ with transition matrix $\smash{\mathbf{Q}\in\mathbb{R}^{\lvert\Omega\rvert\times\lvert\Omega\rvert}}$ with entries $\mathbf{Q}_{ij}=\mathbf{Q}\left(x_{i},x_{j}\right)\in[0,1]$ is a sequence of random variables $\left(\mathbf{X}_{1},\mathbf{X}_{2},\ldots\right)$ taking values in $\Omega$ such that for any $n\in\mathbb{N}$ and $(x_{1},\ldots,x_{n+1})\in\Omega^{n+1}$, we have

$$ $\mathbb{P}\left(\mathbf{X}_{n+1}=x_{n+1}\mid\mathbf{X}_{n}=x_{n},\ldots, \mathbf{X}_{1}=x_{1}\right)=\mathbb{P}\left(\mathbf{X}_{n+1}=x_{n+1}\mid \mathbf{X}_{n}=x_{n}\right)=:\mathbf{Q}(x_{n},x_{n+1}).$ $$

A distribution $\pi$ on $\Omega$ is said to be a stationary distribution if $\mathbf{Q}\pi=\pi$. Under mild conditions on $\mathbf{Q}$, $\text{MC}(\Omega,\mathbf{Q})$ has a unique stationary distribution to which it converges, i.e., for any $x\in\Omega$, $\lim_{n\to\infty}d_{\mathrm{TV}}\left(\mathbf{Q}^{n}\left(x,\cdot\right),\pi
\right)=0$, where $\mathbf{Q}^{n}\left(x,\cdot\right)$ denotes the probability of $\mathbf{X}_{n}$ conditioned on $\mathbf{X}_{1}=x$ and the total variation between two distributions $\mathbb{P}$ and $\mathbb{Q}$, defined on $\left(\Omega,\mathcal{F}\right)$, is

$$ $d_{\mathrm{TV}}\left(\mathbb{P},\mathbb{Q}\right)\coloneqq\sup_{A\in\mathcal{F }}\lvert\mathbb{P}\left(A\right)-\mathbb{Q}\left(A\right)\rvert.$ $$

We recall that the mixing time $t_{\textnormal{mix}}(\varepsilon)$ of a Markov chain is the minimal time needed to be $\varepsilon$-close to its stationary distribution (see Section C.1). Intuitively, a Markov chain mixes slowly when it remains close to the initial state after a given number of steps and doesn’t explore its state space. A Markov chain that exhibits a fast mixing time on the contrary quickly forgets its initial state and transitions more easily to a wider set of states.

##### Autoregressive models.

Let $\mathcal{V}$ denote a dictionary of size $T$ used to encode an arbitrary sequence into a sequence of predefined tokens belonging to $\mathcal{V}$. We assume that our model admits a maximum of $K$ tokens as input, referred to as the *context window* of the model. The domain of the autoregressive model is the set of all sequences consisting of elements from $\mathcal{V}$ with up to $K$ elements. We denote this by $\mathcal{V}_{K}^{*}$, which represents a restriction of Kleene closure of $\mathcal{V}$, i.e., $\smash{\mathcal{V}_{K}^{*}:=\{v\in\mathcal{V}^{*},\,\lvert v\rvert\leq K\}}$ with $\lvert v\rvert$ the length of $v$. We define an autoregressive model with trainable parameters $\bm{\Theta}$ as a function $\smash{f_{\bm{\Theta}}^{T,K}:\mathcal{V}_{K}^{*}\rightarrow\Delta(\mathcal{V})}$, where $\Delta(\mathcal{V})$ is the probability simplex over $\mathcal{V}$, that given a sequence of tokens $v$ outputs a probability distribution over the whole state space indicating the likelihood for each of its elements to appear after $v$ (see Appendix B for more details). We consider a setting where the learner’s objective is to approximate the probabilities of sequences over an input vocabulary given by some reference distribution $\mathbb{P}_{\mathcal{L}}:\mathcal{P}(\mathcal{V}_{K}^{*})\rightarrow[0,1]$(^2^22$\mathcal{P}(\mathcal{V}_{K}^{*})$ denotes the powerset of $\mathcal{V}_{K}^{*}$.). We underline that we do not specify the exact internal structure of $\smash{f_{\bm{\Theta}}^{T,K}}$, i.e., it can rely on any neural network that uses a softmax final layer. We use the terms “autoregressive model” and “LLMs” interchangeably, and we write $f_{\bm{\Theta}}$, dropping the superscripts $T,K$ when they are of no importance.

## 3 Autoregressive models as Markov chains

We formally define a Markov chain that explicitly captures the full inference capacity of a given autoregressive model $f_{\bm{\Theta}}$. We build upon a high-level idea that associates a tokenized input prompt with a state $v_{i}$, from which we transition to a new state $v_{j}=[v_{i},v]$ by concatenating the token $v$ predicted by an LLM to it. We then provide a theoretical characterization of this Markov chain highlighting its intriguing properties and asymptotic behavior.

### 3.1 Markov chain formalization

We begin by defining the transition matrix associated with an autoregressive model $\smash{f_{\bm{\Theta}}^{T,K}}$.
{boxprop}
Any autoregressive model $f_{\bm{\Theta}}^{T,K}$ can be equivalently represented by a Markov chain $\text{MC}(\mathcal{V}_{K}^{*},\mathbf{Q}_{f})$, with a sparse transition matrix $\mathbf{Q}_{f}\in\mathbb{R}^{|\mathcal{V}_{K}^{*}|\times|\mathcal{V}_{K}^{*}|}$ defined as:

$$ $\forall v_{i},v_{j}\in\mathcal{V}_{K}^{*},\ \mathbf{Q}_{f}(v_{i},v_{j})=\begin {cases}0,&\text{if }\exists l\in\{1,\ldots,|v_{i}|\},\text{s.t. }(v_{i})_{l+1} \neq(v_{j})_{l},\\ \{f_{\bm{\Theta}}^{T,K}(v_{i})\}_{j},&\text{otherwise}.\\ \end{cases}$ $$

The proportion of non-zero elements in $\mathbf{Q}_{f}$ is $(T-1)/(T^{K}-1)$.

Figure: Figure 2: Illustration of Section 3.1 with $T=2$ and $K=3$.
Refer to caption: x2.png

We discuss the intuition behind the definition of $\mathbf{Q}_{f}$ provided above and illustrate it in Figure 2 for a case of $T=2$ and $K=3$. For this, we first note that given an input sequence $v_{i}$ of size $\lvert v_{i}\rvert<K$, a transition to any state $v_{j}$ has a probability of 0 if $v_{j}\neq[v_{i},v]$ for some $v\in\mathcal{V}$, i.e., if the state we transition to is not a concatenation of the input sequence with an additional token from the vocabulary (for instance, a state $\{0\}$ cannot transition to $\{1,0\}$ in one step). Applying this reasoning for different values of $k<K$ defines green rectangular blocks of size $T^{k}\times T^{k+1}$ in the transition matrix portrayed in Figure 2. When one reaches the blue square block in the transition matrix, the input sequence reaches the maximum context window length $v_{i}$: the model can no longer append tokens to the input sequence and has to delete the first token from it to proceed. This blue block is of size $T^{K}\times T^{K}$: it captures transitions between all possible sequences of the maximum admissible length. We define similarly the reference transition matrix $\mathbf{Q}^{*}$ of the language where the probability of transitions $\smash{\{f_{\bm{\Theta}}^{T,K}(v_{i})\}_{j}}$ are replaced by ground-truth probabilities $\mathbb{P}_{\mathcal{L}}\left(v_{j}\mid v_{i}\right)$. In order to use $\mathbf{Q}_{f}$ as $f_{\bm{\Theta}}$, it is now sufficient to define an input distribution $\delta_{0}$ of the Markov chain based on input prompt $v$ as a one-hot encoding vector of size $|\mathcal{V}_{K}^{*}|$ with 1 at the position of the state corresponding to $v$. Then, the transition to the next state simply writes as $\delta_{1}=\mathbf{Q}_{f}\delta_{0}$. The output of $f_{\bm{\Theta}}(v)$ for individual tokens in $\mathcal{V}$ would then correspond exactly to the probabilities in $\delta_{1}$ for states that are concatenations of $v$ with $T$ tokens from $\mathcal{V}$. This process is illustrated in Figure 2.

We now characterize this Markov chain and note that, since $\mathcal{V}_{K}^{*}$ is finite, $\text{MC}(\mathcal{V}_{K}^{*},\mathbf{Q}_{f})$ admits a stationary distribution. This stationary distribution is unique given the structure of the transition matrix $\mathbf{Q}_{f}$, as established in the following result.
{boxprop}
Let $\text{MC}(\mathcal{V}_{K}^{*},\mathbf{Q}_{f})$ be a Markov chain defined in Section 3.1. Then $\text{MC}(\mathcal{V}_{K}^{*},\mathbf{Q}_{f})$ is an ergodic unichain and has a unique stationary distribution.
A unichain is a chain that has at most one recurrent class plus some additional transient states. From Section 3.1, we note immediately that green blocks in Fig. 1 represent transient classes, meaning that applying $\mathbf{Q}_{f}$ to the input prompt, represented by a one-hot encoding of size $|\mathcal{V}_{K}^{*}|$, will transition to a state that corresponds to a sequence of length increased by one with an additional, most likely, token appended to it. This process is repeated if the model is called further on: we append tokens until we reach the context window limit $K$. At this point, we reach the recurrent class, represented in blue, in which the chain stays until it reaches its unique stationary distribution. We now characterize how many times one should apply $\mathbf{Q}_{f}$ to the input to reach the stationary distribution.
{boxprop}
Given an ergodic finite-state unichain $\text{MC}(\mathcal{V}_{K}^{*},\mathbf{Q}_{f})$ and $e=(1,1,\ldots,1)^{\top}$, then $\lim_{n\to\infty}\mathbf{Q}_{f}^{n}=e\bm{\pi}$ where $\bm{\pi}$ is the stationary distribution of the recurrent class $\mathscr{R}$ of states, expanded by 0 0’s for each transient state of the unichain. Moreover, for all $n\geq K,$

$$ $\displaystyle\lvert(\mathbf{Q}_{f}^{n})_{i,j}-(e\bm{\pi})_{i,j}\rvert\leq(1-2 \varepsilon)^{\lfloor\frac{n}{K}\rfloor-1},$ $$

where $\varepsilon=\underset{i,j\in\mathscr{R}^{2}}{\min}\{(\mathbf{Q}_{f}^{K})_{i,j}
\}>0$.
The stationary distribution is the long-term equilibrium of the Markov chain defined by the LLM and can be interpreted as a proxy of its understanding of natural language in its token space. It is independent of the initial state (i.e., input prompt) but rather captures the absolute frequencies of occurrences of certain tokens seen during pre-training. For a well-performing model, it is hence likely to be heavy-tailed, meaning that rare states have a non-zero probability of occurring due to language’s ambiguity and complexity. Section 3.1 shows that reaching the stationary distribution requires more generation steps for models with larger context window $K$. Additionally, convergence depends on $\varepsilon$ (that is, the smallest element of the $K$^th power of the transition matrix), which is related to the ability of the chain to explore the state space after having forgotten the input prompt.

Figure: Figure 3: Markov chain with a small GPT-like model. (a) Transition matrix $\mathbf{Q}_{f}$ of the model where ${\color[rgb]{1,0,0}\definecolor[named]{pgfstrokecolor}{rgb}{1,0,0}\square}$ denotes the examples from the training set. (b) Stationary distribution of the trained model assigning almost uniform probabilities to the states seen during training. (c) Convergence rate to the stationary distribution for the considered toy model along with three LLMs, highlighting the dependence on $K$. The y-axis is the upper bound in Section 3.1.

### 3.2 Illustration on a toy model

We illustrate the results of Section 3 on a toy model trained on a sequence of 0 0s and $1$s. Here, each subsequent token is 0 0 if the sum of three previous tokens is even and 0 0 otherwise. Therefore, $T=2$ and $k=3$. We generate a sequence of $40$ digits, resulting in $37$ distinct supervised examples, and train a small “GPT-like” model (Karpathy, ) on it. We extract the logits from the model by prompting it with all possible combinations of 0 0s and $1$s of length less than three to obtain the transition matrix $\mathbf{Q}_{f}\in\mathbb{R}^{14\times 14}$ depicted in Fig. 3(a). The transition matrix’s structure (e.g., presence of transient and recurrent classes) matches the one presented in Fig. 1. Fig. 3(b) displays the stationary distribution of the trained model obtained by raising $\mathbf{Q}_{f}$ to power $10^{5}$. We note that it has a strong bias toward seen training samples in accordance with our intuition behind the stationary distribution presented earlier. Finally, Fig. 3(c) illustrates the convergence rate of the toy model, predicted by Section 3.1, and compares it to models with larger dictionary size $T$ and context window $K$. In Fig. 3(d), we set $\varepsilon=10^{-6}$ and note that this parameter reflects the ability of the LLM to explore the state space.

Figure: Figure 4: Dependence of $\varepsilon$ on the temperature of the model. (a) For low temperatures, $\varepsilon$ becomes too small to achieve convergence to the stationary distribution. (b)-(c) Increasing the temperature from $1$ to $2$ leads to a $\times 10$ faster convergence. (d) $\varepsilon$ (log-scale) increase for temperature values in $[0.1,2]$.

##### Role of the temperature.

To better illustrate the role of $\varepsilon$, we now plot the transition matrix of the studied Markov chain obtained when applying different temperature scaling to the logits returned by the trained model. As the temperature is commonly linked to the ability of LLMs to transition more freely to a large set of states (Chen & Ding, ), we expect that lower temperatures should impact negatively the speed of the convergence to the stationary distribution. In Fig. 4(a), we show that for a low temperature ($0.2$), the Markov chain mixes slowly and is unable to reach its stationary distribution (same line in the transition matrix as in Fig. 3(c)) even after $10^{6}$ steps. In the case of a more commonly used temperature equal to $1$ (Fig. 4(b)), the model requires only $300$ steps to converge. Finally, setting the model’s temperature to $2$ (Fig. 4(c)) makes the convergence extremely fast, reaching the stationary distribution after only $30$ steps. The interplay between $\varepsilon$ and the model’s temperature is displayed in Fig. 4(d), increasing the temperature leads to a drastic improvement in the convergence speed.

## 4 Generalization Bounds for Large Language Models

The inference of any autoregressive language model $f_{\bm{\Theta}}$ can be fully captured by a Markov chain with a finite transition kernel $\mathbf{Q}_{f}$ defined as above. This, in turn, allows us to see and study the generalization of $f_{\bm{\Theta}}$ as its capacity to infer correctly all the elements of $\mathbf{Q}_{f}$ that approximate a true reference matrix of transition probabilities $\mathbf{Q}^{*}$. The hardness of this task lies in achieving precise inference having observed a negligible amount of $\mathbf{Q}^{*}$’s elements during its pre-training. For GPT-3 (Brown et al., ), this represents $5\times 10^{11}$ training tokens, which pales in comparison with the number of non-zero elements in $\mathbf{Q}_{f}$, given by $T^{K+1}\approx 10^{9632}$.

##### Risk definition.

We denote by $X=\left(\mathbf{X}_{1},\ldots,\mathbf{X}_{N}\right)$ the tokens in $\mathcal{V}$ that $f_{\bm{\Theta}}$ observes (e.g., during pre-training or at inference time).
The training sequences of tokens can be written as $\mathbf{S}_{n}=\left(\mathbf{X}_{1},\ldots,\mathbf{X}_{n}\right)$ if $n\leq K$ and $\mathbf{S}_{n}=\left(\mathbf{X}_{n-K+1},\ldots,\mathbf{X}_{n}\right)$ otherwise due to the deletion process (see Section B.1). In particular, the $\mathbf{S}_{n}$ are elements of $\mathcal{V}^{*}_{K}$. For any $n\in[N]$, the true probability of next token $\mathbf{X}_{n+1}$ given a past sequence $\mathbf{S}_{n}$ is defined as $\mathbb{P}_{\mathcal{L}}\left(\cdot\mid\mathbf{S}_{n}\right)\in\Delta_{T}$ and the probability estimated by the model writes $\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}_{n}\right)$. We assume the existence of a constant $c_{0}>0$ such that for any $n\in[N]$ and $(x_{1},\ldots,x_{n+1})\in\Omega^{n+1}$,

$$ $\mathbb{P}_{\mathcal{L}}\left(\mathbf{X}_{n+1}=x_{n+1}\mid\mathbf{X}_{n}=x_{n} ,\ldots,\mathbf{X}_{1}=x_{1}\right)\geq c_{0}>0.$ (1) $$

This is a common assumption used previously in (Zhang et al., ; Hu et al., ; Xie et al., ; Wies et al., ). To assess the generalization of a given model, we respectively define the theoretical and empirical risks for any $\bm{\Theta}\in\mathcal{W}$ as(^3^33Formally, $\mathcal{R}\left(\bm{\Theta}\right)=\mathbb{E}_{\mathbf{S}\sim\mathbb{P}_{ \mathcal{L}}}\left[d_{\mathrm{TV}}\left(\mathbb{P}_{\mathcal{L}}\left(\cdot \mid\mathbf{S}\right),\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}\right) \right)\right]=\mathbb{E}_{\mathbf{S}\sim\mathbb{P}_{\mathcal{L}}}\left[d_{ \mathrm{TV}}\left(\mathbf{Q}^{*}\left(\mathbf{S},\cdot\right),\mathbf{Q}_{f} \left(\mathbf{S},\cdot\right)\right)\right]$.)

$$ $\mathcal{R}\left(\bm{\Theta}\right)\coloneqq\mathbb{E}[\widehat{\mathcal{R}}( \bm{\Theta})],\quad\widehat{\mathcal{R}}(\bm{\Theta})\coloneqq\frac{1}{N}\sum_ {n=1}^{N}d_{\mathrm{TV}}\left(\mathbb{P}_{\mathcal{L}}\left(\cdot\mid\mathbf{S }_{n}\right),\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}_{n}\right) \right),$ (2) $$

The generalization problem consists of bounding the difference $\smash{\mathcal{R}\left(\bm{\Theta}\right)-\widehat{\mathcal{R}}(\bm{\Theta})}$.

###### Remark 4.1 (Choice of risk) .

Our risk definition departs from usual generalization bounds in statistical learning where risks are mostly derived from empirical risk minimization (Redko et al., ; Vapnik, ; Bach, ; Marion, ). As we want to assess how well the model estimates the probability *distribution* of the next token, we rather follow (Zhang et al., ; Hu et al., ) and the learning and identity testing of Markov chains literature (Wolfer & Kontorovich, ; ) and use the total variation distance.

###### Remark 4.1 (Choice of risk) .

##### Transformer model.

Without loss of generality, $f_{\bm{\Theta}}$ is assumed to be a transformer model with $L$ layers and $H$ heads, consisting of alternating multi-head attention (MHA) and feed-forward blocks (more details in  Appendix B). The first layer receives an input $\smash{\mathbf{S}^{(0)}=\mathbf{S}}$ embedded in $r$-dimensional space.
To obtain a probability distribution on the vocabulary $\mathcal{V}$, the output $\mathbf{S}^{(L)}\in\mathbb{R}^{r\times T}$ of the final layer is projected back to the vocabulary size by an \sayunembedding layer $\mathbf{W}_{U}\in\mathbb{R}^{T\times r}$ and averaged over the columns to obtain a vector in $\mathbb{R}^{T}$. A softmax layer is finally applied to obtain the probability distribution of the next token $\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}\right)\coloneqq\mathbb{P}_{
\bm{\Theta}}\left(\cdot\mid\mathbf{S}\right)=\mathrm{softmax}\left(\frac{1}{n
\tau}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_{n}\right)\in\Delta_{T}$, where $\bm{\Theta}$ denotes the parameters of the entire network and $\tau$ is the softmax temperature (Hinton, ). Unless otherwise specified, we assume that the unembedding layer is bounded. The classes of parameters and neural networks it generates respectively write $\mathcal{W}=\{\bm{\Theta}\text{ s.t. }\lVert\mathbf{W}_{U}^{\top}\rVert_{2,1}
\leq B_{U}\}$ and $\mathcal{F}=\{f_{\bm{\Theta}}\text{ s.t. }\bm{\Theta}\in\mathcal{W}\}$.

### 4.1 Pre-training Theoretical Analysis

We now significantly extend the scope of our theoretical contributions by assuming that the pre-training data $S=\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N_{\mathrm{train}}}\right)$ is a sequence of *dependent* random variables with a mild coupling structure, namely that a Marton coupling with mixing matrix $\bm{\Gamma}$ exists for $S=\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N_{\mathrm{train}}}\right)$.(^4^44$\lVert\bm{\Gamma}\rVert=1$ for independent variables and more details on Marton coupling can be found in Section C.3.) This ensures our setting remains very broad as it subsumes the case of independent variables, $m$-dependent variables, language bigrams (Bietti et al., ), and the Markov chain setting considered in state-of-the-art ICL analysis of autoregressive models (Zhang et al., ; Hu et al., ).

##### Generalization bound.

We denote the risks by $\mathcal{R}_{\mathrm{pre}}\left(\bm{\Theta}\right)$ and $\widehat{\mathcal{R}}_{\mathrm{pre}}\left(\bm{\Theta}\right)$ to indicate that we take $N=N_{\mathrm{train}}$ in Eq. 2. Below, we state our main result, whose proof is deferred to Section D.4, which provides a generalization bound on the estimation risk of pre-training.
{boxthm}[Pre-training generalization bound]
Consider an LLM $f_{\bm{\Theta}}\in\mathcal{F}$. We denote by $\bm{\Gamma}$ the mixing matrix of the pre-training sequences of tokens $\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N_{\mathrm{train}}}\right)$. Let $0<\delta<1$, then with probability at least $1-\delta$,

$$ $\mathcal{R}_{\mathrm{pre}}\left(\bm{\Theta}\right)\leq\widehat{\mathcal{R}}_{ \mathrm{pre}}\left(\bm{\Theta}\right)+\frac{\bar{B}}{\sqrt{N_{\mathrm{train}}} }\sqrt{\log{\left(\frac{2}{\delta}\right)}},$ $$

where $\bar{B}=2\lVert\bm{\Gamma}\rVert\max\{\log{(T)}+2B_{U}/\tau,\log{(1/c_{0})}\}^
{1/2}$ is a constant depending on the parameters of the problem.
The bound in Section 4.1 depends on the intrinsic structure of the pre-training data through the norm of the mixing matrix $\lVert\bm{\Gamma}\rVert$. If the pre-training data $S$ is a Markov chain with state space $\Omega$, this norm captures exactly the mixing time of the latter, making sequences that mix at a slower pace harder to learn.
Secondly, and perhaps most surprisingly, this bound becomes model-independent when $\max\{\log{(T)}+2B_{U}/\tau,\log{\left(1/c_{0}\right)}\}$ is dominated by $\log{\left(1/c_{0}\right)}$ term. Hence, if $B_{U}\approx\mathcal{O}(T\sqrt{r})$, which happens in practice due to the common normalization of the unembedding layer, then the model’s hidden dimension $r$ and vocabulary size $T$ should be large enough to ensure $\log(T)+2B_{U}/\tau\geq\log(1/c_{0})$ for some unknown reference constant $c_{0}$. Below this threshold, the architecture of $f_{\bm{\Theta}}$ is not expressive enough to have any tangible impact on its generalization, although it may affect the training error $\smash{\widehat{\mathcal{R}}_{\mathrm{pre}}\left(\bm{\Theta}\right)}$.

##### Depth-dependent variation.

We extend Section 4.1 to make its dependency on $f_{\bm{\Theta}}$ more fine-grained. Rather than assuming that only the norm of the embedding layer’s matrix is bounded, we follow the setting of prior work (Zhang et al., ; Furuya et al., ; Marion, ; Edelman et al., ) and consider the parameter space defined as follows:

$$ $\widetilde{\mathcal{W}}=\{\bm{\Theta}\in\mathcal{W}\mid\forall\ell\in[L], \lVert\mathbf{W}_{V}^{(\ell)}\rVert_{\infty}\leq B_{V},\lVert\mathbf{W}_{O}^{( \ell)}\rVert_{\infty}\leq B_{O},\lVert\mathbf{W}_{1}^{(\ell)}\rVert_{\infty} \leq B_{1},\lVert\mathbf{W}_{2}^{(\ell)}\rVert_{\infty}\leq B_{2}\}.$ $$

The definition of $\widetilde{\mathcal{W}}$ concerns the query, key, and value matrices of all layers and heads. Similarly to Zhang et al. (, Assumption 5.1), we assume that each token has an $\ell_{1}$-norm bounded by $B_{\mathrm{tok}}$.

We have the following generalization bound, whose proof is deferred to Section D.5.
{boxcor}[Depth-dependent bound]
Consider an LLM $f_{\bm{\Theta}}\in\tilde{\mathcal{F}}:=\{f_{\bm{\Theta}}\mid\bm{\Theta}\in
\tilde{\mathcal{W}}\}$. With the same assumptions as in Section 4.1, we have

$$ $\mathcal{R}_{\mathrm{pre}}\left(\bm{\Theta}\right)\leq\widehat{\mathcal{R}}_{ \mathrm{pre}}\left(\bm{\Theta}\right)+\frac{\bar{B}}{\sqrt{N_{\mathrm{train}}} }\sqrt{\log{\left(\frac{2}{\delta}\right)}},$ $$

where $\bar{B}=2\lVert\bm{\Gamma}\rVert\max\{\log{(T)}+2(B_{\bm{\Theta}})^{L}/\tau,
\log{(1/c_{0})}\}^{1/2}$ is a constant depending on the parameters of the problem, and $B_{\bm{\Theta}}=[(1+rmB_{1}B_{2})(1+\frac{r^{3}}{H}B_{O}B_{V})](B_{\mathrm{tok
}}B_{U})^{1/L}$.
We note that $\bar{B}$ exhibits an exponential dependence on the depth of the transformer, which also amplifies the hidden dimensionality (width) of the embedding layer $r$. This contrasts with the dependency in $m$, the hidden dimensionality of the MLP block, which is linear. All these factors are commonly associated with higher expressive power of transformers suggesting that they should contribute to a better minimization of $\smash{\widehat{\mathcal{R}}_{\mathrm{pre}}\left(\bm{\Theta}\right)}$ at the expense of requiring more training data. The number of heads $H$ can be used as a counterbalance to increasing the width in the cubic term $r^{3}$, suggesting that a good balance between these parameters may lead to more data-efficient models.

##### Sample complexity of LLMs.

Our goal is to show the asymptotic dependence on the number of sequences that an LLM requires such that $\mathbf{Q}_{f}$ is $\varepsilon$-close to the reference transition matrix $\mathbf{Q}^{*}$.
We then derive a sample complexity bound. The proof is deferred to Section D.6.
{boxcor}[Sample complexity]
Let $\bar{B}$ be the parameter-dependent constant of Section 4.1 or Section 4.1. Let $\delta\in[0,1]$ and let $\epsilon>0$. If $N_{\mathrm{train}}\geq N^{*}\coloneqq\lceil\frac{4\bar{B}^{2}}{\epsilon^{2}}
\log{\left(\frac{2}{\delta}\right)}\rceil$ and if we assume a perfect pre-training error for $f_{\bm{\Theta}}$, then we have with probability at least $1-\delta$,

$$ $\mathbb{E}_{\mathbf{S}\sim\mathbb{P}_{\mathcal{L}}}\lVert\mathbf{Q}^{*}\left( \mathbf{S},\cdot\right)-\mathbf{Q}_{f}\left(\mathbf{S},\cdot\right)\rVert_{1} \leq\epsilon.$ $$

This result allows us to contextualize LLMs’ ability to learn Markov chains with respect to the existing literature. To the best of our knowledge, the only existing approach with theoretical guarantees for learning Markov chains is the frequentist method: counting the number of occurrences of different states to fill in the matrix $\mathbf{Q}_{f}$. Wolfer & Kontorovich () show that the sample complexity of approximating $\mathbf{Q}^{*}$ up to $\epsilon$ with such approach requires at most $\mathcal{O}(\max\{|\mathcal{V}_{K}^{*}|/\epsilon^{2}\gamma_{s},1/\gamma_{s}\pi
^{*}\})$ samples, where $\gamma_{s}$ is a (pseudo) spectral gap of the Markov chain and $\pi^{*}$ is the smallest element of its stationary distribution. The authors state that the frequentist approach is minimax optimal (up to logarithmic factors). Our bound has a dependence that behaves as $\smash{\bar{B}^{2}=\mathcal{O}(\max\{\log{T}+\frac{2T\sqrt{r}}{\tau},\log{
\left(1/{c_{0}}\right)}\})}$. Given that in practice $T>r$, it then simplifies to $\mathcal{O}(\max\{T/\epsilon^{2}\tau,1/\epsilon^{2}\})$. Note that the LLMs’ sample complexity is linear in the vocabulary size $T$, which is remarkable compared to the sample complexity of the frequentist approach, which scales as $\mathcal{O}(T^{K})$. We show in Section 5 that this is confirmed experimentally: LLM’s ability to learn Markov chains exceeds the frequentist approach for Markov chains with a large state space.

### 4.2 In-context Learning of Markov Chains

Although insightful, the analysis presented above is related to the pre-training of LLMs – a process that is hard and extremely costly to reproduce in practice. Similarly, we do not have access to the ground-truth matrix $\mathbf{Q}^{*}$ to reason about LLM’s ability to infer it in practice. To provide theoretical results that can be confirmed experimentally, we now turn our attention to in-context learning of Markov chains: a setup where one provides an LLM with an input sequence formed by a Markov chain of size $N_{\mathrm{icl}}$ defined over a state space $\Omega$ of size $d$(^5^55This is different from another variation of ICL where supervised ($x$,$y$) pairs are provided in-context. Rather, the supervision is provided from observing transitions between states ($x_{i}$, $x_{i+1}=f(x_{i})$) as discussed in (Li et al., , Fig.1).). Different from the setting of Section 4.1, we now can explicitly use a transition kernel $\mathbb{P}$ of this Markov chain for the theoretical analysis by replacing $\mathbb{P}_{\mathcal{L}}$ with it in the definition of $\mathcal{R}_{\mathrm{icl}}\left(\bm{\Theta}\right)$ and $\widehat{\mathcal{R}}_{\mathrm{icl}}\left(\bm{\Theta}\right)$ in Eq. 2 (see Section D.7 for details on the problem setup). To relate the generalization error to the pre-training error, we quantify the discrepancy between an LLM pre-trained mostly on textual data, and a hypothetical LLM with parameters in $\mathcal{W}_{\mathrm{mc}}$ that is pre-trained on a dataset of Markov chains with the same data distribution as the Markov chain used as an input during in-context inference. We define the divergence between two estimated transition matrices $\mathbb{P}_{\bm{\Theta}_{1}},\mathbb{P}_{\bm{\Theta}_{2}}$ as

$$ $\mathcal{K}(\bm{\Theta}_{1},\bm{\Theta}_{2})\coloneqq\frac{1}{N}\sum_{n=1}^{N} \mathbb{E}_{\mathbf{S}_{n}}\left[d_{\mathrm{TV}}\left(\mathbb{P}_{\bm{\Theta}_ {1}}\left(\cdot\mid\mathbf{S}_{n}\right),\mathbb{P}_{\bm{\Theta}_{2}}\left( \cdot\mid\mathbf{S}_{n}\right)\right)\right].$ (3) $$

The operator $\mathcal{K}$ is akin to a distance (the separation property is only verified almost surely, see Section C.4 for more details). The next result, whose proof is deferred to Section D.7, provides a generalization bound on the in-context learning phase.
{boxthm}[In-Context Learning generalization bound]
Consider an LLM $f_{\bm{\Theta}}\in\mathcal{F}$. We provide as input of $f_{\bm{\Theta}}$ a $d-$state Markov chain $X=\left(\mathbf{X}_{1},\ldots,\mathbf{X}_{N_{\mathrm{icl}}}\right)$. The sequence of subsequences of the first $n$ terms is denoted by $S=\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N_{\mathrm{icl}}}\right)$. $S$ is also a Markov chain, and we denote by $t_{\mathrm{mix}}(\varepsilon)$ its mixing time. Let $\smash{t_{\mathrm{min}}\coloneqq\inf_{0\leq\varepsilon<1}t_{\mathrm{mix}}\left
(\frac{\varepsilon}{2}\right)(\frac{2-\varepsilon}{1-\varepsilon})^{2}}$. Let $\delta>0$. Then, with probability at least $1-\delta$,

$$ $\mathcal{R}_{\mathrm{icl}}\left(\bm{\Theta}\right)\leq\inf_{\bm{\vartheta}\in \mathcal{W}_{\mathrm{mc}}}\{\widehat{\mathcal{R}}_{\mathrm{icl}}\left(\bm{ \vartheta}\right)+\mathcal{K}(\bm{\vartheta},\bm{\Theta})\}+\bar{B}\sqrt{\frac {t_{\mathrm{min}}}{N_{\mathrm{icl}}}}\sqrt{\log{\left(\frac{2}{\delta}\right)}},$ (4) $$

where $\bar{B}=2\max\{\log{(d)}+2B_{U}/\tau,\log{(1/p_{\mathrm{min}})}\}^{1/2}$.
We first note that instead of the norm of the mixing matrix $\bm{\Gamma}$ seen before, we now have an explicit dependency on $t_{\mathrm{min}}$, which is related to the mixing time of the input Markov chain. This, together with the availability of the ground-truth transition matrix, allows us to use Eq. 3 to derive and verify experimentally the scaling laws of ICL for popular LLMs. Eq. 3 also suggests that an LLM pre-trained on diverse data sequences different from Markov chains should exhibit a certain degree of invariance to correctly infer the transition probabilities of the latter. This is reminiscent of the domain adaptation bounds (Redko et al., ) that also commonly involve a distribution shift (i.e., a distance or a divergence) term that vanishes if the model is invariant to classes of transformations linking the distribution of the input data with that on which it is applied during inference. A recent success of applying LLMs to time series data (Gruver et al., ), for instance, suggests that this term is indeed small for certain types of data not used during pre-training.

## 5 Numerical Experiments

Eq. 3 provides a practically verifiable result which naturally stems from our analysis in Section 4. We then evaluate the ability of recent LLMs, namely Mistral 7Bv0.1 (Jiang et al., ), Llama2 7B & 13B (Touvron et al., ), and Gemma 2B (Team et al., ) to infer transition probabilities of Markov chains in-context. We associate each state in the $d$-state Markov chain with a token from the set $\{0,\ldots,d-1\}$, concatenated to obtain a prompt of length $N_{\mathrm{icl}}$. Bearing in mind the differences in the tokenization mechanisms of the different models, we add comas whenever necessary to ensure that each state is tokenized separately. More details on the experimental setup and additional experiments with more Markov chains and with Llama3.2 (Dubey et al., ) are available in Section E.1.

Figure: Figure 5: In-context scaling laws. We plot the risk $\mathcal{R}_{\mathrm{icl}}$ as functions of $N_{\mathrm{icl}}$, with $95\%$ confidence intervals. Left. Risks for different LLMs along with the scaling law of Eq. 3. Right. Risks in semi-log scale with Mistral 7B v0.1 for random $3$-state transition matrices and different $t_{\mathrm{min}}$.

##### Dependence on N icl subscript 𝑁 icl N_{\mathrm{icl}} italic_N start_POSTSUBSCRIPT roman_icl end_POSTSUBSCRIPT .

We first analyze the effect of $N_{\mathrm{icl}}$ on the risk calculated for a randomly generated $3$-state Markov transition matrix. From the results presented in Fig. 5(left), we note that Llama-2 models deviate from our $\smash{\mathcal{O}(N_{\mathrm{icl}}^{-1/2})}$ theoretical scaling law, while most recent models (Mistral and Gemma) stay much closer to Eq. 3, similarly to what was observed by Cabannes et al. (). Being randomly generated, the Markov chains provided to the models have not been seen during training, and older (weaker) models naturally struggle to generalize.

##### Dependence on t min subscript 𝑡 min t_{\mathrm{min}} italic_t start_POSTSUBSCRIPT roman_min end_POSTSUBSCRIPT .

Eq. 3 states that Markov chains with slow mixing (higher $t_{\mathrm{min}}$) are slower to learn. We now plot the true risk for a single model with different values of $t_{\mathrm{min}}$ highlighting in Fig. 5(right) a two-stage regime of ICL. In a first stage, the bound in Eq. 4 is dominated by $\smash{\sqrt{t_{\mathrm{min}}/N_{\mathrm{icl}}}}$ for small $N_{\mathrm{icl}}$, and depends strongly on $t_{\mathrm{min}}$, while the scaling law $\smash{\mathcal{O}(N_{\mathrm{icl}}^{-1/2})}$ dominates as $N_{\mathrm{icl}}$ increases beyond $N_{\mathrm{icl}}\approx 20$.

Figure: Figure 6: Impact of the number of states. We plot the risks $\mathcal{R}_{\mathrm{icl}}$ as functions of $N_{\mathrm{icl}}$ for Gemma 2B and the frequentist approach (Wolfer & Kontorovich, ) with $95\%$ confidence intervals. Left. The input sequence is a random $3$-state Markov chain. Right. The input sequence is a Brownian motion discretized as a $700$-state Markov chain, similarly to Liu et al. ().

##### Dependence on d 𝑑 d italic_d .

We now verify Eq. 3 for Markov chains with a different state space size (previously $d=3$). We also consider a baseline given by the frequentist method mentioned before. We recall that, for the latter, its dependence on $d$ behaves like $\smash{\mathcal{O}({\sqrt{d/N_{\mathrm{icl}}}})}$, while Eq. 3 gives $\smash{\mathcal{O}({\sqrt{\log(d)/N_{\mathrm{icl}}}})}$. For Markov chains with a small number of states $d$, there is no clear difference between the frequentist estimator and a LLM. However, as $d$ grows the frequentist estimator struggles to estimate the transition matrix due to the $\mathcal{O}(\sqrt{d})$ scaling factor. This is verified experimentally in Fig. 6, where we vary the parameter $d$ from $3$ (left) to $700$ (right). We observe that the LLM follows the theoretical neural scaling law $\smash{\mathcal{O}(N_{\mathrm{icl}}^{-1/2})}$ and outperforms the frequentist method for $d=700$, while being close to it for $d=3$. We conclude that our analysis gives theoretical insights on the ICL neural scaling law observed empirically in (Liu et al., ). The additional experiments conducted in Section E.5 show that our bounds remain valid for large values of $d$.

## 6 Conclusion

This paper proposed an explicit characterization of the inference mechanism in large language models through an equivalent finite-state Markov chain. We provided an insightful theoretical analysis based on the established characterization and the ability of the LLM to infer the transition kernel approximating the true transition probabilities of language. We adapted our results to in-context learning where experiments confirm our theoretical insights. In the future, we hope that the proposed equivalence will have far-reaching implications on our understanding of LLMs and allow for a more fine-grained understanding of their expressiveness.

#### Acknowledgments

The authors would like to thank Vasilii Feofanov, Giuseppe Paolo, Albert Thomas, Malik Tiomoko, Aladin Virmaux, and Alain Durmus for fruitful discussions. Nicolas Boullé was supported by the Office of Naval Research (ONR), under grant N00014-23-1-2729.

## Appendix A Notations

We denote $\{1,\cdots,N\}$ as $[N]$. We represent scalar values with regular letters (e.g., parameter $\lambda$), vectors with bold lowercase letters (e.g., vector $\mathbf{x}$), and matrices with bold capital letters (e.g., matrix $\mathbf{A}$). The $i$-th row of the matrix $\mathbf{A}$ is denoted by $\mathbf{A}_{i}$, its $j$-th
column is denoted by $\mathbf{A}_{\textperiodcentered,j}$ and its transpose is denoted by by $\mathbf{A}^{\top}$. The identity
matrix of size $n$ is denoted by $\mathbf{I}_{n}\in\mathbb{R}^{n\times n}$. The vector of size $n$ with each entry equal to $1$ is denoted by $\mathbbm{1}_{n}$. We denote by $\lVert\mathbf{A}\rVert_{p,q}$ the $L_{p,q}$ matrix norm where the $p$-norm is over columns and the $q$-norm is over rows. We denote by $\lVert\mathbf{A}\rVert$ the operator norm of $\mathbf{A}$ induced by the $\ell_{2}$ norm and by $\lVert\mathbf{A}\rVert_{\infty}=\max_{ij}\lvert\mathbf{A}_{ij}\rvert$ the operator norm induced by the $\ell_{\infty}$-norm. Similarly, $\mathbf{x}^{\top}$ is the transpose of the vector $\mathbf{x}$ and $\lVert\mathbf{x}\rVert_{p}$ is its $\ell_{p}$-norm. The total variation between two probability distributions $\mathbb{P},\mathbb{Q}$ is denoted by $d_{\mathrm{TV}}\left(\mathbb{P},\mathbb{Q}\right)$. The term \sayalmost surely is denoted by the notation \saya.s. while the term *random variable* is denoted by the notation \sayr.v.. $\Delta_{n}\coloneqq\{\mathbf{p}\in[0,1]^{n}|\sum_{i=1}^{n}\mathbf{p}_{i}=1\}$ is the probability simplex of $\mathbb{R}^{n}$.

## Appendix B Background on Autoregressive Models

We first recall important notions regarding autoregressive models before focusing on the most widely used ones, namely the transformer-based LLMs. We describe the components of the vanilla transformer architecture before describing the whole network at the heart of such a model and formally defining the class of parameters and neural networks considered in our work.

### B.1 Autoregressive Models

In this section, we recall how the sequences of tokens are processed by the autoregressive model notably regarding the next token generation and the deletion process.
{boxdef}[Generation process]
Given an input $s\in\mathcal{V}_{K}^{*}$ of size $p$, an autoregressive model outputs a probability mass function $f_{\bm{\Theta}}^{T,K}(s)$ over the discrete vocabulary space. A next token $x$ is then sampled from $f_{\bm{\Theta}}^{T,K}(s)$, to construct a new sequence $(s,x)$ of size $p+1$.

Generation can be repeated by considering $(s,x)$ as new input sequence and iterating this process. Since these models are designed to handle only sequences of size at most $K$, a deletion process is required.
{boxdef}[Deletion process]
Given an input $s$ of size $p>K$, an autoregressive model outputs a probability mass function $f_{\bm{\Theta}}^{T,K}(s_{K})$ where $s_{K}$ is a truncation of $K$ tokens of the sequence $s$. Autoregressive models implement front truncation, which is done by setting $s_{K}$ as the last $K$ tokens of $s$.

As shown in Fig. 7, only the last $K$ tokens of a long input sequence are used. This is why we speak of deletion, since we ignore the first tokens.

Figure: Figure 7: Deletion process, front truncation. An autoregressive model with context window $K=7$ in navy blue, processing sequences of different lengths. Top. A sequence of length $4$. Bottom. Front truncation of a sequence of length $10$.
Refer to caption: x3.png

Note that it is possible to implement other kinds of truncation, but autoregressive models usually do not (Brown et al., ; Touvron et al., ), however, in models like BERT (Devlin et al., ), which are not autoregressive, back truncation as described in Fig. 8 is also an option.

Figure: Figure 8: Back truncation. An autoregressive model with context window $K=7$ in navy blue, processing back truncation of a sequence of a sequence of length $10$.
Refer to caption: x5.png

### B.2 Transformer Architecture

The most popular autoregressive LLMs rely on the transformer architecture (Vaswani et al., ) which we describe below following (Brown et al., ; Edelman et al., ; Zhang et al., ). An autoregressive transformer-based LLM takes as input a sequence of length $n$, with $n\leq K$ and $K$ is the context window, tokens with values in a vocabulary $\mathcal{V}$ of size $T$. The tokens are embedded into a $r$-dimensional space and the input can be written as $\mathbf{S}\in\mathbb{R}^{r\times n}$. We consider a transformer model with $L$ layers and $h$ heads. The output of the $\ell$-th layer writes $\mathbf{S}^{(\ell)}$ and is fed as input of the $(\ell+1)$-th layer. The input of the whole model is $\mathbf{S}^{(0)}=\mathbf{S}$. Below, we describe the operations performed by the model, including the embeddings of the tokens.

- •
Token embeddings. The tokens are embedded in a $r$-dimensional space via an embedding layer $\mathbf{W}_{E}$ which results in an input of the form $\mathbf{S}^{r\times n}$;
- •
Positional embeddings. (Learnable) positional embeddings are added to each token depending on its position in the input sequence. This breaks the permutation-invariance of the transformer architecture and leads, by abuse of notation, to an output $\mathbf{S}\in\mathbb{R}^{r\times n}$;
- •
Multi-head attention (MHA). Given an input sequence $\mathbf{S}\in\mathbb{R}^{r\times n}$, query, key, and value matrices $\mathbf{W}_{Q},\mathbf{W}_{K},\mathbf{W}_{V}\in\mathbb{R}^{r\times r}$ (here the value and output matrices are merged for ease of notations), the self-attention module computes
$\mathcal{A}\left(\mathbf{S};\mathbf{W}_{Q},\mathbf{W}_{K},\mathbf{W}_{V}\right
)\coloneq\operatorname{\mathrm{softmax}}\left(\mathbf{W}_{Q}\mathbf{S}\left(
\mathbf{W}_{K}\mathbf{S}\right)^{\top}/\sqrt{r}\right)\left(\mathbf{W}_{V}
\mathbf{S}\right)\in\mathbb{R}^{r\times n},$
with $\mathrm{softmax}\colon\mathbf{x}\in\mathbb{R}^{n}\to\exp(\mathbf{x})/\sum_{i}
\exp(\mathbf{x})_{i}\in\Delta_{n}$. The operation described below corresponds to single-head self-attention. In practice, multi-head attention (MHA) is used with $H$ heads and the query and key matrices are in $\mathbb{R}^{\frac{r}{H}\times\frac{r}{H}}$ and the value matrix is in $\mathbb{R}^{\frac{r}{H}\times r}$ ($r,H$ are taken such that $\frac{r}{H}$ is an integer). The MHA module concatenates on the row dimension the outputs of $\mathcal{A}$ for each head and then projects it back to the embedding dimension $r$ with an output matrix $\mathbf{W}_{O}\in\mathbb{R}^{r\times r}$. By abuse of notation, we also denote by $\mathcal{A}$ this operation which results in an output of dimension $r\times n$, and we include the output matrix in the argument of the operator. The $\ell$-th layer of the transformer applies attention with layer-specific weight matrices and a residual connection that leads to an output
$\mathbf{Z}^{(\ell)}=\mathbf{S}^{(\ell-1)}+\mathcal{A}\left(\mathbf{S}^{(\ell-1
)};\mathbf{W}_{Q}^{(\ell)},\mathbf{W}_{K}^{(\ell)},\mathbf{W}_{V}^{(\ell)},
\mathbf{W}_{O}^{(\ell)}\right).$
This is followed by a layer normalization (Zhang & Sennrich, ) that projects each token into the $\ell_{2}$-unit ball, i.e., each column $\mathbf{S}^{(\ell)}_{\cdot,n}$ has an $\ell_{2}$-norm lower than $1$;
- •
Feed-forward block (FF). Finally, a feed-forward block is applied, consisting of a two-layer MLP with hidden dimension $m$, layer-specific weight matrices $\mathbf{W}_{1}^{(\ell)}\in\mathbb{R}^{m\times r},\mathbf{W}_{2}^{(\ell)}\in
\mathbb{R}^{r\times m}$ and ReLU activation denoted by $\operatorname{\mathrm{ReLU}}\left(x\right)=\max\{0,x\}$ and applied entry-wise. The output of this layer reads
$\mathbf{Y}^{(\ell)}=\mathbf{W}_{2}^{(\ell)}\operatorname{\mathrm{ReLU}}\left(
\mathbf{W}_{1}^{(\ell)}\mathbf{Z}^{(\ell)}\right).$
It is followed by a residual connection to produce the output
$\mathbf{S}^{(\ell)}=\mathbf{Z}^{(\ell)}+\mathbf{W}_{2}^{(\ell)}\operatorname{
\mathrm{ReLU}}\left(\mathbf{W}_{1}^{(\ell)}\mathbf{Z}^{(\ell)}\right)\in
\mathbb{R}^{r\times n},$
on which layer normalization (Zhang & Sennrich, ) is applied ensuring that each column $\mathbf{S}^{(\ell)}_{\cdot,n}$ has an $\ell_{2}$-norm lower than $1$.
- •
softmax output layer. In the autoregressive setting, the model outputs a probability distribution on the vocabulary $\mathcal{V}$. To that end, the output $\mathbf{S}^{(L)}\in\mathbb{R}^{r\times n}$ of the final layer is projected back to the vocabulary size by an \sayunembedding layer $\mathbf{W}_{U}\in\mathbb{R}^{T\times r}$ and averaged over the columns to obtain a vector in $\mathbb{R}^{T}$. A softmax layer is finally applied on top of it to obtain the probability distribution of the next token $\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}\right)$. Formally, we have
$\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}\right)=\mathrm{softmax}\left
(\frac{1}{n\tau}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_{n}\right)\in\Delta_
{T},$
$n$ is the length (i.e., number of columns) of the input sequence $\mathbf{S}$ (and thus of the last layer output $\mathbf{S}^{(L)}$), $\bm{\Theta}$ denotes the parameters of the whole network that subsume the parameters of each layer and each block and $\tau$ is the softmax temperature (Hinton, ).

### B.3 Autoregressive Transformer-based LLM

The architecture described above is used in most of the transformer-based autoregressive LLM (Brown et al., ; Dubey et al., ; Anil et al., ; Jiang et al., ). In the theoretical analysis of Section 4, and unless specified otherwise, we remain faithful to their practical implementation and only make the following mild assumption: we assume that the unembedding layer is bounded. The class of parameters and the class of neural networks it generates respectively writes

$$ $\mathcal{W}=\{\bm{\Theta}\mid\lVert\mathbf{W}_{U}^{\top}\rVert_{2,1}\leq B_{U} \}\quad\text{ and }\quad\mathcal{F}=\{f_{\bm{\Theta}}\mid\bm{\Theta}\in \mathcal{W}\}.$ $$

It should be noted that this assumption is significantly weaker than what is usually done in the literature (Zhang et al., ; Edelman et al., ).

## Appendix C Background on Markov Chains

We recall below some important notions related to Markov chains based on (Roberts & Rosenthal, ; Paulin, ) and that will be used in our proofs.

### C.1 Basic Notions

Consider two distribution probabilities $\mathbb{P}$ and $\mathbb{Q}$ defined on a measurable space $\left(\Omega,\mathcal{F}\right)$.

The total variation between $\mathbb{P}$ and $\mathbb{Q}$ is defined as

$$ $d_{\mathrm{TV}}\left(\mathbb{P},\mathbb{Q}\right)\coloneqq\sup_{A\in\mathcal{F }}\lvert\mathbb{P}\left(A\right)-\mathbb{Q}\left(A\right)\rvert.$ $$

In the setting considered in the main paper, we consider Markov chains with finite discrete state space $\Omega$. In this section, we refer to $\Omega$ as a general Polish space, whose elements are referred to as states.

Informally, a discrete-time, time-homogeneous Markov chain with state space $\Omega$ is a sequence of random variables $\left(\mathbf{X}_{1},\mathbf{X}_{2},\ldots\right)$ taking values in $\Omega$ such that the next observation is independent of the past given the present. This property is referred to as the Markov property and is defined below.
{boxdef}
A sequence of random variables $\left(\mathbf{X}_{1},\mathbf{X}_{2},\ldots\right)$ is said to satisfy the Markov property if for all $n\geq 1$ and any $\left(x_{1},\ldots,x_{n+1}\right)\in\Omega^{n+1}$

$$ $\mathbb{P}\left(\mathbf{X}_{n+1}=x_{n+1}\mid\mathbf{X}_{n}=x_{n},\cdots, \mathbf{X}_{1}=x_{1}\right)=\mathbb{P}\left(\mathbf{X}_{n+1}=x_{n+1}\mid \mathbf{X}_{n}=x_{n}\right).$ $$

To a given Markov chain, we associate its *transition kernel* $\mathbf{Q}:\Omega^{2}\to[0,1]$ which collects the transition probabilities from one state to another

$$ $\forall n\in\mathbb{N},(x,y)\in\Omega^{2},\quad\mathbf{Q}(x,y)=\mathbb{P}\left (\mathbf{S}_{n+1}=y\mid\mathbf{S}_{n}=x\right).$ $$

In the main text, we refer to $\mathbf{Q}$ as a transition *matrix* as the Markov chains we consider are of finite state space.

A distribution $\pi$ on $\Omega$ is said to be a stationary distribution if the action of the transition kernel leaves $\pi$ unchanged, that is

$$ $(\mathbf{Q}\pi)(A):=\int_{y\in A}\mathbf{Q}(x,y)d\pi(x)=\pi(A)$ $$

for all $A\in\mathcal{F}$.

A natural question is whether such a distribution exists for a generic Markov chain. Before stating an existence theorem, we introduce a classification of states below.

##### Class of states.

All definitions bellow are borrowed from (Gallager, )

[Accessibility and communication]
A state $x$ is accessible from $y$ (abbreviated as $x\rightarrow y$) if there exists $n>0$ such that $\mathbf{Q}^{n}(x,y)>0$.
Two distinct states $x$ and $y$ communicate (abbreviated $x\leftrightarrow y$) if $x$ is accessible from $y$ and $y$ is accessible from $x$.

Accessibility and communication concepts define how states can reach each other within a Markov chain. This leads to an important classification of states into transient and recurrent categories.

[Recurrent and transient states]
For finite-state Markov chains, a recurrent state is a state $i$ that is accessible from all states that are accessible from $i$ ($i$ is recurrent if $i\rightarrow j$ implies that $j\rightarrow i$).
A transient state is a state that is not recurrent.

With the distinction between recurrent and transient states established, we can now group states into classes based on their communication properties.

[Class of states]
A class $\mathcal{C}$ of states is a non-empty set of states such that each $i\in\mathcal{C}$ communicates with every other state $j\in\mathcal{C}$ and communicates with no $j\notin\mathcal{C}$

##### Aperiodicity and Ergodicity.

Aperiodicity ensures that the system does not exhibit cyclic behavior, which is a key condition for understanding the asymptotic behavior of states.

[Aperiodicity]
The period of a state $i$, denoted $d(i)$, is the greatest common divisor (gcd) of those values of $n$ for which $\mathbf{Q}^{n}(i,i)>0$.
If the period is $1$, the state is aperiodic.

Under some conditions on the Markov chain (aperiodicity and irreducibility (Roberts & Rosenthal, )), it can be proven that the chain converges to its stationary distribution i.e. for any $x\in\Omega$, $\lim_{n\to\infty}d_{\mathrm{TV}}\left(Q^{n}\left(x,\cdot\right),\pi\right)=0$, where $Q^{n}\left(x,\cdot\right)$ denotes the probability of $\mathbf{S}_{n}$ conditioned on $\mathbf{S}_{1}=x$.

We recall below the notion of mixing time that assesses the time taken by the Markov chain to be $\varepsilon$-close to its stationary distribution (see Section C.1).

[Mixing time for time-homogeneous Markov chains (Paulin, )]
Let $X\coloneqq\left(\mathbf{X}_{1},\mathbf{X}_{2},\ldots\right)$ be a time-homogeneous Markov chain with a state space $\Omega$, a transition kernel $Q$, and a stationary distribution $\pi$. Its mixing time is defined for any $\varepsilon\in[0,1]$ as

$$ $t_{\mathrm{mix}}\left(\varepsilon\right)\coloneqq\min{\{t\mid d(t)\leq \varepsilon\}}\text{ where }d(t)\coloneqq\sup_{x\in\Omega}d_{\mathrm{TV}}\left (Q^{t}\left(x,\cdot\right),\pi\right).$ $$

We also introduce the quantity

$$ $t_{\mathrm{min}}\coloneqq\inf_{0\leq\varepsilon<1}t_{\mathrm{mix}}\left(\frac{ \varepsilon}{2}\right)\cdot\left(\frac{2-\varepsilon}{1-\varepsilon}\right)^{2}$ $$

which will be useful later on.

###### Remark C.1 (Well-posedness of $t_{\mathrm{min}}$ ) .

As we only consider finite state-space Markov chains in our work, we know that a stationary distribution always exists. However, its uniqueness and the convergence to it require additional assumptions (see Section C.2). In particular, not all Markov chains admit a finite $t_{\mathrm{mix}}(\varepsilon)$, $t_{\mathrm{min}}$ for some $\varepsilon<\frac{1}{2}$. In such case, $t_{\mathrm{min}}$ can be infinite. In our practical experimentation, this is never the case despite considering various Markov chains.

###### Remark C.1 (Well-posedness of t min subscript 𝑡 min t_{\mathrm{min}} italic_t start_POSTSUBSCRIPT roman_min end_POSTSUBSCRIPT ) .

### C.2 Ergodic Unichains

We are now ready to state the following theorem, which formalizes the classification of states into recurrent, transient, and aperiodic classes.

[Recurrent and transient classes]
For finite state Markov chains, either all states in a class are transient or all are recurrent. We refer to these classes as transient and recurrent, respectively.

For any Markov chain, all states in a class have the same period. If the period is 1, the class is said to be aperiodic

Having categorized states into recurrent, transient, and aperiodic classes, we can now define ergodicity.

[Ergodicity]
For a finite-state Markov chain, an ergodic class of states is a class that is both recurrent and aperiodic. A Markov chain consisting entirely of one ergodic class is
called an ergodic chain.

##### Unichains.

We now introduce the concept of unichains.

[Unichains and ergodic unichains]
A unichain is a finite-state Markov chain containing a single recurrent class and transient states.
An ergodic unichain is a unichain for which the recurrent class is ergodic.

### C.3 Marton Couplings

While we consider Markov chain inputs in Section 4.2, we consider less structured inputs during the pre-training phase Section 4.1.

More specifically, we model the sequences of tokens used during pre-training as generic dependent random variables. To derive meaningful results, we rely on the notion of Marton couplings introduced by Marton (). A Marton coupling can be seen as a weak dependency structure between random variables. The associated notion of the mixing matrix, analogous to the mixing time of a Markov chain, is used to assess the strength of the dependence between those variables.

This minimal modeling choice is made to remain as faithful as possible to the pre-training considered in practical applications of LLMs, for which the pre-training data is not public and may contain arbitrary data points such as video, code snippets, text and images (Dubey et al., ; Touvron et al., ; Anil et al., ; Jiang et al., ; Achiam et al., ; Brown et al., ).

As shown in Paulin (, Remark 2.2.), considering sequences of random variables linked through a Marton coupling is a weaker assumption than what is usually done in the literature on generalization bounds, which typically relies on independent random variables and Markov chains (Wolfer & Kontorovich, ; Zhang et al., ; Hu et al., ; Marion, ).

In particular, the results stated in Section 4.1 encompass the case where the pre-training input sequences of tokens are independent random variables (Kim et al., ) or Markov chains (Zhang et al., ). We also note that Markov chains can model bigrams used in natural language (Jurafsky & Martin, ; Bietti et al., ).

We do not provide an exhaustive review of Marton couplings. We will simply recall its definition and introduce the associated mixing matrix. We refer the interested reader to Marton () and Paulin (). Consider a sequence of dependent random variables $S=\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N}\right)$ taking values in a polish space $\Omega=\Omega_{1}\times\ldots\times\Omega_{N}$. We will denote by $\mathbb{P}\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N}\right)$ the distribution of $S$.

[Marton coupling]
We define a *Marton coupling* for $S$ as a set of couplings

$$ $\left(S^{(s_{1},\ldots,s_{i},s_{i}^{\prime})},{S^{\prime}}^{(s_{1},\ldots,s_{i },s_{i}^{\prime})}\right)\in\Omega\times\Omega,$ $$

for every $i\in[N]$, every $s_{1}\in\Omega_{1},\ldots,s_{i}\in\Omega_{i},s_{i}^{\prime}\in\Omega_{i}$, satisfying the following conditions.

- (i)
$\begin{aligned} \mathbf{S}^{(s_{1},\ldots,s_{i},s_{i}^{\prime})}_{1}&=s_{1},
\hskip 56.9055pt\ldots,\quad&\mathbf{S}^{(s_{1},\ldots,s_{i},s_{i}^{\prime})}_
{i}=s_{i},\\
\mathbf{S}^{\prime(s_{1},\ldots,s_{i},s_{i}^{\prime})}_{1}&=s_{1},\quad\ldots,
\quad\mathbf{S}^{\prime(s_{1},\ldots,s_{i},s_{i}^{\prime})}_{i-1}=s_{i-1},
\quad&\mathbf{S}^{\prime(s_{1},\ldots,s_{i},s_{i}^{\prime})}_{i}=s_{i}^{\prime
}.\end{aligned}$
- (ii)
$\begin{aligned} &\left(\mathbf{S}^{(s_{1},\ldots,s_{i},s_{i}^{\prime})}_{i+1},
\ldots,\mathbf{S}^{(s_{1},\ldots,s_{i},s_{i}^{\prime})}_{N}\right)\\
&\sim\mathbb{P}(\mathbf{S}_{i+1},\ldots,\mathbf{S}_{N}\mid\mathbf{S}_{1}=s_{1}
,\ldots,\mathbf{S}_{i}=s_{i}),\\
&\left({\mathbf{S}^{\prime}}^{(x_{1},\ldots,x_{i},x_{i}^{\prime})}_{i+1},
\ldots,{\mathbf{S}^{\prime}}^{(x_{1},\ldots,x_{i},x_{i}^{\prime})}_{N}\right)
\\
&\sim\mathbb{P}(\mathbf{S}_{i+1},\ldots,\mathbf{S}_{N}\mid\mathbf{S}_{1}=x_{1}
,\ldots,\mathbf{S}_{i-1}=x_{i-1},\mathbf{S}_{i}=x_{i}^{\prime}).\end{aligned}$
- (iii)
If $x_{i}=x_{i}^{\prime}$, then $S^{(x_{1},\ldots,x_{i},x_{i}^{\prime})}=S^{\prime(x_{1},\ldots,x_{i},x_{i}^{
\prime})}$.

[Mixing matrix (Paulin, )]
For a Marton coupling, we define
the *mixing matrix* $\bm{\Gamma}\in\mathbb{R}^{N\times N}$ as an upper diagonal matrix with

$$ $\forall 1\leq i<j\leq N,\quad\begin{cases}&\bm{\Gamma}_{i,i}:=1,\\ &\bm{\Gamma}_{j,i}:=0\\ &\bm{\Gamma}_{i,j}:=\sup_{s_{1},\ldots,s_{i},s_{i}^{\prime}}\mathbb{P}\left[ \mathbf{S}^{(s_{1},\ldots,s_{i},s_{i}^{\prime})}_{j}\neq{\mathbf{S}^{\prime}}^ {(s_{1},\ldots,s_{i},s_{i}^{\prime})}_{j}\right]\end{cases}.$ $$

For independent random variables, one can define a Marton coupling with a mixing matrix equal to the identity (see Paulin, , Remark 2.2). In particular, it means that for independent variables, we have the operator norm of the mixing matrix equal to $1$, i.e., $\lVert\bm{\Gamma}\rVert=1$.

### C.4 An (Almost) Distance between Markov Chains

In Section D.7.4,
We state elementary properties of $\mathcal{K}$ in the proposition below.
{boxprop}[Properties of $\mathcal{K}$]
$\mathcal{K}$ is an *almost*-distance between transition matrices in the sense that it satisfies the properties below:

- 1.
Non-negativity. For any $\bm{\Theta}_{1},\bm{\Theta}_{2}$, $\mathcal{K}(\bm{\Theta}_{1},\bm{\Theta}_{2})\geq 0$.
- 2.
Almost sure positivity. $\mathcal{K}(\bm{\Theta}_{1},\bm{\Theta}_{2})=0\iff\forall n\in[N],\mathbb{P}_{
\bm{\Theta}_{1}}\left(\cdot\mid\mathbf{S}_{n}\right)=\mathbb{P}_{\bm{\Theta}_{
2}}\left(\cdot\mid\mathbf{S}_{n}\right)\text{ a.s.}$.
- 3.
Symmetry. For any $\bm{\Theta}_{1},\bm{\Theta}_{2}$, $\mathcal{K}(\bm{\Theta}_{1},\bm{\Theta}_{2})=\mathcal{K}(\bm{\Theta}_{1},\bm{
\Theta}_{2})$.
- 4.
Triangular inequality.. For any $\bm{\Theta}_{1},\bm{\Theta}_{2},\bm{\Theta}_{3}$, $\mathcal{K}(\bm{\Theta}_{1},\bm{\Theta}_{3})\leq\mathcal{K}(\bm{\Theta}_{1},
\bm{\Theta}_{2})+\mathcal{K}(\bm{\Theta}_{2},\bm{\Theta}_{3})$.

###### Proof of Section C.4 .

We first recall the following technical lemma.
{boxlem}[Proposition 2.16 in Folland ()]
Let $Y$ be a non-negative random variable defined on a probability space $\Omega$ with probability function $\mathbb{P}$. If $\mathbb{E}\left[Y\right]=0$, then $Y=0$ almost surely, i.e.,

$$ $\mathbb{P}\left(\{\omega\in\Omega\mid Y(\omega)=0\}\right)=1$ $$

The non-negativity and symmetry of $\mathcal{K}$ directly come from the symmetry and non-negativity of the total variation distance. The triangular inequality follows from the fact that the total variation is a distance and that the expectation respects inequalities. For the almost positivity, consider $\bm{\Theta}_{1},\bm{\Theta}_{2}$ such that $\mathcal{K}(\bm{\Theta}_{1},\bm{\Theta}_{2})=0$. By non-negativity of all the terms in the sum, it means that for all $n\in[N]$, we have

$$ $\mathbb{E}_{\mathbf{S}_{n}}\left[d_{\mathrm{TV}}\left(\mathbb{P}_{\bm{\Theta}_ {1}}\left(\cdot\mid\mathbf{S}_{n}\right),\mathbb{P}_{\bm{\Theta}_{2}}\left( \cdot\mid\mathbf{S}_{n}\right)\right)\right]=0.$ $$

As the total variation is a distance, we know that the random variable under the expectation is non-negative. Applying Section C.4 leads to

$$ $d_{\mathrm{TV}}\left(\mathbb{P}_{\bm{\Theta}_{1}}\left(\cdot\mid\mathbf{S}_{n} \right),\mathbb{P}_{\bm{\Theta}_{2}}\left(\cdot\mid\mathbf{S}_{n}\right)\right )=0\quad\text{ almost surely}.$ $$

On the probability space, deprived of the set where the distance is non-zero (which is of null measure), the total variation is equal to zero and as a distance between probability distributions, it means that on this subset of the probability space, the probabilities are equal. Again, as the set on which they are not equal is of null measure, we have

$$ $\mathbb{P}_{\bm{\Theta}_{1}}\left(\cdot\mid\mathbf{S}_{n}\right)=\mathbb{P}_{ \bm{\Theta}_{2}}\left(\cdot\mid\mathbf{S}_{n}\right)\quad\text{ almost surely}.$ $$

Putting everything together, we have

$$ $\forall n\in[N],\mathbb{P}_{\bm{\Theta}_{1}}\left(\cdot\mid\mathbf{S}_{n} \right)=\mathbb{P}_{\bm{\Theta}_{2}}\left(\cdot\mid\mathbf{S}_{n}\right)\quad \text{ a.s.},$ (5) $$

which concludes the direct sense. The converse sense is proved by assuming that Eq. 5 holds and using the distance properties of the total variation. This concludes the proof.
∎

###### Proof of Section C.4 .

## Appendix D Proofs

### D.1 Proof of Section 3.1

We detail below the proof of Section 3.1.

###### Proof of Section 3.1 .

Step 1: Autoregressive models as Markov chains. Given an input $v_{i}\in\mathcal{V}_{K}^{*}$ of $p$ tokens, an autoregressive model outputs a probability mass function $f_{\bm{\Theta}}^{T,K}(v_{i})$ over the discrete vocabulary space. As the temperature is positive, i.e., $\tau>0$, and as the exponential is positive, we know that all the tokens in the vocabulary will be given a positive mass.

A next sequence $v_{j}\in\mathcal{V}_{K}^{*}$ is then sampled according to $f_{\bm{\Theta}}^{T,K}(v_{i})$. But the $v_{j}$ sequences that fit necessarily contain the $v_{i}$ sequence (except possibly the first element of $v_{i}$, thanks to Section B.1), i.e. $\forall l,(v_{j})_{l}=(v_{i})_{l+1}$. Note also the size of $v_{j}$ is $p+1$ when $p<k$ and $k$ when $p=k$. All other sequences $v_{j}$ that do not satisfy this condition are not suitable.

In that sense, $f_{\bm{\Theta}}^{T,K}$ can be represented by a Markov chain $\text{MC}(\mathcal{V}_{K}^{*},\mathbf{Q}_{f})$ with transition kernel $\mathbf{Q}_{f}\in\mathbb{R}^{|\mathcal{V}_{K}^{*}|\times|\mathcal{V}_{K}^{*}|}$, as defined in Section 3.1.

Step 2: Proportion of non-zero elements. We denote by $\mathscr{R}$ the set of states of length $K$. The set of states of length strictly less than equal $K$ is denoted by $\mathscr{T}$. We can construct a transition matrix $P_{\mathscr{R}}\in\mathbb{R}^{T^{K}\times T^{K}}$ with the states of this class, containing the probabilities of moving from one state of $\mathscr{R}$ to another. $P_{\mathscr{R}}$ corresponds to the blue block in Fig. 1 while green rectangle blocks correspond to part of $P_{\mathscr{T}}$ and $P_{\mathscr{TR}}$ in the following description of autoregressive models as Markov chains,

$$ $\mathbf{Q}_{f}=\pNiceMatrix[columns-width=auto,hvlines,cell-space-limits=4pt]P _{\mathscr{T}}&P_{\mathscr{TR}}\\ 0P_{\mathscr{R}}\\ .$ (6) $$

Now, let us count the number of non-zero elements in each of these $4$ large blocks.

$P_{\mathscr{T}}$ block : The size of this block is $\displaystyle\Big{[}\frac{T}{T-1}(T^{K-1}-1)\Big{]}\times\Big{[}\frac{T}{T-1}(
T^{K-1}-1)\Big{]}$. There are $K-2$ green blocks contained in $P_{\mathscr{T}}$. The block number $i\in[K-2]$ is of size $T^{i}\times T^{i+1}$. Since each sentence of size $i$ can be completed with non-zero probability, by any other token, there are a total of $\sum_{p=1}^{T^{i}}T=T^{i+1}$ non-zero elements. There are therefore $\sum_{i=1}^{K-2}T^{i+1}$ non-zero elements in the entire $P_{\mathscr{T}}$ block.

$P_{\mathscr{TR}}$ block : The size of this block is $\displaystyle\Big{[}\frac{T}{T-1}(T^{K-1}-1)\Big{]}\times T^{K}$. The green block contained in $P_{\mathscr{TR}}$ that contains non-zero elements is of size $T^{K-1}\times T^{K}$. Since each sentence of size $K-1$ can be completed with non-zero probability, by any other token, there are a total of $\sum_{p=1}^{T^{K-1}}T=T^{K}$ non-zero elements.

$P_{\mathscr{R}}$ block : The size of this block is $T^{K}\times T^{K}$. Each sentence $v=(v_{1},\ldots,v_{K})$ of size $K$ is mapped to another sentence $v^{\prime}=(v_{1}^{\prime},\ldots,v_{K}^{\prime})$ of size $K$ with non-zero probability, if and only if $v_{1}^{\prime}=v_{2},v_{2}^{\prime}=v_{3},\ldots,v^{\prime}_{k-1}=v_{K}$. The final token $v^{\prime}_{K}$ can by any other token in the vocabulary. It means that there are a total of $\sum_{p=1}^{T^{K}}T=T^{K+1}$ non-zero elements.

$0^{\prime}s$ block : Obviously, there are no non-zero elements in this block.

Finally, there are

$$ $\sum_{i=1}^{K-2}T^{i+1}+T^{K}+T^{K+1}=\sum_{i=1}^{K}T^{i+1}=T^{2}\left(\frac{T ^{K}-1}{T-1}\right)$ $$

non-zero elements. This means that the proportion of non-zero elements in the matrix is exactly

$$ $\frac{T^{2}\left(\frac{T^{K}-1}{T-1}\right)}{\left(T\left(\frac{T^{K}-1}{T-1} \right)\right)^{2}}=\frac{T-1}{T^{K}-1}.$ $$

Note that for large $T$ and $K$ we have that

$$ $\frac{T-1}{T^{K}-1}\sim\frac{1}{T^{K-1}}.$ $$

∎

###### Proof of Section 3.1 .

### D.2 Proof of Section 3.1

We begin with a preliminary lemma.

[Powers of $\mathbf{Q}_{f}$ greater than $K$]
For any initial state $i$, the following hold:

- •
$\forall k\geq K,\forall j\in\mathscr{T},(\mathbf{Q}_{f}^{k})_{i,j}=0$,
- •
$\forall k\geq K,\forall j\in\mathscr{R},(\mathbf{Q}_{f}^{k})_{i,j}>0$.

###### Proof.

By considering $\mathbf{Q}_{f}$ as defined in (6), we can compute its powers. For any $k\geq 1,$

$$ $\mathbf{Q}_{f}^{k}=\pNiceMatrix[columns-width=auto,hvlines,cell-space-limits=4 pt]P_{\mathscr{T}}^{k}&B_{k}\\ 0P_{\mathscr{R}}^{k}\\ ,$ $$

where $B_{k}=\sum_{m=0}^{k-1}P_{\mathscr{T}}^{m}P_{\mathscr{TR}}P_{\mathscr{R}}^{k-1-m}$.

To prove the first item, we focus on the blocks on the left of $\mathbf{Q}_{f}$. Since the lower left block is zero, we have that $\forall k\geq 1,\forall i\in\mathscr{R},\forall j\in\mathscr{T},(\mathbf{Q}_{f
}^{k})_{i,j}=0$. In the upper left block, the element $(P_{\mathscr{T}}^{k})_{i,j}$ designates the probability of moving from one transient state $i\in\mathscr{T}$ to another transient state $j\in\mathscr{T}$ after $k$ iterations. According to Section B.1, if state $i$ is a sequence of $p\geq 1$ tokens, state $j$ is necessarily a sequence of $\min\{K,p+K\}=K$ elements. Thus, $P_{\mathscr{T}}$ is a nilpotent matrix and $\forall k\geq K,\forall i,j,(P_{\mathscr{T}}^{k})_{i,j}=0$. This proves that $\forall k\geq K,\forall j\in\mathscr{T},(\mathbf{Q}_{f}^{k})_{i,j}=0$.

We now move on to the second item. From the above, $\forall k\geq K,B_{k}=\sum_{m=0}^{K-1}P_{\mathscr{T}}^{m}P_{\mathscr{TR}}P_{
\mathscr{R}}^{k-1-m}$. Note that this sum is finite, but there is still a dependence on $k$, in the powers of the matrix $P_{\mathscr{R}}$. In the lower right block, the element $(P_{\mathscr{R}}^{k})_{i,j}$ designates the probability of moving from one recurrent state $i\in\mathscr{R}$ to another recurrent state $j\in\mathscr{R}$ after $k$ iterations. According to the definition of $\mathbf{Q}_{f}$ in Section 3.1 and Section B.1, $\forall k\geq K,\forall i,j\in\mathscr{R}^{2},(P_{\mathscr{R}}^{k})_{i,j}$ is nonzero. Exploiting this also in $B_{k}$, we obtain the result, i.e. $\forall k\geq K,\forall j\in\mathscr{R},(\mathbf{Q}_{f}^{k})_{i,j}>0$.
∎

We are now ready to prove Section 3.1, which is inspired by  Gallager ().

###### Proof of Section 3.1 .

The states of length strictly less than equal $K$ (elements of $\mathscr{T}$) are transient, because of Section B.1. To discuss the nature of states of length $K$ (elements of $\mathscr{R}$), let us introduce a result regarding the powers of the $\mathbf{Q}_{f}$ matrix as defined in (6). Thanks to Section D.2, the set of states $\mathscr{R}$ (i.e. the states of length $K$) form a class. Section D.2 gives us also that $\mathscr{R}$ is ergodic. In fact, every state in $\mathscr{R}$ only communicates with all the other states in $\mathscr{R}$, which proves the recurrence. Since $\forall i,j\in\mathscr{R}^{2},(\mathbf{Q}_{f}^{K})_{i,j}>0$, we can move between any two states in exactly $K$ steps, regardless of the initial position. This ensures that $\mathscr{R}$ is aperiodic because the transition probabilities do not depend on a specific cycle, and states can be revisited at various time steps, not just multiples of a particular number. More simply, by considering a token $x$, the state defined as $i=\underbrace{xx\ldots x}_{\text{$K$ times}}$ has period $1$, i.e. $(\mathbf{Q}_{f})_{i,i}>0$. This is a consequence of Section B.1 and Section 3.1. Thanks to Section C.2, it means that the whole class $\mathscr{R}$ is aperiodic. Finally, this means that $\text{MC}(\mathcal{V}_{K}^{*},\mathbf{Q}_{f})$ are ergodic unichains, in the sense of Section C.2.
∎

###### Proof.

###### Proof of Section 3.1 .

### D.3 Proof of Section 3.1

We start by introducing three technical lemmas that will be useful in the proof of Section 3.1. We start with the Chapman–Kolmogorov equation.

[Chapman-Kolmogorov equation]
Let $P$ be a matrix of size $d$. Then, $P$ satisfies

$$ $\forall i,j\in[d]^{2},\forall n,n^{\prime}\in\mathbb{N}^{2},(P^{n+n^{\prime}}) _{i,j}=\sum_{k=1}^{d}(P^{n})_{i,k}(P^{n^{\prime}})_{k,j}.$ $$

###### Proof.

The result follows from the fact that $\forall n,n^{\prime}\in\mathbb{N}^{2},P^{n+n^{\prime}}=P^{n}P^{n^{\prime}}$.
∎

Then, we introduce a simple but useful result of monotonicity.

[Lemma 3.3.1. in  Gallager ()]
Let the transition matrix $P$ of a finite state Markov chain.
Then, for all states $j$ and $n\geq 1$, we have

$$ $\underset{i}{\max}~{}(P^{n+1})_{i,j}\leq\underset{i}{\max}~{}(P^{n})_{i,j}, \quad\text{and}\quad\underset{i}{\min}~{}(P^{n+1})_{i,j}\geq\underset{i}{\min} ~{}(P^{n})_{i,j}.$ $$

We now refer to a result on Markov chains with positive transition matrices.

[Lemma 3.3.2. in Gallager ()]
Let the transition matrix $P$ of a finite state Markov chain satisfy $\forall i,j,P_{i,j}>0$, and let $\alpha=\underset{i,j}{\min}~{}P_{i,j}>0$. Then, for all states $j$ and $n\geq 1$,

$$ $\displaystyle\underset{i}{\max}~{}(P^{n})_{i,j}-\underset{i}{\min}~{}(P^{n})_{ i,j}$ $\displaystyle\leq(1-2\alpha)\left(\underset{i}{\max}~{}(P^{n})_{i,j}-\underset {i}{\min}~{}(P^{n})_{i,j}\right),$ $\displaystyle\underset{i}{\max}~{}(P^{n})_{i,j}-\underset{i}{\min}~{}(P^{n})_{ i,j}$ $\displaystyle\leq(1-2\alpha)^{n},$ $\displaystyle\lim_{n\to\infty}\underset{i}{\max}~{}(P^{n})_{i,j}$ $\displaystyle=\lim_{n\to\infty}\underset{i}{\min}~{}(P^{n})_{i,j}>0.$ $$

We are now ready to prove Section 3.1 using a similar argument as in Gallager ().

###### Proof of Section 3.1 .

Let $\mathscr{T}$ and $\mathscr{R}$ denote respectively the sets of transient and recurrent states. For any state $j$, we define $\pi_{j}:=\lim_{n\to\infty}\max_{i}~{}(\mathbf{Q}_{f}^{n})_{i,j}=\lim_{n\to
\infty}\min_{i}~{}(\mathbf{Q}_{f}^{n})_{i,j}$. Then $\bm{\pi}=(\pi_{j})_{j\in\Omega}$ is the stationary distribution for $\mathbf{Q}_{f}$.

###### Proof.

###### Proof of Section 3.1 .

##### Step 1: Stationary distribution for transient states.

Section D.2 gives us that $\forall i,\forall k\geq K,\forall j\in\mathscr{T},(\mathbf{Q}_{f}^{k})_{i,j}=0$. This means that $\forall j\in\mathscr{T},\pi_{j}=0$ and hence the limit is reached at most after $K$ iteration.

##### Step 2: Stationary distribution for recurrent states.

Section D.2 gives us $\forall i,j\in\mathscr{R}^{2},(\mathbf{Q}_{f}^{K})_{i,j}>0$. By defining $\varepsilon:=\underset{i,j\in\mathscr{R}^{2}}{\min}~{}(\mathbf{Q}_{f}^{K})_{i,j}$, Section D.3 shows that for any integer $\ell\geq 1,$

$$ $\displaystyle\underset{i\in\mathscr{R}}{\max}~{}(\mathbf{Q}_{f}^{\ell K})_{i,j }-\underset{i\in\mathscr{R}}{\min}~{}(\mathbf{Q}_{f}^{\ell K})_{i,j}$ $\displaystyle\leq(1-2\varepsilon)\left(\underset{i\in\mathscr{R}}{\max}~{}( \mathbf{Q}_{f}^{\ell K})_{i,j}-\underset{i\in\mathscr{R}}{\min}~{}(\mathbf{Q}_ {f}^{\ell K})_{i,j}\right),$ (7) $\displaystyle\underset{i\in\mathscr{R}}{\max}~{}(\mathbf{Q}_{f}^{\ell K})_{i,j }-\underset{i\in\mathscr{R}}{\min}~{}(\mathbf{Q}_{f}^{\ell K})_{i,j}$ $\displaystyle\leq(1-2\varepsilon)^{\ell},$ (8) $\displaystyle\lim_{\ell\to\infty}\underset{i\in\mathscr{R}}{\max}~{}(\mathbf{Q }_{f}^{\ell K})_{i,j}$ $\displaystyle=\lim_{\ell\to\infty}\underset{i\in\mathscr{R}}{\min}~{}(\mathbf{ Q}_{f}^{\ell K})_{i,j}>0.$ (9) $$

Thanks to Section D.3, $\underset{i}{\max}~{}(\mathbf{Q}_{f}^{n+1})_{i,j}$ is non-decreasing in $n$, so the limit on the left in Eq. 9 can be replaced with a limit in $n$. The same argument for the limit on the right gives that, $\forall j\in\mathscr{R}$,

$$ $\displaystyle\underset{i\in\mathscr{R}}{\max}~{}(\mathbf{Q}_{f}^{n})_{i,j}- \underset{i\in\mathscr{R}}{\min}~{}(\mathbf{Q}_{f}^{n})_{i,j}$ $\displaystyle\leq(1-2\varepsilon)^{\lfloor n/K\rfloor},$ $\displaystyle\lim_{n\to\infty}\underset{i\in\mathscr{R}}{\max}~{}(\mathbf{Q}_{ f}^{n})_{i,j}$ $\displaystyle=\lim_{n\to\infty}\underset{i\in\mathscr{R}}{\min}~{}(\mathbf{Q}_ {f}^{n})_{i,j}>0,$ $$

where we have taken the floor function to also convert the result of (8). Since $\pi_{j}$ lies between the minimum and maximum $(\mathbf{Q}_{f}^{n})_{i,j}$ for each $n$, we have that $\forall i,j\in\mathscr{R}^{2}$,

$$ $\lvert(\mathbf{Q}_{f}^{n})_{i,j}-\pi_{j}\rvert\leq(1-2\varepsilon)^{\lfloor \frac{n}{K}\rfloor}.$ $$

It means that $\forall i,j\in\mathscr{R}^{2},\pi_{j}=\lim_{n\to\infty}(\mathbf{Q}_{f}^{n})_{i
,j}$. This also gives us the convergence rate when the initial state $i$ is recurrent. In the next step, we consider the general convergence rate, regardless of the nature of the initial state $i$.

##### Step 3: Convergence bound.

We proceed to the remaining case, i.e. the case where the initial state $i\in\mathscr{T}$ and the final state $j\in\mathscr{R}$. Section D.3 says that $\forall n\geq K$,

$$ $(\mathbf{Q}_{f}^{n})_{i,j}=\sum_{k\in\mathscr{T}}(\mathbf{Q}_{f}^{K})_{i,k}( \mathbf{Q}_{f}^{n-K})_{k,j}+\sum_{k\in\mathscr{R}}(\mathbf{Q}_{f}^{K})_{i,k}( \mathbf{Q}_{f}^{n-K})_{k,j}.$ $$

We then have that $\forall i\in\mathscr{T},\forall n\in\mathbb{N},$

$$ $\displaystyle\lvert(\mathbf{Q}_{f}^{n})_{i,j}-\pi_{j}\rvert$ $\displaystyle\leq\Big{\lvert}\sum_{k\in\mathscr{T}}(\mathbf{Q}_{f}^{K})_{i,k} \big{[}(\mathbf{Q}_{f}^{n-K})_{k,j}-\pi_{j}\big{]}+\sum_{k\in\mathscr{R}}( \mathbf{Q}_{f}^{K})_{i,k}\big{[}(\mathbf{Q}_{f}^{n-K})_{k,j}-\pi_{j}\big{]} \Big{\rvert}$ $\displaystyle\leq\sum_{k\in\mathscr{T}}(\mathbf{Q}_{f}^{K})_{i,k}\big{\lvert}( \mathbf{Q}_{f}^{n-K})_{k,j}-\pi_{j}\big{\rvert}+\sum_{k\in\mathscr{R}}(\mathbf {Q}_{f}^{K})_{i,k}\big{\lvert}(\mathbf{Q}_{f}^{n-K})_{k,j}-\pi_{j}\big{\rvert}$ $\displaystyle\leq\sum_{k\in\mathscr{T}}(\mathbf{Q}_{f}^{K})_{i,k}+\sum_{k\in \mathscr{R}}(\mathbf{Q}_{f}^{K})_{i,k}\big{\lvert}(\mathbf{Q}_{f}^{n-K})_{k,j} -\pi_{j}\big{\rvert}$ $\displaystyle\leq(1-2\varepsilon)^{\lfloor\frac{n-K}{K}\rfloor},$ $$

where the first sum vanishes and $\sum_{k\in\mathscr{R}}(\mathbf{Q}_{f}^{K})_{i,k}\leq 1$. Finally, $\forall i\in\mathscr{T},\forall n\geq K,$

$$ $\lvert(\mathbf{Q}_{f}^{n})_{i,j}-\pi_{j}\rvert\leq(1-2\varepsilon)^{\lfloor \frac{n}{K}\rfloor-1}.$ $$

Combining this with the result of Step $2$ concludes the proof.
∎

### D.4 Proof of Section 4.1

In this section, we detail the proof of Section 4.1. We provide below an overview of the proof before detailing it.

##### Overview of the proof.

We are going to use McDiarmid’s inequality for dependent random variables of Paulin (, Theorem 2.9). To adapt the arguments of Paulin (, Theorem 2.9) to our setting, we bound the total variation between the true probability of the next token and the one estimated by the LLM. The rest of this section is organized as follows. First in Section D.4.1, we adapt the concentration inequality of Paulin (, Theorem 2.9). Then in Section D.4.2, we show how to bound the total variation between the true and the estimated probability of the next token. , in Section D.4.3, we restate Section 4.1 and conclude the proof.

#### D.4.1 Concentration Inequalities for Dependent Random Variables

We first state a concentration inequality for dependent random variables that will be used to obtain our final bound.

[McDiarmid’s inequality for dependent random variables]
Let $S\coloneqq\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N}\right)$ be a sequence of random variables that take values in $\Omega=\Omega_{1}\times\ldots\times\Omega_{N}$. Assume there exists a Marton coupling for $S$ with mixing matrix $\bm{\Gamma}$. Let $\lVert\bm{\Gamma}\rVert$ be the operator norm of $\bm{\Gamma}$. If $f\colon\Omega\to\mathbb{R}$ is such that there exists $\mathbf{c}\in\mathbb{R}^{N}$ satisfying

$$ $\forall\mathbf{x},\mathbf{y}\in\Omega,\quad f(\mathbf{x})-f(\mathbf{y})\leq \sum_{i=1}^{N}\mathbf{c}_{i}\mathbbm{1}_{\{\mathbf{x}_{i}\neq\mathbf{y}_{i}\}},$ $$

then we have for any $u\geq 0$,

$$ $\mathbb{P}\left(\lvert f(S)-\mathbb{E}_{S}\left[f(S)\right]\rvert\geq u\right) \leq 2\exp{\left(\frac{-2u^{2}}{\lVert\bm{\Gamma}\rVert^{2}\lVert\mathbf{c} \rVert_{2}^{2}}\right)}.$ $$

###### Proof.

Consider a function $f$ verifying the properties of Section D.4.1. Paulin (, Theorem 2.9) ensures that for a partition $\hat{S}$ of $S$ (see Paulin, , Definition 2.3) the following inequality holds

$$ $\forall u\geq 0,\quad\mathbb{P}\left(\lvert f(\hat{S})-\mathbb{E}\left[f(\hat{ S})\right]\rvert\geq u\right)\leq 2\exp{\left(\frac{-2u^{2}}{\lVert\bm{\Gamma} \cdot C(\mathbf{c})\rVert_{2}^{2}}\right)},$ (10) $$

where $C(\mathbf{c})$ is a vector of $\mathbb{R}^{N}$ whose $i$-th element is the sum of the $\mathbf{c}_{j}$ such that $j$ is an index of the elements of $\hat{\mathbf{S}}_{i}$. Taking the trivial partition $\hat{S}=S$ implies that the index of the elements in $\hat{\mathbf{S}}_{i}$ are reduced to $\{i\}$. Hence the $i$-th entry of $C(\mathbf{c})$ is equal to $\mathbf{c}_{i}$ and $C(\mathbf{c})=\mathbf{c}$. By definition of the operator norm (naturally induced by the $\ell_{2}$-norm), we have

$$ $\lVert\bm{\Gamma}\cdot\mathbf{c}\rVert_{2}=\frac{\lVert\bm{\Gamma}\mathbf{c} \rVert_{2}}{\lVert\mathbf{c}\rVert_{2}}\cdot\lVert\mathbf{c}\rVert_{2}\leq \underbrace{\sup_{\mathbf{x}\neq 0}\frac{\lVert\bm{\Gamma}\mathbf{x}\rVert_{2} }{\lVert\mathbf{x}\rVert_{2}}}_{=\lVert\bm{\Gamma}\rVert}\cdot\lVert\mathbf{c} \rVert_{2}\leq\lVert\bm{\Gamma}\rVert\cdot\lVert\mathbf{c}\rVert_{2},$ $$

where the first inequality comes from the fact that $\mathbf{c}$ is non-zero (otherwise the only possible $f$ is the zero function which is not of great interest). Using the fact that the function $x\to\exp{(-\frac{2u^{2}}{x})}$ is increasing, we obtain

$$ $\exp{\left(\frac{-2u^{2}}{\lVert\bm{\Gamma}\cdot\mathbf{c}\rVert_{2}^{2}} \right)}\leq\exp{\left(\frac{-2u^{2}}{\lVert\bm{\Gamma}\rVert^{2}\cdot\lVert \mathbf{c}\rVert_{2}^{2}}\right)},$ $$

which concludes the proof.
∎

By looking at the definition of the risk $\widehat{\mathcal{R}}_{\mathrm{pre}}\left(\bm{\Theta}\right)$, we can see that applying Section D.4.1 to the function

$$ $f\colon\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N_{\mathrm{train}}}\right)= \frac{1}{N_{\mathrm{train}}}\sum_{n=1}^{N_{\mathrm{train}}}d_{\mathrm{TV}} \left(\mathbb{P}_{\mathcal{L}}\left(\cdot\mid\mathbf{S}_{n}\right),\mathbb{P}_ {\bm{\Theta}}\left(\cdot\mid\mathbf{S}_{n}\right)\right),$ $$

would lead to the desired bound as we already know $S$ admits a Marton coupling with mixing matrix $\bm{\Gamma}$. We investigate in the next section how to find the bounding vector $\mathbf{c}$ to apply Section D.4.1.

###### Proof.

#### D.4.2 Finding the Bounding Vector

##### Technical lemmas.

We first recall the following important notions from (Tsybakov, ). Let $\left(\Omega,\mathcal{F}\right)$ be a measure space and consider two probability distributions $\mathbb{P},\mathbb{Q}$ defined on $\left(\Omega,\mathcal{F}\right)$. For any $\sigma$-finite measure $\nu$ on $\left(\Omega,\mathcal{F}\right)$ such that $\mathbb{P},\mathbb{Q}$ are absolutely continuous with respect to $\nu$, we can define $p=\frac{d\mathbb{P}}{d\nu},q=\frac{d\mathbb{Q}}{d\nu}$ which can also be written as $\mathbb{P}(d\omega)=q(\omega)\nu(d\omega)$ and $\mathbb{Q}(d\omega)=p(\omega)\nu(d\omega)$. We will adopt both notations interchangeably. It should be noted that there always exists at least one such measure $\nu$ as one can take $\nu=\mathbb{P}+\mathbb{Q}$. With these notations, the squared Hellinger distance between $\mathbb{P}$ and $\mathbb{Q}$ is defined as

$$ $H\left(\mathbb{P},\mathbb{Q}\right)^{2}\coloneqq\int_{\omega\in\Omega}\left( \sqrt{p(\omega)}-\sqrt{q(\omega)}\right)^{2}\nu(d\omega)=\int_{\omega\in\Omega }\left(\sqrt{\mathbb{P}(d\omega)}-\sqrt{\mathbb{Q}(d\omega)}\right)^{2}.$ $$

The lemma below shows that the total variation between two probability distributions is controlled from above by the absolute value of the logarithm of their ratio.
{boxlem}
Consider two probability distributions $\mathbb{P},\mathbb{Q}$ defined on a measure space $\left(\Omega,\mathcal{F}\right)$ and a $\sigma$-finite measure $\nu$ on $\left(\Omega,\mathcal{F}\right)$. Let $p,q$ be the corresponding probabilities densities, i.e., we have $\mathbb{P}(d\omega)=q(\omega)\nu(d\omega)$ and $\mathbb{Q}(d\omega)=p(\omega)\nu(d\omega)$, the total variation between $\mathbb{P}$ and $\mathbb{Q}$ satisfies

$$ $d_{\mathrm{TV}}\left(\mathbb{P},\mathbb{Q}\right)\leq\left(2\int_{\omega\in \Omega}\left|\log{\sqrt{\frac{\mathbb{P}(d\omega)}{\mathbb{Q}(d\omega)}}} \right|q(\omega)d\nu(d\omega)\right)^{1/2}.$ $$

If there exists a non-negative constant $B$ such that for any $z\in\Omega$, $\left|\log{\sqrt{\frac{\mathbb{P}(z)}{\mathbb{Q}(z)}}}\right|\leq B$,
then we have

$$ $d_{\mathrm{TV}}\left(\mathbb{P},\mathbb{Q}\right)\leq\sqrt{2B}.$ $$

###### Proof.

We have the following relation between the total variation and the Hellinger distance (cf. Tsybakov, , Lem. 2.3, Chapt. 2, p. 86):

$$ $d_{\mathrm{TV}}\left(\mathbb{P},\mathbb{Q}\right)^{2}\leq H\left(\mathbb{P}, \mathbb{Q}\right)^{2}\cdot\left(1-\underbrace{H\left(\mathbb{P},\mathbb{Q} \right)^{2}/4}_{\geq 0}\right)\leq H\left(\mathbb{P},\mathbb{Q}\right)^{2},$ (11) $$

where the last inequality uses the positivity of the Hellinger distance. Inspired by the decomposition of the Hellinger distance in (Agarwal et al., , Lem. 25), we have

$$ $\displaystyle H\left(\mathbb{P},\mathbb{Q}\right)^{2}$ $\displaystyle=\int_{\omega\in\Omega}\left(\sqrt{\mathbb{P}(d\omega)}-\sqrt{ \mathbb{Q}(d\omega)}\right)^{2}=\int_{\omega\in\Omega}\left(\mathbb{P}(d\omega )+\mathbb{Q}(d\omega)-2\sqrt{\mathbb{P}(d\omega)}\sqrt{\mathbb{Q}(d\omega)}\right)$ $\displaystyle=2\cdot\left(1-\int_{\omega\in\Omega}\sqrt{\mathbb{P}(d\omega)} \sqrt{\mathbb{Q}(d\omega)}\right)=2\cdot\left(1-\int_{\omega\in\Omega}\sqrt{ \frac{\mathbb{P}(d\omega)}{\mathbb{Q}(d\omega)}}\mathbb{Q}(d\omega)\right)$ $\displaystyle=2\cdot\left(1-\int_{\omega\in\Omega}\sqrt{\frac{\mathbb{P}(d \omega)}{\mathbb{Q}(d\omega)}}q(\omega)d\nu(d\omega)\right)$ (by definition of $\mathbb{Q}(d\omega)$ ) $\displaystyle\leq-2\log{\left(\int_{\omega\in\Omega}\sqrt{\frac{\mathbb{P}(d \omega)}{\mathbb{Q}(d\omega)}}q(\omega)d\nu(d\omega)\right)}$ (using $1-x\leq-\log{(x)}$ ) $$

It follows using Eq. 11

$$ $\displaystyle d_{\mathrm{TV}}\left(\mathbb{P},\mathbb{Q}\right)^{2}$ $\displaystyle\leq H\left(\mathbb{P},\mathbb{Q}\right)^{2}$ $\displaystyle\leq 2\int_{\omega\in\Omega}-\log{\left(\sqrt{\frac{\mathbb{P}(d \omega)}{\mathbb{Q}(d\omega)}}\right)}q(\omega)d\nu(d\omega)$ (by Jensen as $-\log$ is convex) $\displaystyle\leq 2\left|\int_{\omega\in\Omega}-\log{\left(\sqrt{\frac{\mathbb {P}(d\omega)}{\mathbb{Q}(d\omega)}}\right)}q(\omega)d\nu(d\omega)\right|$ $\displaystyle\leq 2\int_{\omega\in\Omega}\left|-\log{\left(\sqrt{\frac{\mathbb {P}(d\omega)}{\mathbb{Q}(d\omega)}}\right)}\right|q(\omega)d\nu(d\omega)$ (by Jensen as $\lvert\cdot\rvert$ is convex) $\displaystyle\leq 2\int_{\omega\in\Omega}\underbrace{\left|\log{\left(\sqrt{ \frac{\mathbb{P}(d\omega)}{\mathbb{Q}(d\omega)}}\right)}\right|}_{\leq B}q( \omega)d\nu(d\omega)$ (first part of Section D.4.2 ) $\displaystyle\leq 2B\underbrace{\int_{\omega\in\Omega}q(\omega)d\nu(d\omega)}_ {=1}\leq 2B.$ (second part of Section D.4.2 ) $$

This concludes both parts of the proof.
∎

The next lemma provides a lower bound on the softmax output if its input is upper-bounded (in $\ell_{1}$-norm).
{boxlem}
Let $\mathbf{x}\in\mathbb{R}^{m}$ be such that $\lVert\mathbf{x}\rVert_{1}\leq c_{1}$ for some $c_{1}>0$. Then, we have

$$ $\operatorname{\mathrm{softmax}}\left(\mathbf{u}\right)\geq\frac{1}{m\exp{\left (2c_{1}\right)}},$ $$

where the inequality holds for each component of $\operatorname{\mathrm{softmax}}\left(\mathbf{u}\right)$.

###### Proof.

Using the fact that

$$ $\lVert\mathbf{x}\rVert_{1}=\sum_{i=1}^{m}\lvert\mathbf{x}_{i}\rvert\leq c_{1},$ $$

we know that for any $i\in[m]$, we have

$$ $-c_{1}\leq\mathbf{x}_{i}\leq c_{1}.$ $$

Hence, using the fact that the exponential is increasing, we have for any $i\in[m]$

$$ $\exp{\left(-c_{1}\right)}\leq\exp{\left(\mathbf{x}_{i}\right)}\leq\exp{\left(c _{1}\right)}.$ (12) $$

Summing and taking the inverse leads to

$$ $\begin{split}&\sum_{i=1}^{m}\exp{\left(-c_{1}\right)}\leq\sum_{i=1}^{m}\exp{ \left(\mathbf{x}_{j}\right)}\leq\sum_{i=1}^{m}\exp{\left(c_{1}\right)}\\ \iff&\frac{1}{\sum_{j=1}^{m}\exp{\left(c_{1}\right)}}\leq\frac{1}{\sum_{j=1}^{ m}\exp{\left(\mathbf{x}_{j}\right)}}\leq\frac{1}{\sum_{j=1}^{m}\exp{\left(-c_{ 1}\right)}}.\end{split}$ (13) $$

Combining Eq. 12 and Eq. 13 yields

$$ $\frac{\exp{\left(-c_{1}\right)}}{\sum_{j=1}^{m}\exp{\left(c_{1}\right)}}\leq \frac{\exp{\left(\mathbf{x}_{i}\right)}}{\sum_{j=1}^{m}\exp{\left(\mathbf{x}_{ j}\right)}}\leq\frac{\exp{\left(c_{1}\right)}}{\sum_{j=1}^{m}\exp{\left(-c_{1} \right)}}.$ $$

As we desire a lower bound, we only focus on the left-hand side of the previous inequality. Multiplying the numerator and denominator by $\exp{(c_{1})}$ leads to

$$ $\forall i\in[m],\quad\mathrm{softmax}(\mathbf{x})_{i}=\frac{\exp{\left(\mathbf {x}_{i}\right)}}{\sum_{j=1}^{m}\exp{\left(\mathbf{x}_{j}\right)}}\geq\frac{1}{ m\exp{\left(2c_{1}\right)}},$ $$

which concludes the proof.
∎

###### Proof.

###### Proof.

##### Upper-bounding the total variation.

We now proceed with finding an upper bound on the total variation between the true probability of the next token and the one estimated by the LLM $f_{\bm{\Theta}}$. It will enable us to find the bounding vector $\mathbf{c}$. The next lemma shows that the input of the softmax layer of the model is bounded.
{boxlem}
Consider an LLM $f_{\bm{\Theta}}\in\mathcal{F}$. For any input sequence $\mathbf{S}\in\mathbb{R}^{r\times n}$, the following inequality holds

$$ $\lVert\frac{1}{n\tau}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_{n}\rVert_{1} \leq\frac{1}{\tau}\lVert\mathbf{W}_{U}^{\top}\rVert_{2,1},$ $$

where $\tau$ is the temperature, $\mathbf{W}_{U}$ is the unembedding matrix (which is bounded as stated in the definition of the parameters space $\mathcal{W}$), and $\mathbf{S}^{(L)}$ is the output of the last transformer layer.

###### Proof.

We recall that the layer normalization ensures that at each layer, the tokens are in the unit $\ell_{2}$-ball. This is, in particular, the case for the output of the last layer $\mathbf{S}^{(L)}$. It means that the columns of $\mathbf{S}^{(L)}$ verifies

$$ $\forall k\in[n],\quad\rVert\mathbf{S}^{(L)}_{\cdot,k}\lVert_{2}\leq 1,$ (14) $$

which implies

$$ $\max_{1\leq k\leq n}{\lVert\mathbf{S}^{(L)}_{\cdot,i}\rVert_{2}}\leq 1.$ (15) $$

Recalling that the $L_{p,q}$-norm of a matrix $\mathbf{A}\in\mathbb{R}^{n\times m}$ can be rewritten as

$$ $\lVert\mathbf{A}\rVert_{p,q}\coloneqq\left(\sum_{j=1}^{m}\left(\sum_{i=1}^{n} \lvert\mathbf{A}_{ij}\rvert^{p}\right)^{\frac{q}{p}}\right)^{\frac{1}{q}}= \lVert\left(\lVert\mathbf{A}_{\cdot,j}\rVert_{p}\right)_{j=1}^{m}\rVert_{q},$ (16) $$

the $\ell_{1}$-norm of the last layer before the softmax layer satisfies

$$ $\displaystyle\lVert\frac{1}{n\tau}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_{n }\rVert_{1}$ $\displaystyle=\frac{1}{n\tau}\sum_{i=1}^{T}\left|\sum_{j=1}^{r}\mathbf{W}_{ij} \sum_{k=1}^{n}\mathbf{S}_{jk}\right|=\frac{1}{n\tau}\sum_{i=1}^{T}\left|\sum_{ j=1}^{r}\sum_{k=1}^{n}\mathbf{W}_{ij}\mathbf{S}_{jk}\right|$ $\displaystyle\leq\frac{1}{n\tau}\sum_{i=1}^{T}\sum_{j=1}^{r}\sum_{k=1}^{n} \left|\mathbf{W}_{ij}\mathbf{S}_{jk}\right|$ (triangular inequality) $\displaystyle\leq\frac{1}{n\tau}\sum_{i=1}^{T}\sum_{k=1}^{n}\left|\mathbf{W}_{ i}^{\top}\mathbf{S}_{\cdot,k}\right|$ $\displaystyle\leq\frac{1}{n\tau}\sum_{i=1}^{T}\sum_{k=1}^{n}\lVert\mathbf{W}_{ i}\rVert_{2}\lVert\mathbf{S}_{\cdot,k}\rVert_{2}$ (Cauchy-Schwartz inequality) $\displaystyle\leq\frac{1}{n\tau}\sum_{i=1}^{T}\sum_{k=1}^{n}\lVert\mathbf{W}_{ i}\rVert_{2}\max_{1\leq k\leq n}{\lVert\mathbf{S}_{\cdot,k}\rVert_{2}}\leq \frac{1}{n\tau}n\max_{1\leq k\leq n}{\lVert\mathbf{S}_{\cdot,k}\rVert_{2}}\sum _{i=1}^{T}\lVert\mathbf{W}_{i}\rVert_{2}$ $\displaystyle\leq\frac{1}{\tau}\sum_{i=1}^{T}\lVert\mathbf{W}_{i}\rVert_{2} \leq\frac{1}{\tau}\lVert\mathbf{W}_{U}^{\top}\rVert_{2,1}$ (by Eq. 15 and the def. of $L_{2,1}$ in Eq. 16 ) $$

where we dropped the subscript and superscript on $\mathbf{W}_{U}$ and $\mathbf{S}^{(L)}$ to ease the notations. This concludes the proof.
∎

The previous lemma can be used to show that the logarithm of the ratio between the true probability of the next token and the one estimated by the LLM $f_{\bm{\Theta}}$ is upper bounded as a function of the vocabulary size $T$, the temperature, the upper-bound on $\mathbf{W}_{U}$ and some constant related to the ambiguity of language (see Eq. 1).

[Upper-bound on the logarithm]
Consider an LLM $f_{\bm{\Theta}}\in\mathcal{F}$ with vocabulary size $T$. We recall that $B_{U}$ is the upper bound on the norm of $\mathbf{W}_{U}$ in the definition of parameter space $\mathcal{W}$, $\tau$ is the softmax temperature and $c_{0}$ is the constant related to the ambiguity of language (see Eq. 1). We have

$$ $\forall n\in[N],\quad\left|\log{\left(\frac{\mathbb{P}_{\mathcal{L}}\left( \mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)}{\mathbb{P}_{\bm{\Theta}}\left( \mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)}\right)}\right|\leq\bar{B}=\max\{ \log{(T)}+\frac{2B_{U}}{\tau},\log{\left(\frac{1}{c_{0}}\right)}\}.$ $$

###### Proof.

The main idea of the proof is to bound the probability ratio and use the fact that $\log$ is non-decreasing. Let $n\in[N]$. The model $f_{\bm{\Theta}}$ receives as input sequences of tokens $\mathbf{S}_{n}$ of size $n\leq K$. We first lower-bound each term of the probability ratio. From Eq. 1, we have

$$ $\mathbb{P}_{\mathcal{L}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)\geq c_ {0}.$ (17) $$

We want to obtain a similar inequality for $\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)$. As the parameters $\bm{\Theta}$ of the LLM are in $\mathcal{W}$, we know that $\lVert\mathbf{W}_{U}^{\top}\rVert_{2,1}\leq B_{U}$. Section D.4.2 ensures that

$$ $\lVert\frac{1}{n\tau}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_{n}\rVert_{1} \leq\frac{1}{\tau}\lVert\mathbf{W}_{U}^{\top}\rVert_{2,1}\leq\frac{B_{U}}{\tau}.$ $$

We can then apply Section D.4.2 with $c_{1}=\frac{B_{U}}{\tau}$ and given that $\frac{1}{n\tau}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_{n}\in\mathbb{R}^{T}$, it leads to

$$ $\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}_{n}\right)=\operatorname{ \mathrm{softmax}}\left(\frac{1}{n\tau}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1 }_{n}\right)\geq\frac{1}{T\exp{(2B_{U}/\tau)}},$ $$

where the inequality holds for each component of $\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}_{n}\right)$. This is in particular the case for $\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)$ which is the entry we are interested in, i.e., we have

$$ $\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)\geq \frac{1}{T\exp{(2B_{U}/\tau)}}.$ (18) $$

Going back to the ratio of probability, consider the situation where we have

$$ $\frac{\mathbb{P}_{\mathcal{L}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)} {\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)}\geq 1.$ $$

Then, using Eq. 18, we have

$$ $1\leq\frac{\mathbb{P}_{\mathcal{L}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n} \right)}{\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n} \right)}\leq\frac{1}{\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf {S}_{n}\right)}\leq T\exp{(2B_{U}/\tau)},$ $$

which implies, as the $\log$ is non-decreasing monotonically,

$$ $0\leq\log{\left(\frac{\mathbb{P}_{\mathcal{L}}\left(\mathbf{X}_{n+1}\mid \mathbf{S}_{n}\right)}{\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid \mathbf{S}_{n}\right)}\right)}\leq\log{(T\exp{(2B_{U}/\tau)})}=\log{(T)}+\frac {2B_{U}}{\tau}.$ (19) $$

Similarly, consider the case where we have

$$ $\frac{\mathbb{P}_{\mathcal{L}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)} {\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)}\leq 1.$ $$

Then, we have

$$ $\frac{\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)} {\mathbb{P}_{\mathcal{L}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)}\geq 1,$ $$

and similarly to above, we can use Eq. 17 to obtain

$$ $1\leq\frac{\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n} \right)}{\mathbb{P}_{\mathcal{L}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n} \right)}\leq\frac{1}{\mathbb{P}_{\mathcal{L}}\left(\mathbf{X}_{n+1}\mid\mathbf {S}_{n}\right)}\leq\frac{1}{c_{0}}.$ $$

This implies

$$ $0\leq\log{\left(\frac{\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid \mathbf{S}_{n}\right)}{\mathbb{P}_{\mathcal{L}}\left(\mathbf{X}_{n+1}\mid \mathbf{S}_{n}\right)}\right)}\leq\log{\left(\frac{1}{c_{0}}\right)},$ $$

which also rewrites

$$ $0\leq-\log{\left(\frac{\mathbb{P}_{\mathcal{L}}\left(\mathbf{X}_{n+1}\mid \mathbf{S}_{n}\right)}{\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid \mathbf{S}_{n}\right)}\right)}\leq\log{\left(\frac{1}{c_{0}}\right)}.$ (20) $$

By definition of the absolute value, combining Eqs. 19 and 20 leads to

$$ $\left|\log{\left(\frac{\mathbb{P}_{\mathcal{L}}\left(\mathbf{X}_{n+1}\mid \mathbf{S}_{n}\right)}{\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid \mathbf{S}_{n}\right)}\right)}\right|\leq\max\{\log{(T)}+\frac{2B_{U}}{\tau}, \log{\left(\frac{1}{c_{0}}\right)}\}.$ $$

This concludes the proof.
∎

We are now ready to upper-bound the total variation.

[Upper-bound on the total variation]
Consider an LLM $f_{\bm{\Theta}}\in\mathcal{F}$ with vocabulary size $T$. We recall that $B_{U}$ is the upper bound on the norm of $\mathbf{W}_{U}$ in the definition of parameter space $\mathcal{W}$, $\tau$ is the softmax temperature and $c_{0}$ is the constant related to the ambiguity of language (see Eq. 1). For $n\in[N]$, we have

$$ $d_{\mathrm{TV}}\left(\mathbb{P}_{\mathcal{L}}\left(\cdot\mid\mathbf{S}_{n} \right),\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}_{n}\right)\right) \leq\sqrt{2\max\{\log{(T)}+\frac{2B_{U}}{\tau},\log{\left(\frac{1}{c_{0}} \right)}\}}\coloneqq c_{2}.$ (21) $$

###### Proof.

Using Section D.4.2, we can directly apply Section D.4.2 with $B=\max\{\log{(T)}+\frac{2B_{U}}{\tau},\log{\left(\frac{1}{c_{0}}\right)}\}$ for any $n\in[N]$. This leads to

$$ $\forall n\in[N],\quad d_{\mathrm{TV}}\left(\mathbb{P}_{\mathcal{L}}\left(\cdot \mid\mathbf{S}_{n}\right),\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}_{n }\right)\right)\leq\sqrt{2\max\{\log{(T)}+\frac{2B_{U}}{\tau},\log{\left(\frac {1}{c_{0}}\right)}\}}.$ $$

This concludes the proof.
∎

###### Proof.

###### Proof.

###### Proof.

#### D.4.3 Concluding the Proof

We are now ready to state our main result.

[Restatement of Section 4.1]
Consider an LLM $f_{\bm{\Theta}}\in\mathcal{F}$ with vocabulary size $T$. We denote by $\bm{\Gamma}$ the mixing matrix of the pretraining sequences of tokens $\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N_{\mathrm{train}}}\right)$. Let $\delta>0$. Then, with probability at least $1-\delta$,

$$ $\mathcal{R}_{\mathrm{pre}}\left(\bm{\Theta}\right)\leq\widehat{\mathcal{R}}_{ \mathrm{pre}}\left(\bm{\Theta}\right)+\frac{\bar{B}}{\sqrt{N_{\mathrm{train}}} }\sqrt{\log{\left(\frac{2}{\delta}\right)}},$ $$

where $\bar{B}$ is a constant depending on the parameters of the problem. More precisely,

$$ $\bar{B}=2\lVert\bm{\Gamma}\rVert\sqrt{\max\{\log{(T)}+\frac{2B_{U}}{\tau},\log {\left(\frac{1}{c_{0}}\right)}\}}.$ $$

###### Proof of Section 4.1 .

By definition of the risk, we have

$$ $\displaystyle\widehat{\mathcal{R}}_{\mathrm{pre}}\left(\bm{\Theta}\right)$ $\displaystyle=\frac{1}{N_{\mathrm{train}}}\sum_{n=1}^{N_{\mathrm{train}}} \underbrace{d_{\mathrm{TV}}\left(\mathbb{P}_{\mathcal{L}}\left(\cdot\mid \mathbf{S}_{n}\right),\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}_{n} \right)\right)}_{=g_{n}\left(\mathbf{S}_{n}\right)}=\frac{1}{N_{\mathrm{train} }}\sum_{n=1}^{N_{\mathrm{train}}}g_{n}\left(\mathbf{S}_{n}\right)$ $\displaystyle=f\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N_{\mathrm{train}}} \right)=f\left(S\right).$ $$

Using Section D.4.2, we know that

$$ $\lvert g_{n}\left(\mathbf{S}_{n}\right)\rvert\leq\sqrt{2\max\{\log{(T)}+\frac{ 2B_{U}}{\tau},\log{\left(\frac{1}{c_{0}}\right)}\}}\coloneqq c_{2}.$ $$

By definition, each sequence of tokens $\mathbf{S}_{n}$ takes its values in $\mathcal{V}^{n}$ (again by abuse of notation, $n=\min\{n,K\}$) and $S$ takes its values in $\mathcal{V}^{1}\times\ldots\times\mathcal{V}^{N_{\mathrm{train}}}$.
For any two sequences $\zeta,\Sigma$ with values in $\mathcal{V}^{1}\times\ldots\times\mathcal{V}^{N_{\mathrm{train}}}$,
we have

$$ $\displaystyle f\left(\zeta\right)-f\left(\Sigma\right)$ $\displaystyle=\frac{1}{N_{\mathrm{train}}}\sum_{n=1}^{N_{\mathrm{train}}}\left (\underbrace{d_{\mathrm{TV}}\left(\mathbb{P}_{\mathcal{L}}\left(\cdot\mid\bm{ \zeta}_{n}\right),\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\bm{\zeta}_{n}\right) \right)}_{=g_{n}\left(\bm{\zeta}_{n}\right)}-\underbrace{d_{\mathrm{TV}}\left( \mathbb{P}_{\mathcal{L}}\left(\cdot\mid\bm{\Sigma}_{n}\right),\mathbb{P}_{\bm{ \Theta}}\left(\cdot\mid\bm{\Sigma}_{n}\right)\right)}_{=g_{n}\left(\bm{\Sigma} _{n}\right)}\right)$ $\displaystyle=\frac{1}{N_{\mathrm{train}}}\sum_{n=1}^{N_{\mathrm{train}}}\left (g_{n}\left(\bm{\zeta}_{n}\right)-g_{n}\left(\bm{\Sigma}_{n}\right)\right)$ $\displaystyle=\frac{1}{N_{\mathrm{train}}}\sum_{n=1}^{N_{\mathrm{train}}}\left (g_{n}\left(\bm{\zeta}_{n}\right)-g_{n}\left(\bm{\Sigma}_{n}\right)\right) \mathbbm{1}_{\{\bm{\zeta}_{n}\neq\bm{\Sigma}_{n}\}}$ (removing the zero terms) $\displaystyle\leq\left|\frac{1}{N_{\mathrm{train}}}\sum_{n=1}^{N_{\mathrm{ train}}}\left(g_{n}\left(\bm{\zeta}_{n}\right)-g_{n}\left(\bm{\Sigma}_{n} \right)\right)\mathbbm{1}_{\{\bm{\zeta}_{n}\neq\bm{\Sigma}_{n}\}}\right|$ $\displaystyle\leq\frac{1}{N_{\mathrm{train}}}\sum_{n=1}^{N_{\mathrm{train}}} \left|\left(g_{n}\left(\bm{\zeta}_{n}\right)-g_{n}\left(\bm{\Sigma}_{n}\right) \right)\mathbbm{1}_{\{\bm{\zeta}_{n}\neq\bm{\Sigma}_{n}\}}\right|$ $\displaystyle\leq\frac{1}{N_{\mathrm{train}}}\sum_{n=1}^{N_{\mathrm{train}}} \left|g_{n}\left(\bm{\zeta}_{n}\right)-g_{n}\left(\bm{\Sigma}_{n}\right)\right |\mathbbm{1}_{\{\bm{\zeta}_{n}\neq\bm{\Sigma}_{n}\}}$ $\displaystyle\leq\frac{1}{N_{\mathrm{train}}}\sum_{n=1}^{N_{\mathrm{train}}} \left(\underbrace{\left|g_{n}\left(\bm{\zeta}_{n}\right)\right|}_{\leq c_{2}}+ \underbrace{\left|g_{n}\left(\bm{\Sigma}_{n}\right)\right|}_{\leq c_{2}}\right )\mathbbm{1}_{\{\bm{\zeta}_{n}\neq\bm{\Sigma}_{n}\}}$ ( Section D.4.2 ) $\displaystyle\leq\frac{1}{N_{\mathrm{train}}}\sum_{n=1}^{N_{\mathrm{train}}}2c _{2}\mathbbm{1}_{\{\bm{\zeta}_{n}\neq\bm{\Sigma}_{n}\}}=\sum_{n=1}^{N_{\mathrm {train}}}\left(\frac{2c_{2}}{N_{\mathrm{train}}}\right)\mathbbm{1}_{\{\bm{ \zeta}_{n}\neq\bm{\Sigma}_{n}\}},$ $$

where $c_{2}=\sqrt{2\max\{\log{(T)}+\frac{2B_{U}}{\tau},\log{\left(\frac{1}{c_{0}}
\right)}\}}$. As $\zeta$ and $\Sigma$ were taken arbitrary, choosing $\mathbf{c}\in\mathbb{R}^{N_{\mathrm{train}}}$ with all entries equal to $\frac{2c_{2}}{N_{\mathrm{train}}}$ ensures that $f$ verifies the condition in Section D.4.1, i.e.,

$$ $\forall\zeta,\Sigma,\quad f(\zeta)-f(\Sigma)\leq\sum_{n=1}^{N_{\mathrm{train}} }\mathbf{c}_{n}\mathbbm{1}_{\{\bm{\zeta}_{n}\neq\bm{\Sigma}_{n}\}}.$ $$

We assumed in Section 4.1 that the sequences $\mathbf{S}_{n}$ were related via a Marton coupling with mixing matrix $\bm{\Gamma}$. Putting everything together, we can apply Section D.4.1 which leads to

$$ $\forall u\geq 0,\quad\mathbb{P}\left(\lvert f(S)-\mathbb{E}_{S}\left[f(S) \right]\rvert\geq u\right)\leq 2\exp{\left(\frac{-2u^{2}}{\lVert\bm{\Gamma} \rVert^{2}\lVert\mathbf{c}\rVert_{2}^{2}}\right)}.$ (22) $$

Let $u\geq 0$. We have the following events ordering

$$ $\displaystyle\left(\mathbb{E}_{S}\left[f(S)\right]-f(S)\geq u\right)$ $\displaystyle\subseteq\left(\mathbb{E}_{S}\left[f(S)\right]-f(S)\geq u\right) \cup\left(f(S)-\mathbb{E}_{S}\left[f(S)\right]\geq u\right)$ $\displaystyle=\left(\left|f(S)-\mathbb{E}_{S}\left[f(S)\right]\right|\geq u \right).$ $$

Hence, as $u$ was taken arbitrary and using Eq. 22, we have

$$ $\forall u\geq 0,\quad\mathbb{P}\left(\mathbb{E}_{S}\left[f(S)\right]-f(S)\geq u \right)\leq 2\exp{\left(\frac{-2u^{2}}{\lVert\bm{\Gamma}\rVert^{2}\lVert \mathbf{c}\rVert_{2}^{2}}\right)}.$ $$

We recall that by definition

$$ $f(S)=\widehat{\mathcal{R}}_{\mathrm{pre}}\left(\bm{\Theta}\right)\text{ and } \mathcal{R}_{\mathrm{pre}}\left(\bm{\Theta}\right)=\mathbb{E}_{S}\left[ \widehat{\mathcal{R}}_{\mathrm{pre}}\left(\bm{\Theta}\right)\right].$ $$

Since the previous inequality holds for any $u\geq 0$, we can hence choose $u$ such that

$$ $\displaystyle\delta=2\exp{\left(\frac{-2u^{2}}{\lVert\bm{\Gamma}\rVert^{2} \lVert\mathbf{c}\rVert_{2}^{2}}\right)}$ $\displaystyle\iff\frac{-2u^{2}}{\lVert\bm{\Gamma}\rVert^{2}\lVert\mathbf{c} \rVert_{2}^{2}}=\log{\left(\frac{\delta}{2}\right)}\iff u^{2}=\frac{1}{2} \lVert\bm{\Gamma}\rVert^{2}\lVert\mathbf{c}\rVert_{2}^{2}\log{\left(\frac{2}{ \delta}\right)}$ $\displaystyle\iff u=\frac{1}{\sqrt{2}}\lVert\bm{\Gamma}\rVert\lVert\mathbf{c} \rVert_{2}\sqrt{\log{\left(\frac{2}{\delta}\right)}}.$ $$

Using the fact that

$$ $\lVert\mathbf{c}\rVert_{2}=\sqrt{\sum_{n=1}^{N_{\mathrm{train}}}\mathbf{c}_{n} ^{2}}=\sqrt{\sum_{n=1}^{N_{\mathrm{train}}}\left(\frac{2c_{2}}{N_{\mathrm{ train}}}\right)^{2}}=\sqrt{\sum_{n=1}^{N_{\mathrm{train}}}\frac{4c_{2}^{2}}{N_ {\mathrm{train}}^{2}}}=\sqrt{\frac{4c_{2}^{2}}{N_{\mathrm{train}}}}=\frac{2c_{ 2}}{\sqrt{N_{\mathrm{train}}}}$ $$

and using the fact that $c_{2}=\sqrt{2\max\{\log{(T)}+\frac{2B_{U}}{\tau},\log{\left(\frac{1}{c_{0}}
\right)}\}}$ from Section D.4.2, we obtain

$$ $\displaystyle u$ $\displaystyle=\frac{1}{\sqrt{2}}\frac{2c_{2}}{\sqrt{N_{\mathrm{train}}}}\lVert \bm{\Gamma}\rVert\sqrt{\log{\left(\frac{2}{\delta}\right)}}=\frac{\sqrt{2}c_{2 }}{\sqrt{N_{\mathrm{train}}}}\lVert\bm{\Gamma}\rVert\sqrt{\log{\left(\frac{2}{ \delta}\right)}}$ $\displaystyle=\frac{2\lVert\bm{\Gamma}\rVert\sqrt{\max\{\log{(T)}+\frac{2B_{U} }{\tau},\log{\left(\frac{1}{c_{0}}\right)}\}}}{\sqrt{N_{\mathrm{train}}}}\sqrt {\log{\left(\frac{2}{\delta}\right)}}=\frac{\bar{B}}{\sqrt{N_{\mathrm{train}}} }\sqrt{\log{\left(\frac{2}{\delta}\right)}},$ $$

where we define

$$ $\bar{B}=2\lVert\bm{\Gamma}\rVert\sqrt{\max\{\log{(T)}+\frac{2B_{U}}{\tau},\log {\left(\frac{1}{c_{0}}\right)}\}}.$ $$

Putting everything together, we have

$$ $\mathbb{P}\left(\mathcal{R}_{\mathrm{pre}}\left(\bm{\Theta}\right)-\widehat{ \mathcal{R}}_{\mathrm{pre}}\left(\bm{\Theta}\right)\geq\frac{\bar{B}}{\sqrt{N_ {\mathrm{train}}}}\sqrt{\log{\left(\frac{2}{\delta}\right)}}\right)\leq\delta.$ $$

Taking the opposite event leads to the following inequality with probability at least $1-\delta$

$$ $\mathcal{R}_{\mathrm{pre}}\left(\bm{\Theta}\right)\leq\widehat{\mathcal{R}}_{ \mathrm{pre}}\left(\bm{\Theta}\right)+\frac{\bar{B}}{\sqrt{N_{\mathrm{train}}} }\sqrt{\log{\left(\frac{2}{\delta}\right)}},$ $$

which concludes the proof.
∎

###### Proof of Section 4.1 .

### D.5 Proof of Section 4.1

As the layer norm is not applied anymore, each token is no longer in the $\ell_{2}$-unit ball, and Section D.4.2 does not hold anymore. We want to provide an analogous lemma for our setting. We first prove the following technical lemmas.
{boxlem}
The $\mathrm{ReLU}$ is a norm-decreasing operator, i.e., we have

$$ $\forall\mathbf{A}\in\mathbb{R}^{n\times m},\quad\lVert\mathrm{ReLU}\left( \mathbf{A}\right)\rVert_{1,1}\leq\lVert\mathbf{A}\rVert_{1,1},$ $$

where the $\mathrm{ReLU}$ is applied entry-wise.

###### Proof.

Recalling that $\mathrm{ReLU}(x)=\max\{0,x\}$ is applied entry-wise, using the fact that $\lvert\max\{0,x\}\rvert\leq\lvert x\rvert$ and considering $\mathbf{A}$ and $\tilde{\mathbf{A}}=\mathrm{ReLU}\left(\mathbf{A}\right)$, we have

$$ $\lVert\tilde{\mathbf{A}}\rVert_{1,1}=\sum_{i,j}\lvert\tilde{\mathbf{A}}_{i,j} \rvert=\sum_{i,j}\lvert\max\{0,\tilde{\mathbf{A}}_{i,j}\}\rvert\leq\sum_{i,j} \lvert\mathbf{A}_{i,j}\rvert\leq\lVert\mathbf{A}\rVert_{1,1},$ $$

which concludes the proof.
∎

The $L_{1,1}$-norm verifies the following property:

$$ $\forall\mathbf{A}\in\mathbb{R}^{n\times m},\mathbf{B}\in\mathbb{R}^{m\times p} ,\quad\lVert\mathbf{AB}\rVert_{1,1}\leq n\lVert\mathbf{A}\rVert_{\infty}\lVert \mathbf{B}\rVert_{1,1}.$ $$

###### Proof.

We have

$$ $\displaystyle\lVert\mathbf{AB}\rVert_{1,1}$ $\displaystyle=\sum_{j=1}^{p}\sum_{i=1}^{n}\lvert\left(\mathbf{AB}\right)_{ij} \rvert=\sum_{j=1}^{p}\sum_{i=1}^{n}\lvert\sum_{k=1}^{m}\mathbf{A}_{ik}\mathbf{ B}_{kj}\rvert\leq\sum_{j=1}^{p}\sum_{i=1}^{n}\sum_{k=1}^{m}\lvert\mathbf{A}_{ ik}\mathbf{B}_{kj}\rvert$ $\displaystyle\leq\sum_{j=1}^{p}\sum_{i=1}^{n}\sum_{k=1}^{m}\lvert\mathbf{A}_{ ik}\rvert\lvert\mathbf{B}_{kj}\rvert\leq\max_{ik}\lvert\mathbf{A}_{ik}\rvert \sum_{j=1}^{p}\sum_{i=1}^{n}\sum_{k=1}^{m}\lvert\mathbf{B}_{kj}\rvert$ $\displaystyle\leq n\lVert\mathbf{A}\rVert_{\infty}\sum_{j=1}^{p}\sum_{k=1}^{m} \lvert\mathbf{B}_{kj}\rvert\leq n\lVert\mathbf{A}\rVert_{\infty}\lVert\mathbf{ B}\rVert_{1,1},$ $$

which concludes the proof.
∎

The $L_{2,1}$ and $L_{\infty,1}$-norms verify the following relation

$$ $\forall\mathbf{A}\in\mathbb{R}^{n\times m},\quad\lVert\mathbf{A}\rVert_{\infty ,1}\leq\lVert\mathbf{A}\rVert_{2,1}.$ $$

###### Proof.

By definition of the $L_{p,q}$-norm, we have

$$ $\displaystyle\lVert\mathbf{A}\rVert_{\infty,1}$ $\displaystyle=\sum_{j=1}^{M}\max_{1\leq i\leq n}\lvert\mathbf{A}_{ij}\rvert= \sum_{j=1}^{M}\sqrt{\max_{1\leq i\leq n}\lvert\mathbf{A}_{ij}^{2}}\rvert$ (as $x\to x^{2}$ is increasing) $\displaystyle\leq\sum_{j=1}^{M}\sqrt{\sum_{i=1}^{n}\lvert\mathbf{A}_{ij}^{2}} \rvert\leq\sum_{j=1}^{M}\lVert\mathbf{A}_{\cdot,j}\rVert_{2}\leq\lVert\mathbf{ A}\rVert_{2,1},$ $$

where the first inequality comes from adding non-negative terms.
∎

We are now ready to state the lemma analogous to Section D.4.2.
{boxlem}
Consider an LLM $f_{\bm{\Theta}}\in\tilde{F}$ with $L$ layers. For any input sequence $\mathbf{S}\in\mathbb{R}^{r\times n}$, the following inequality holds

$$ $\lVert\frac{1}{n\tau}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_{n}\rVert_{1} \leq\frac{c_{3}}{\tau}\lVert\mathbf{W}_{U}^{\top}\rVert_{2,1},$ $$

where $\tau$ is the temperature and $c_{3}$ is a constant depending on the parameters upper-bound. More precisely,

$$ $c_{3}=\left[\left(1+rmB_{1}B_{2}\right)\cdot\left(1+\frac{r^{3}}{H}B_{O}B_{V} \right)\right]^{L}\cdot B_{\mathrm{tok}}.$ $$

$\mathbf{W}_{U}$ is the unembedding matrix (which is bounded as stated in the definition of the parameters space $\mathcal{W}$), and $\mathbf{S}^{(L)}$ is the output of the last transformer layer.

###### Proof of Section D.5 .

Our model $f_{\bm{\Theta}}\in\tilde{\mathcal{F}}$ is given as input a sequence $\mathbf{S}\in\mathbb{R}^{r\times n}$. With similar computations than in Section D.4.2, we have

$$ $\displaystyle\frac{1}{n\tau}\lVert\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_{n }\rVert_{1}$ $\displaystyle=\frac{1}{n\tau}\sum_{i=1}^{T}\left|\sum_{j=1}^{r}\mathbf{W}_{ij} \sum_{k=1}^{n}\mathbf{S}_{jk}\right|=\frac{1}{n\tau}\sum_{i=1}^{T}\left|\sum_{ j=1}^{r}\sum_{k=1}^{n}\mathbf{W}_{ij}\mathbf{S}_{jk}\right|$ $\displaystyle\leq\frac{1}{n\tau}\sum_{i=1}^{T}\sum_{j=1}^{r}\sum_{k=1}^{n} \left|\mathbf{W}_{ij}\mathbf{S}_{jk}\right|$ (triangular inequality) $\displaystyle\leq\frac{1}{n\tau}\sum_{i=1}^{T}\sum_{k=1}^{n}\left|\mathbf{W}_{ i}^{\top}\mathbf{S}_{\cdot,k}\right|\leq\frac{1}{n\tau}\sum_{i=1}^{T}\sum_{k=1 }^{n}\lVert\mathbf{W}_{i}\rVert_{\infty}\lVert\mathbf{S}_{\cdot,k}\rVert_{1}$ $\displaystyle\leq\frac{1}{n\tau}\left(\sum_{i=1}^{T}\lVert\mathbf{W}_{i}\rVert _{\infty}\right)\cdot\left(\sum_{k=1}^{n}\lVert\mathbf{S}_{\cdot,k}\rVert_{1} \right)\leq\frac{1}{n\tau}\lVert\mathbf{W}_{U}^{\top}\rVert_{\infty,1}\lVert \mathbf{S}^{(L)}\rVert_{1,1}$ $\displaystyle\leq\frac{1}{n\tau}\lVert\mathbf{W}_{U}^{\top}\rVert_{2,1}\lVert \mathbf{S}^{(L)}\rVert_{1,1},$ ( Section D.5 ) $$

where, again, we dropped the subscript and superscript on $\mathbf{W}_{U}$ and $\mathbf{S}^{(L)}$ to ease the notations. We obtain

$$ $\lVert\frac{1}{n\tau}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_{n}\rVert_{1} \leq\frac{1}{n\tau}\lVert\mathbf{W}_{U}^{\top}\rVert_{2,1}\lVert\mathbf{S}^{(L )}\rVert_{1,1}.$ (23) $$

As we do not use layer normalization, we want to find another way to bound $\mathbf{S}^{(L)}$. To that end, we will first express $\mathbf{S}^{(\ell)}$, the output of the $(\ell)$-th layer of the transformer, as a function of $\mathbf{S}^{(\ell-1)}$, the output of the $(\ell-1)$-th layer. Using the definition of the transformer model (see Appendix B), we have

$$ $\begin{cases}&\mathbf{Z}^{(\ell)}=\mathbf{S}^{(\ell-1)}+\mathcal{A}\left( \mathbf{S}^{(\ell-1)};\mathbf{W}_{Q}^{(\ell)},\mathbf{W}_{K}^{(\ell)},\mathbf{ W}_{V}^{(\ell)},\mathbf{W}_{O}^{(\ell)}\right),\\ &\mathbf{Y}^{(\ell)}=\mathbf{W}_{2}^{(\ell)}\operatorname{\mathrm{ReLU}}\left( \mathbf{W}_{1}^{(\ell)}\mathbf{Z}^{(\ell)}\right),\\ &\mathbf{S}^{(\ell)}=\mathbf{Z}^{(\ell)}+\mathbf{Y}^{(\ell)}.\end{cases}$ $$

We will compute each layer’s $L_{1,1}$-norm.

Step 1: MHA. By definition, denoting the number of heads by $H$, we know that $\mathcal{A}\left(\mathbf{S}^{(\ell-1)};\mathbf{W}_{Q}^{(\ell)},\mathbf{W}_{K}^
{(\ell)},\mathbf{W}_{V}^{(\ell)},\mathbf{W}_{O}^{(\ell)}\right)\in\mathbb{R}^{
r\times n}$ multiplies $\mathbf{W}^{(\ell)}\in\mathbb{R}^{r\times r}$ with the concatenation on the rows of the $H$ softmax layers that each writes

$$ $\operatorname{\mathrm{softmax}}\left(\mathbf{W}^{(\ell)}_{Q}\mathbf{S}^{(\ell) }\left(\mathbf{W}^{(\ell)}_{K}\mathbf{S}^{(\ell-1)}\right)^{\top}/\sqrt{r} \right)\left(\mathbf{W}^{(\ell)}_{V}\mathbf{S}^{(\ell-1)}\right)\in\mathbb{R}^ {\frac{r}{H}\times n},$ $$

We keep the notations $\ell$ without explicating the index of the head to ease notations. Denoting the concatenation on the rows by $\mathbf{C}^{(\ell)}\in\mathbb{R}^{r\times n}$, we have

$$ $\displaystyle\lVert\mathcal{A}\left(\mathbf{S}^{(\ell-1)};\mathbf{W}_{Q}^{( \ell)},\mathbf{W}_{K}^{(\ell)},\mathbf{W}_{V}^{(\ell)},\mathbf{W}_{O}^{(\ell)} \right)\rVert_{1,1}$ $\displaystyle=\lVert\mathbf{W}_{O}^{(\ell)}\mathbf{C}^{(\ell)}\rVert_{1,1}\leq r \cdot\lVert\mathbf{W}_{O}^{(\ell)}\rVert_{\infty}\lVert\mathbf{C}^{(\ell)} \rVert_{1,1}$ $\displaystyle\leq rB_{O}\lVert\mathbf{C}^{(\ell)}\rVert_{1,1}.$ (definition of $\tilde{\mathcal{W}}$ ) $$

Moreover, by definition of $\mathbf{C}^{(\ell)}$, we have

$$ $\lVert\mathbf{C}^{(\ell)}\rVert_{1,1}=\sum_{j=1}^{r}\sum_{i=1}^{r}\lvert \mathbf{C}^{(\ell)}_{ij}\rvert=\sum_{j=1}^{r}\sum_{i=1}^{r/H}\sum_{h=1}^{H} \lvert\mathbf{C}^{(\ell,h)}_{ij}\rvert=\sum_{h=1}^{H}\lVert\mathbf{C}^{(\ell,h )}\rVert_{1,1},$ (24) $$

where $\mathbf{C}^{(\ell,h)}\in\mathbb{R}^{\frac{r}{H}\times n}$ is the softmax matrix of the $h$-th layer. We recall that the softmax matrix is a row-stochastic matrix of $\mathbb{R}^{\frac{r}{H}\times r}$ so it has all values lower than $1$. In the next computations, we drop the $h$ index on the query, key, and value matrices to ease the notations. Using Section D.5 on the softmax matrix and on the value matrix $\mathbf{W}_{V}^{(\ell)}\in\mathbb{R}^{\frac{r}{H}\times r}$, we have

$$ $\displaystyle\lVert\mathbf{C}^{(\ell,h)}\rVert_{1,1}$ $\displaystyle=\lVert\operatorname{\mathrm{softmax}}\left(\mathbf{W}^{(\ell)}_{ Q}\mathbf{S}^{(\ell)}\left(\mathbf{W}^{(\ell)}_{K}\mathbf{S}^{(\ell-1)}\right) ^{\top}/\sqrt{r}\right)\left(\mathbf{W}^{(\ell)}_{V}\mathbf{S}^{(\ell-1)} \right)\rVert_{1,1}$ $\displaystyle\leq\frac{r}{H}\cdot\lVert\operatorname{\mathrm{softmax}}\left( \mathbf{W}^{(\ell)}_{Q}\mathbf{S}^{(\ell)}\left(\mathbf{W}^{(\ell)}_{K}\mathbf {S}^{(\ell-1)}\right)^{\top}/\sqrt{r}\right)\rVert_{\infty}\cdot\lVert\left( \mathbf{W}^{(\ell)}_{V}\mathbf{S}^{(\ell-1)}\right)\rVert_{1,1}$ $\displaystyle\leq\frac{r}{H}\cdot\lVert\left(\mathbf{W}^{(\ell)}_{V}\mathbf{S} ^{(\ell-1)}\right)\rVert_{1,1}$ (the softmax matrix is row-stochastic) $\displaystyle\leq\frac{r}{H}\cdot\frac{r}{H}\lVert(\mathbf{W}^{(\ell)}_{V} \rVert_{\infty}\lVert\mathbf{S}^{(\ell-1)}\rVert_{1,1}\leq\left(\frac{r}{H} \right)^{2}B_{V}\lVert\mathbf{S}^{(\ell-1)}\rVert_{1,1}.$ (definition of $\tilde{\mathcal{W}}$ ) $$

Combining the previous inequality with Eq. 24 leads to

$$ $\lVert\mathbf{C}^{(\ell)}\rVert_{1,1}\leq\frac{r^{2}}{H}B_{V}\lVert\mathbf{S}^ {(\ell-1)}\rVert_{1,1}.$ $$

In the end, the multi-head attention norm verifies

$$ $\lVert\mathcal{A}\left(\mathbf{S}^{(\ell-1)};\mathbf{W}_{Q}^{(\ell)},\mathbf{W }_{K}^{(\ell)},\mathbf{W}_{V}^{(\ell)},\mathbf{W}_{O}^{(\ell)}\right)\rVert_{1 ,1}\leq\frac{r^{3}}{H}B_{O}B_{V}\lVert\mathbf{S}^{(\ell-1)}\rVert_{1,1}.$ $$

Using the triangular inequality, we obtain

$$ $\lVert\mathbf{Z}^{(\ell)}\rVert_{1,1}\leq\left(1+\frac{r^{3}}{H}B_{O}B_{V} \right)\cdot\lVert\mathbf{S}^{(\ell-1)}\rVert_{1,1}.$ (25) $$

Step 2: FF. We recall that $\mathbf{W}_{1}\in\mathbb{R}^{m\times r}$ and $\mathbf{W}_{2}\in\mathbb{R}^{r\times m}$. Using similar arguments to the above, we have

$$ $\displaystyle\lVert\mathbf{Y}^{(\ell)}\rVert_{1,1}$ $\displaystyle=\lVert\mathbf{W}_{2}^{(\ell)}\operatorname{\mathrm{ReLU}}\left( \mathbf{W}_{1}^{(\ell)}\mathbf{Z}^{(\ell)}\right)\rVert_{1,1}$ $\displaystyle\leq r\cdot\lVert\mathbf{W}_{2}^{(\ell)}\rVert_{\infty}\lVert \operatorname{\mathrm{ReLU}}\left(\mathbf{W}_{1}^{(\ell)}\mathbf{Z}^{(\ell)} \right)\rVert_{1,1}$ ( Section D.5 ) $\displaystyle\leq r\cdot\lVert\mathbf{W}_{2}^{(\ell)}\rVert_{\infty}\lVert \mathbf{W}_{1}^{(\ell)}\mathbf{Z}^{(\ell)}\rVert_{1,1}$ ( Section D.5 ) $\displaystyle\leq r\cdot m\cdot\lVert\mathbf{W}_{2}^{(\ell)}\rVert_{\infty} \lVert\mathbf{W}_{1}^{(\ell)}\rVert_{\infty}\lVert\mathbf{Z}^{(\ell)}\rVert_{1 ,1}$ ( Section D.5 ) $\displaystyle\leq rmB_{1}B_{2}\lVert\mathbf{Z}^{(\ell)}\rVert_{1,1}.$ (definition of $\tilde{\mathcal{W}}$ ) $$

Step 3: output layer. Again, applying the triangular inequality and using the previous inequality and Eq. 25, we have

$$ $\displaystyle\lVert\mathbf{S}^{(\ell)}\rVert_{1,1}$ $\displaystyle\leq\lVert\mathbf{Z}^{(\ell)}\rVert_{1,1}+\lVert\mathbf{Y}^{(\ell )}\rVert_{1,1}\leq\left(1+rmB_{1}B_{2}\right)\lVert\mathbf{Z}^{(\ell)}\rVert_{ 1,1}$ $\displaystyle\leq\left(1+rmB_{1}B_{2}\right)\left(1+\frac{r^{3}}{H}B_{O}B_{V} \right)\lVert\mathbf{S}^{(\ell-1)}\rVert_{1,1}.$ $$

Iterating through the layers, recalling that $\mathbf{S}^{(0)}=\mathbf{S}$, we finally obtain

$$ $\lVert\mathbf{S}^{(L)}\rVert_{1,1}\leq\left[\left(1+rmB_{1}B_{2}\right)\left(1 +\frac{r^{3}}{H}B_{O}B_{V}\right)\right]^{L}\lVert\mathbf{S}\rVert_{1,1},$ $$

where $\mathbf{S}$ is the input sequence. Combining this inequality with Eq. 23 leads to

$$ $\lVert\frac{1}{n\tau}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_{n}\rVert_{1} \leq\left[\left(1+rmB_{1}B_{2}\right)\left(1+\frac{r^{3}}{H}B_{O}B_{V}\right) \right]^{L}\frac{\lVert\mathbf{S}\rVert_{1,1}}{n}\left(\frac{1}{\tau}\lVert \mathbf{W}_{U}^{\top}\rVert_{2,1}\right).$ $$

Using the fact that each token has a $\ell_{1}$-norm bounded by $B_{\mathrm{tok}}$. Hence, each column of $\mathbf{S}$ is too and we have

$$ $\frac{1}{n}\lVert\mathbf{S}\rVert_{1,1}=\frac{1}{n}\sum_{j=1}^{n}\sum_{i=1}^{r }\rvert\mathbf{S}_{ij}\lvert=\frac{1}{n}\sum_{j=1}^{n}\underbrace{\lVert \mathbf{S}_{\cdot,j}\rVert_{1}}_{\leq B_{\mathrm{tok}}}\leq B_{\mathrm{tok}}.$ $$

Combining the last two inequalities concludes the proof.
∎

We can now restate Corollary 4.1.
{boxcor}[Restatement of Section 4.1]
Consider an LLM $f_{\bm{\Theta}}\in\tilde{\mathcal{F}}$ with vocabulary size $T$ composed of $L$ transformer blocks and $H$ attention heads. We denote by $\bm{\Gamma}$ the mixing matrix of the pretraining sequences of tokens $\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N_{\mathrm{train}}}\right)$. Let $\delta>0$. Then, with probability at least $1-\delta$,

$$ $\mathcal{R}_{\mathrm{pre}}\left(\bm{\Theta}\right)\leq\widehat{\mathcal{R}}_{ \mathrm{pre}}\left(\bm{\Theta}\right)+\frac{\bar{B}}{\sqrt{N_{\mathrm{train}}} }\sqrt{\log{\left(\frac{2}{\delta}\right)}},$ $$

where $\bar{B}$ is a constant depending on the parameters of the problem. More precisely,

$$ $\bar{B}=2\lVert\bm{\Gamma}\rVert\sqrt{\max\{\log{(T)}+\frac{2(B_{\bm{\Theta}}) ^{L}}{\tau},\log{\left(\frac{1}{c_{0}}\right)}\}},$ $$

with $B_{\bm{\Theta}}=\left[\left(1+rmB_{1}B_{2}\right)\left(1+\frac{r^{3}}{H}B_{O}B
_{V}\right)\right]\left(B_{\mathrm{tok}}B_{U}\right)^{1/L}$.

###### Proof of Section 4.1 .

We first note that the only change from Section D.4.2 to Section D.5 is the multiplicative constant $c_{3}=\left[\left(1+rmB_{1}B_{2}\right)\left(1+\frac{r^{3}}{H}B_{O}B_{V}\right
)\right]^{L}B_{\mathrm{tok}}$ in front of $\frac{1}{\tau}\lVert\mathbf{W}_{U}^{\top}\rVert_{2,1}$. In particular, as we know that $\tilde{\mathcal{W}}\subset\mathcal{W}$, we also have
$\lVert\mathbf{W}_{U}^{\top}\rVert_{2,1}\leq B_{U}$. Hence, we can apply the proof of Section 4.1 in a straightforward manner by changing $\frac{B_{U}}{\tau}$ by $c_{3}\cdot\frac{B_{U}}{\tau}$. This concludes the proof.
∎

###### Proof.

###### Proof.

###### Proof.

###### Proof of Section D.5 .

###### Proof of Section 4.1 .

### D.6 Proof of Section 4.1

We detail the proof of Section 4.1 below.

###### Proof.

We first note that by definition of the total variation distance (Wolfer & Kontorovich, ), we have

$$ $\displaystyle\mathbb{E}_{\mathbf{S}\sim\mathbb{P}_{\mathcal{L}}}\lVert\mathbf{ Q}^{*}\left(\mathbf{S},\cdot\right)-\mathbf{Q}_{f}\left(\mathbf{S},\cdot\right )\rVert_{1}$ $\displaystyle=\mathbb{E}_{\mathbf{S}\sim\mathbb{P}_{\mathcal{L}}}\left[2\cdot d _{\mathrm{TV}}\left(\mathbf{Q}^{*}\left(\mathbf{S},\cdot\right),\mathbf{Q}_{f} \left(\mathbf{S},\cdot\right)\right)\right]$ $\displaystyle=2\cdot\mathbb{E}_{\mathbf{S}\sim\mathbb{P}_{\mathcal{L}}}\left[d _{\mathrm{TV}}\left(\mathbf{Q}^{*}\left(\mathbf{S},\cdot\right),\mathbf{Q}_{f} \left(\mathbf{S},\cdot\right)\right)\right]$ $\displaystyle=2\cdot\mathcal{R}_{\mathrm{pre}}\left(\bm{\Theta}\right).$ (by definition of the risk Eq. 2 ) $$

Applying Section 4.1 (or similarly Section 4.1), we know that

$$ $\mathcal{R}_{\mathrm{pre}}\left(\bm{\Theta}\right)\leq\widehat{\mathcal{R}}_{ \mathrm{pre}}\left(\bm{\Theta}\right)+\frac{\bar{B}}{\sqrt{N_{\mathrm{train}}} }\sqrt{\log{\left(\frac{2}{\delta}\right)}},$ $$

where $\bar{B}$ is formally defined in Section 4.1 (respectively Section 4.1). Assuming a perfect pre-training error amounts to consider $\widehat{\mathcal{R}}_{\mathrm{pre}}\left(\bm{\Theta}\right)=0$. We denote by $N^{*}$ the integer such that the error is equal to $\frac{\epsilon}{2}$, i.e.,

$$ $\frac{\bar{B}}{\sqrt{N^{*}}}\sqrt{\log{\left(\frac{2}{\delta}\right)}}=\frac{ \epsilon}{2}\iff\frac{\bar{B}^{2}}{N^{*}}\log{\left(\frac{2}{\delta}\right)}= \frac{\epsilon^{2}}{4}\iff N^{*}=\left(\frac{2\bar{B}}{\epsilon}\right)^{2} \log{\left(\frac{2}{\delta}\right)}.$ $$

Taking the ceiling function ensures that $N^{*}$ is an integer. Hence, taking $N_{\mathrm{train}}\geq N^{*}=\lceil\left(\frac{2\bar{B}}{\epsilon}\right)^{2}
\log{\left(\frac{2}{\delta}\right)}\rceil$ ensures that

$$ $\displaystyle\frac{\bar{B}}{\sqrt{N_{\mathrm{train}}}}\sqrt{\log{\left(\frac{2 }{\delta}\right)}}\leq\frac{\bar{B}}{\sqrt{N^{*}}}\sqrt{\log{\left(\frac{2}{ \delta}\right)}}=\frac{\epsilon}{2}.$ $$

Putting everything together, taking $N_{\mathrm{train}}\geq N^{*}$ leads to

$$ $\mathbb{E}_{\mathbf{S}\sim\mathbb{P}_{\mathcal{L}}}\lVert\mathbf{Q}^{*}\left( \mathbf{S},\cdot\right)-\mathbf{Q}_{f}\left(\mathbf{S},\cdot\right)\rVert_{1} \leq 2\cdot\mathcal{R}_{\mathrm{pre}}\left(\bm{\Theta}\right)\leq 2\cdot\frac{ \epsilon}{2}=\epsilon,$ $$

which concludes the proof.
∎

###### Proof.

### D.7 Proof of Eq. 3

In this section, we detail the proof of Eq. 3. We first recall the problem setup.

##### Markov chains inputs.

In this section, we give as input of the model a single Markov chain $X=\left(\mathbf{X}_{1},\ldots,\mathbf{X}_{N_{\mathrm{icl}}}\right)$ with finite, discrete state space $\Omega$ of size $d$ with transition probability $\mathbb{P}$. We assume the $\mathbf{X}_{n}$ are already tokenized and thus we have $\Omega\subset\mathcal{V}$. We denote the sequence of tokens the LLM receives by $\mathbf{S}_{n}=\left(\mathbf{X}_{1},\ldots,\mathbf{X}_{n}\right)$ if $n\leq K$ and $\mathbf{S}_{n}=\left(\mathbf{X}_{n-K+1},\ldots,\mathbf{X}_{n}\right)$ otherwise due to the deletion process (see Section B.1). In particular, the $\mathbf{S}_{n}$ are elements of $\mathcal{V}^{*}_{K}$. We note that $S=\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N_{\mathrm{icl}}}\right)$ is also a Markov chain (see Section D.7.1). By definition of $\mathbb{P}$, we know that for any $n\in[N_{\mathrm{icl}}]$, the next token $\mathbf{X}_{n+1}$ follows the distribution $\mathbb{P}\left(\cdot\mid\mathbf{S}_{n}\right)$. We assume that there exists a positive constant $p_{\mathrm{min}}$ that lower bounds all the transition probability between states, i.e., $\forall n\in[N_{\mathrm{icl}}],\forall x,y\in\Omega,\quad\mathbb{P}\left(
\mathbf{X}_{n+1}=y\mid\mathbf{X}_{n}=x\right)\geq p_{\mathrm{min}}>0$. This is akin to the ambiguity of language constant $c_{0}$ considered in the previous section and in Zhang et al. (); Hu et al. (); Xie et al. (); Wies et al. ().

##### Next token probability distribution.

An important difference with the setting considered in Section 4.1 is that here, we predict a probability distribution on the state space $\Omega$ of the Markov chain and not on the vocabulary of the LLM $\mathcal{V}$. To that end, we restrict the predicted probability given the past tokens $\mathbf{S}_{n}$ to the state space $\Omega$. Formally, denoting the output of the last layer of $f_{\bm{\Theta}}$ by $\mathbf{S}^{(L)}$, the last layer before the softmax outputs a vector $\mathbf{u}=\frac{1}{n\tau}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_{n}\in
\mathbb{R}^{T}$. We first extract the entries of $\mathbf{u}$ whose index $i$ are such that the $i$-th element of the vocabulary space $\mathcal{V}$ is in $\Omega$. This can be formalized as follows. We denote by $\mathbb{I}_{d}=(i_{1}\leq i_{2}\leq\ldots\leq i_{d})\in[T]^{d}$ the subset of $d$ distinct elements of $[T]$ and consider the matrix $\mathbf{M}_{j}=\mathbf{e}_{i_{j}}^{\top}$, where $\mathbf{e}_{i_{j}}\in\mathbb{R}^{T}$ has value $1$ at entry $i_{j}\in\mathbb{I}$ and 0 0 elsewhere. Extracting only the $d$ entries of $\mathbf{u}$ that corresponds to the state space yields a vector in $\mathbb{R}^{d}$ that writes $\mathbf{v}=\frac{1}{n\tau}\mathbf{M}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_
{n}\in\mathbb{R}^{T}$. Similarly to Appendix B, the probability distribution of next token $\mathbf{X}_{n+1}$ provided by the LLM $f_{\bm{\Theta}}$ now writes

$$ $\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}_{n}\right)=\operatorname{ \mathrm{softmax}}\left(\frac{1}{n\tau}\mathbf{M}\mathbf{W}_{U}\mathbf{S}^{(L)} \mathbbm{1}_{n}\right)\in\Delta_{d}.$ $$

We aim to obtain a similar generalization bound than in Section 4.1 where the reference probability distribution is the Markov chain transition probability $\mathbb{P}$ instead of the probability distribution of language $\mathbb{P}_{\mathcal{L}}$. In particular, $\mathbb{P}$ will replace $\mathbb{P}_{\mathcal{L}}$ in the definition of the risks in Eq. 2. We provide below an overview of the proof before detailing it.

##### Overview of the proof.

We are going to use McDiarmid’s inequality for Markov chains of Paulin (, Corollary 2.11). To adapt their arguments to our setting, we bound the total variation between the true probability of the next token and the one estimated by the LLM. The rest of this section is organized as follows. First, in Section D.7.1, we show that $S=\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N_{\mathrm{icl}}}\right)$ is a Markov chain. Then in Section D.7.2, we adapt the concentration inequality of Paulin (, Corollary 2.11). Afterwards in Section D.7.3, we show how to bound the total variation between the true and the estimated probability of the next token. Finally Section D.7.4 concludes the proof.

#### D.7.1 Connection between tokens and sequences of tokens Markov chains

We first show that $S=\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N_{\mathrm{icl}}}\right)$ is also a Markov chain.

Consider a sequence (not necessarily a Markov chain) $X=\left(\mathbf{X}_{1},\ldots,\mathbf{X}_{N}\right)$ with values in $\Omega$ and let $\mathbf{S}_{n}=\left(\mathbf{X}_{1},\ldots,\mathbf{X}_{n}\right)$ if $n<K$ and $\mathbf{S}_{n}=\left(\mathbf{X}_{n-K+1},\ldots,\mathbf{X}_{n}\right)$ otherwise. Then, the sequence $S=\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N}\right)$ is a Markov chain with state space $\Omega^{*}_{K}$ that contains the sequence of elements in $\Omega$ of length smaller than $K$.

###### Proof.

By definition of the $\mathbf{S}_{n}$, we know that they take values in $\Omega^{*}_{K}$. Let $x_{1},\ldots,x_{n+1}\in\Omega$. We first assume that $n>K$ and denote $s_{i}=(x_{n-K+1},\ldots,x_{i})$.
We have

$$ $\displaystyle\mathbb{P}\left(\mathbf{S}_{n+1}=s_{n+1}\mid\mathbf{S}_{n}=s_{n}, \ldots,\mathbf{S}_{n-K+1}=s_{n-K+1}\right)$ $\displaystyle=\mathbb{P}\left(\mathbf{S}_{n+1}=s_{n+1}\mid\mathbf{X}_{n}=x_{n} ,\ldots,\mathbf{X}_{n-K+1}=x_{n-K+1}\right)$ $\displaystyle=\mathbb{P}\left(\mathbf{S}_{n+1}=s_{n+1}\mid\mathbf{S}_{n}=s_{n} \right).$ (by definition of $\mathbf{S}_{n}$ ) $$

Similarly, we assume $n<K$ and denote $s_{i}=(x_{1},\ldots,x_{i})$. We have

$$ $\displaystyle\mathbb{P}\left(\mathbf{S}_{n+1}=s_{n+1}\mid\mathbf{S}_{n}=s_{n}, \ldots,\mathbf{S}_{1}=s_{1}\right)$ $\displaystyle=\mathbb{P}\left(\mathbf{S}_{n+1}=s_{n+1}\mid\mathbf{X}_{n}=x_{n} ,\ldots,\mathbf{X}_{1}=x_{1}\right)$ $\displaystyle=\mathbb{P}\left(\mathbf{S}_{n+1}=s_{n+1}\mid\mathbf{S}_{n}=s_{n} \right).$ (by definition of $\mathbf{S}_{n}$ ) $$

Finally, for $n=K$, we denote $s_{i}=(x_{1},\ldots,x_{i})$ for $i\leq K$ and $s_{K+1}=(x_{2},\ldots,x_{K+1})$. We have

$$ $\displaystyle\mathbb{P}\left(\mathbf{S}_{K+1}=s_{K+1}\mid\mathbf{S}_{n}=s_{n}, \ldots,\mathbf{S}_{2}=s_{2}\right)$ $\displaystyle\qquad=\mathbb{P}\left(\mathbf{S}_{K+1}=s_{K+1}\mid\mathbf{X}_{K} =x_{K},\ldots,\mathbf{X}_{1}=x_{1}\right)$ $\displaystyle\qquad=\mathbb{P}\left(\mathbf{S}_{K+1}=s_{K+1}\mid\mathbf{S}_{K} =s_{K}\right).$ (by definition of $\mathbf{S}_{K}$ ) $$

This establishes the Markov property for $\mathbf{S}$.
∎

###### Proof.

#### D.7.2 Concentration Inequalities for Markov Chains

We first state a concentration inequality for time-homogeneous Markov chains that will be used to obtain our final bound.

[McDiarmid’s inequality for time-homogeneous Markov chains]
Let $S\coloneqq\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N}\right)$ be a Markov chain with value in a discrete, finite state space $\Omega$ and mixing time $t_{\mathrm{mix}}\left(\varepsilon\right)$. Let
$t_{\mathrm{min}}\coloneqq\inf_{0\leq\varepsilon<1}t_{\mathrm{mix}}\left(\frac{
\varepsilon}{2}\right)\cdot\left(\frac{2-\varepsilon}{1-\varepsilon}\right)^{2}$.
If $f\colon\Omega\to\mathbb{R}$ is such that there exists $\mathbf{c}\in\mathbb{R}^{N}$ satisfying

$$ $\forall\mathbf{x},\mathbf{y}\in\Omega,\quad f(\mathbf{x})-f(\mathbf{y})\leq \sum_{i=1}^{N}\mathbf{c}_{i}\mathbbm{1}_{\{\mathbf{x}_{i}\neq\mathbf{y}_{i}\}},$ $$

then we have for any $u\geq 0$,

$$ $\mathbb{P}\left(\lvert f(S)-\mathbb{E}_{S}\left[f(S)\right]\rvert\geq u\right) \leq 2\exp{\left(\frac{-2u^{2}}{\lVert\mathbf{c}\rVert_{2}^{2}\cdot t_{\mathrm {min}}}\right)}.$ $$

###### Proof.

We recall that Corollary 2.11 of Paulin () ensures that for such a function $f$, we have

$$ $\mathbb{P}\left(\lvert f(S)-\mathbb{E}\left[f(S)\right]\rvert\geq u\right)\leq 2 \exp{\left(\frac{-2u^{2}}{\lVert\mathbf{c}\rVert_{2}^{2}\cdot\tau_{\mathrm{min }}}\right)},$ (26) $$

where $\tau_{\mathrm{min}}$ is defined as

$$ $\tau_{\mathrm{min}}\coloneqq\inf_{0\leq\varepsilon<1}\tau(\varepsilon)\left( \frac{2-\varepsilon}{1-\varepsilon}\right)^{2},$ $$

with $\tau(\varepsilon)$ being the mixing time of a Markov chain *without assuming time homogeneity* (see Paulin (, Definition 1.4)). As in our case, we assume the time homogeneity, this inequality in Eq. 26 has to be adapted. Following Remark 1.5 of Paulin (), we notice that

$$ $\forall\varepsilon\in[0,1],\quad\tau(2\varepsilon)\leq t_{\mathrm{mix}}\left( \varepsilon\right)\leq\tau(\varepsilon).$ $$

Let $0\leq\varepsilon<1$. Using the fact that $\left(\frac{2-\varepsilon}{1-\varepsilon}\right)^{2}>0$, the previous inequality ensures

$$ $\displaystyle\tau(\varepsilon)\leq t_{\mathrm{mix}}\left(\frac{\varepsilon}{2}\right)$ $\displaystyle\iff\tau(\varepsilon)\left(\frac{2-\varepsilon}{1-\varepsilon} \right)^{2}\leq t_{\mathrm{mix}}\left(\frac{\varepsilon}{2}\right)\left(\frac{ 2-\varepsilon}{1-\varepsilon}\right)^{2}.$ $$

Taking the infimum on the left-hand side leads to

$$ $\tau_{\mathrm{min}}=\inf_{0\leq\varepsilon<1}\tau(\varepsilon)\left(\frac{2- \varepsilon}{1-\varepsilon}\right)^{2}\leq t_{\mathrm{mix}}\left(\frac{ \varepsilon}{2}\right)\left(\frac{2-\varepsilon}{1-\varepsilon}\right)^{2}.$ $$

As we took $\varepsilon$ arbitrary in $[0,1)$, we can take the infimum on the right-hand side, which leads to

$$ $\tau_{\mathrm{min}}\leq t_{\mathrm{min}}.$ $$

As the function $x\to\exp{\left(\frac{-2u^{2}}{\lVert\mathbf{c}\rVert_{2}^{2}x}\right)}$ is decreasing, we finally obtain

$$ $\exp{\left(\frac{-2u^{2}}{\lVert\mathbf{c}\rVert_{2}^{2}\tau_{\mathrm{min}}} \right)}\leq\exp{\left(\frac{-2u^{2}}{\lVert\mathbf{c}\rVert_{2}^{2}t_{\mathrm {min}}}\right)}.$ (27) $$

Combining Eqs. 26 and 27 concludes the proof.
∎

Similarly to Section 4.1, we want to apply Section D.7.2 to a function $f$ that consists of sums of total variation. We investigate in the next section how to find the bounding vector $\mathbf{c}$ to apply Section D.7.2.

###### Proof.

#### D.7.3 Finding the Bounding Vector

We want to apply the same arguments as in the proof of Section 4.1 to find the bounding vector $\mathbf{c}$. The only difference in terms of setting is the definition of the probability of the next token. Indeed, in our case, we apply an extraction matrix $\mathbf{M}\in\mathbb{R}^{d\times T}$ to recover the $d$ states of the input Markov chain. We first prove the following technical lemma.

Let $d\leq T$ and consider a subset of $d$ *distinct* elements of $[T]$ that writes $\mathbb{I}_{d}=(i_{1}\leq i_{2}\leq\ldots\leq i_{d})\in[T]^{d}$. We denote by $\mathbf{M}\in\mathbb{R}^{d\times T}$ the matrix with rows $\mathbf{M}_{j}=\mathbf{e}_{i_{j}}^{\top}$, where $\mathbf{e}_{i_{j}}\in\mathbb{R}^{T}$ has value $1$ at entry $i_{j}\in\mathbb{I}$ and 0 0 elsewhere. For any vector $\mathbf{u}\in\mathbb{R}^{T}$, we have

$$ $\lVert\mathbf{M}\mathbf{u}\rVert_{1}\leq\lVert\mathbf{u}\rVert_{1}.$ $$

###### Proof.

By definition of the $\ell_{1}$-norm, we have

$$ $\lVert\mathbf{M}\mathbf{u}\rVert_{1}=\sum_{k=1}^{d}\lvert\sum_{l=1}^{T}\mathbf {M}_{kl}\mathbf{u}_{l}\rvert\leq\sum_{k=1}^{d}\sum_{l=1}^{T}\lvert\mathbf{M}_{ kl}\mathbf{u}_{l}\rvert\leq\sum_{l=1}^{T}\lvert\mathbf{u}_{l}\rvert\sum_{k=1}^ {d}\lvert\mathbf{M}_{kl}\rvert.$ $$

Moreover, each column of $\mathbf{M}$ contains at most one non-zero entry (with value $1$). Otherwise, it means that two $\mathbf{e}_{i_{j}}$ are identical (as they only have one non-zero entry with value $1$, having it at the same position ensures their equality) which contradicts the fact that the $i_{j}$ where taken distinct. Hence, for all $l$, we have $\sum_{k=1}^{d}\lvert\mathbf{M}_{kl}\rvert\leq 1$, which concludes the proof.
∎

We now prove a lemma analogous to Section D.4.2.
{boxlem}
Let $\mathbf{S}\in\mathbb{R}^{r\times n}$ denote the entry of the LLM $f_{\bm{\Theta}}$ and $\mathbf{S}^{(L)}$ denote the output of the last layer before the softmax. Let $d\leq T$ and consider a subset of $d$ *distinct* elements of $[T]$ that writes $\mathbb{I}_{d}=(i_{1}\leq i_{2}\leq\ldots\leq i_{d})\in[T]^{d}$. We denote by $\mathbf{M}\in\mathbb{R}^{d\times T}$ the matrix with rows $\mathbf{M}_{j}=\mathbf{e}_{i_{j}}^{\top}$, where $\mathbf{e}_{i_{j}}\in\mathbb{R}^{T}$ has value $1$ at entry $i_{j}\in\mathbb{I}$ and 0 0 elsewhere. Then, the following inequality holds

$$ $\frac{1}{n\tau}\lVert\mathbf{M}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_{n} \rVert_{1}\leq\frac{1}{\tau}\lVert\mathbf{W}_{U}^{\top}\rVert_{2,1}.$ $$

###### Proof.

Applying Section D.7.3 with the matrix $\mathbf{M}\in\mathbb{R}^{d}$ and the vector $\frac{1}{n\tau}\mathbf{W}_{U}\mathbf{X}^{(L)}\mathbbm{1}_{n}\in\mathbb{R}^{T}$ leads to

$$ $\frac{1}{n\tau}\lVert\mathbf{M}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_{n} \rVert_{1}\leq\frac{1}{n\tau}\lVert\mathbf{W}_{U}\mathbf{X}^{(L)}\mathbbm{1}_{ n}\rVert_{1}.$ $$

Applying Section D.4.2 concludes the proof.
∎

The previous lemma can be used to show that the logarithm of the ratio between the true probability of the next token and the one estimated by the LLM $f_{\bm{\Theta}}$ is upper bounded as a function of the number of states of the Markov chain $d$, the temperature $\tau$, the upper-bound on $\mathbf{W}_{U}$ and some constant related to the ambiguity of language (see Eq. 1).

[Upper-bound on the logarithm]
Consider an LLM $f_{\bm{\Theta}}\in\mathcal{F}$ and an input Markov chain $X=\left(\mathbf{X}_{1},\ldots,\mathbf{X}_{N_{\mathrm{icl}}}\right)$ with $d$ states. We recall that $B_{U}$ is the upper bound on the norm of $\mathbf{W}_{U}$ in the definition of parameter space $\mathcal{W}$, $\tau$ is the softmax temperature, and $p_{\mathrm{min}}$ is the constant related to the minimal transition probability between states. We have

$$ $\forall n\in[N],\quad\left|\log{\left(\frac{\mathbb{P}\left(\mathbf{X}_{n+1} \mid\mathbf{S}_{n}\right)}{\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid \mathbf{S}_{n}\right)}\right)}\right|\leq\bar{B}=\max\{\log{(d)}+\frac{2B_{U}} {\tau},\log{\left(\frac{1}{p_{\mathrm{min}}}\right)}\}.$ $$

###### Proof.

The main idea of the proof is to bound the probability ratio and use the non-decreasing monotonicity of the $\log$. Let $n\in[N]$. The model $f_{\bm{\Theta}}$ receives as input sequences of tokens $\mathbf{S}_{n}$ of size $n\leq K$. We first lower-bound each term of the probability ratio. By definition of $p_{\mathrm{min}}$, we have

$$ $\mathbb{P}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)=\mathbb{P}\left( \mathbf{X}_{n+1}\mid\mathbf{X}_{n}\right)\geq p_{\mathrm{min}}>0,$ (28) $$

where we used the Markov property for the first equality.
We want to obtain a similar inequality for $\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)$. As the parameters $\bm{\Theta}$ of the LLM are in $\mathcal{W}$, we know that $\lVert\mathbf{W}_{U}^{\top}\rVert_{2,1}\leq B_{U}$. Section D.7.3 ensures that

$$ $\lVert\frac{1}{n\tau}\mathbf{M}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_{T} \rVert_{1}\leq\frac{1}{\tau}\lVert\mathbf{W}_{U}^{\top}\rVert_{2,1}\leq\frac{B _{U}}{\tau}.$ $$

We can then apply Section D.4.2 with $c_{1}=\frac{B_{U}}{\tau}$ and given that $\frac{1}{T\tau}\mathbf{M}\mathbf{W}_{U}\mathbf{S}^{(L)}\mathbbm{1}_{T}\in
\mathbb{R}^{d}$, it leads to

$$ $\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}_{n}\right)=\operatorname{ \mathrm{softmax}}\left(\frac{1}{n\tau}\mathbf{M}\mathbf{W}_{U}\mathbf{S}^{(L)} \mathbbm{1}_{n}\right)\geq\frac{1}{d\exp{(2B_{U}/\tau)}},$ $$

where the inequality holds for each component of $\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}_{n}\right)$. This is in particular the case $\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)$ which is the entry we are interested in, i.e., we have

$$ $\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)\geq \frac{1}{d\exp{(2B_{U}/\tau)}}.$ (29) $$

Going back to the ratio of probability, consider the situation where we have

$$ $\frac{\mathbb{P}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)}{\mathbb{P}_{ \bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)}\geq 1.$ $$

Then, using Eq. 29, we have

$$ $1\leq\frac{\mathbb{P}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)}{\mathbb{ P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)}\leq\frac{1}{ \mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)}\leq d \exp{(2B_{U}/\tau)},$ $$

which implies, as the $\log$ is non-decreasing monotonically,

$$ $0\leq\log{\left(\frac{\mathbb{P}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right )}{\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)} \right)}\leq\log{(d\exp{(2B_{U}/\tau)})}=\log{(d)}+\frac{2B_{U}}{\tau}.$ (30) $$

Similarly, consider the case where we have

$$ $\frac{\mathbb{P}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)}{\mathbb{P}_{ \bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)}\leq 1.$ $$

Then, we have

$$ $\frac{\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)} {\mathbb{P}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)}\geq 1,$ $$

and similarly to above, we can use Eq. 28 to obtain

$$ $1\leq\frac{\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n} \right)}{\mathbb{P}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)}\leq\frac{1 }{\mathbb{P}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n}\right)}\leq\frac{1}{p_{ \mathrm{min}}}.$ $$

This implies

$$ $0\leq\log{\left(\frac{\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid \mathbf{S}_{n}\right)}{\mathbb{P}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n} \right)}\right)}\leq\log{\left(\frac{1}{p_{\mathrm{min}}}\right)},$ $$

which also rewrites

$$ $0\leq-\log{\left(\frac{\mathbb{P}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n} \right)}{\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n} \right)}\right)}\leq\log{\left(\frac{1}{p_{\mathrm{min}}}\right)}.$ (31) $$

By definition of the absolute value, combining Eq. 30 and Eq. 31 leads to

$$ $\left|\log{\left(\frac{\mathbb{P}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n} \right)}{\mathbb{P}_{\bm{\Theta}}\left(\mathbf{X}_{n+1}\mid\mathbf{S}_{n} \right)}\right)}\right|\leq\max\{\log{(d)}+\frac{2B_{U}}{\tau},\log{\left( \frac{1}{p_{\mathrm{min}}}\right)}\}.$ $$

This concludes the proof.
∎

We are now ready to upper-bound the total variation.
{boxcor}[Upper-bound on the total variation]
Consider an LLM $f_{\bm{\Theta}}\in\mathcal{F}$ and an input Markov chain $X=\left(\mathbf{X}_{1},\ldots,\mathbf{X}_{N_{\mathrm{icl}}}\right)$ with $d$ states. We recall that $B_{U}$ is the upper bound on the norm of $\mathbf{W}_{U}$ in the definition of parameter space $\mathcal{W}$, $\tau$ is the softmax temperature, and $p_{\mathrm{min}}$ is the constant related to the minimal transition probability between states. We have

$$ $\forall n\in[N],\quad d_{\mathrm{TV}}\left(\mathbb{P}\left(\cdot\mid\mathbf{S} _{n}\right),\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}_{n}\right)\right )\leq\sqrt{2\max\{\log{(d)}+\frac{2B_{U}}{\tau},\log{\left(\frac{1}{p_{\mathrm {min}}}\right)}\}}\coloneqq c_{4}.$ (32) $$

###### Proof.

Using Section D.7.3, we can directly apply Section D.4.2 with $B=\max\{\log{(d)}+\frac{2B_{U}}{\tau},\log{\left(\frac{1}{p_{\mathrm{min}}}
\right)}\}$ for any $n\in[N]$. It leads to

$$ $\forall n\in[N],\quad d_{\mathrm{TV}}\left(\mathbb{P}\left(\cdot\mid\mathbf{S} _{n}\right),\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}_{n}\right)\right )\leq\sqrt{2\max\{\log{(d)}+\frac{2B_{U}}{\tau},\log{\left(\frac{1}{p_{\mathrm {min}}}\right)}\}}.$ $$

This concludes the proof.
∎

###### Proof.

###### Proof.

###### Proof.

###### Proof.

#### D.7.4 Concluding the Proof

We are now ready to state our main result.

[Restatement of Eq. 3]
Consider an LLM $f_{\bm{\Theta}}\in\mathcal{F}$. We provide as input of $f_{\bm{\Theta}}$ a $d-$state Markov chain $X=\left(\mathbf{X}_{1},\ldots,\mathbf{X}_{N_{\mathrm{icl}}}\right)$. The sequence of subsequences of the first $n$ terms is denoted by $S=\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N_{\mathrm{icl}}}\right)$. $S$ is also a Markov chain, and we denote by $t_{\mathrm{mix}}(\varepsilon)$ its mixing time. Let $t_{\mathrm{min}}\coloneqq\inf_{0\leq\varepsilon<1}t_{\mathrm{mix}}\left(\frac{
\varepsilon}{2}\right)\cdot\left(\frac{2-\varepsilon}{1-\varepsilon}\right)^{2}$. Let $\delta>0$. Then, with probability at least $1-\delta$,

$$ $\mathcal{R}_{\mathrm{icl}}\left(\bm{\Theta}\right)\leq\inf_{\bm{\vartheta}\in \mathcal{W}_{\mathrm{mc}}}\{\widehat{\mathcal{R}}_{\mathrm{icl}}\left(\bm{ \vartheta}\right)+K(\bm{\vartheta},\bm{\Theta})\}+\bar{B}\sqrt{\frac{t_{ \mathrm{min}}}{N_{\mathrm{icl}}}}\sqrt{\log{\left(\frac{2}{\delta}\right)}},$ $$

where $\bar{B}$ is a constant depending on the parameters of the problem. More precisely,

$$ $\bar{B}=2\sqrt{\max\{\log{(d)}+\frac{2B_{U}}{\tau},\log{\left(\frac{1}{p_{ \mathrm{min}}}\right)}\}}.$ $$

###### Proof.

Let $\bm{\vartheta}\in\mathcal{W}_{\mathrm{mc}}$. We first benefit from the metric properties of the total variation to decompose the risk.

$$ $\displaystyle\mathcal{R}_{\mathrm{icl}}\left(\bm{\Theta}\right)$ $\displaystyle=\frac{1}{N_{\mathrm{icl}}}\sum_{n=1}^{N_{\mathrm{icl}}}\mathbb{E }_{\mathbf{S}_{n}}\left[d_{\mathrm{TV}}\left(\mathbb{P}\left(\cdot\mid\mathbf{ S}_{n}\right),\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}_{n}\right) \right)\right]$ $\displaystyle\leq\frac{1}{N_{\mathrm{icl}}}\sum_{n=1}^{N_{\mathrm{icl}}} \mathbb{E}_{\mathbf{S}_{n}}\left[d_{\mathrm{TV}}\left(\mathbb{P}\left(\cdot \mid\mathbf{S}_{n}\right),\mathbb{P}_{\bm{\vartheta}}\left(\cdot\mid\mathbf{S} _{n}\right)\right)+d_{\mathrm{TV}}\left(\mathbb{P}_{\bm{\vartheta}}\left(\cdot \mid\mathbf{S}_{n}\right),\mathbb{P}_{\bm{\Theta}}\left(\cdot\mid\mathbf{S}_{n }\right)\right)\right]$ $\displaystyle\leq\frac{1}{N_{\mathrm{icl}}}\sum_{n=1}^{N_{\mathrm{icl}}} \mathbb{E}_{\mathbf{S}_{n}}\left[d_{\mathrm{TV}}\left(\mathbb{P}\left(\cdot \mid\mathbf{S}_{n}\right),\mathbb{P}_{\bm{\vartheta}}\left(\cdot\mid\mathbf{S} _{n}\right)\right)\right]$ $\displaystyle\qquad\qquad+\frac{1}{N_{\mathrm{icl}}}\sum_{n=1}^{N_{\mathrm{icl }}}\mathbb{E}_{\mathbf{S}_{n}}\left[d_{\mathrm{TV}}\left(\mathbb{P}_{\bm{ \vartheta}}\left(\cdot\mid\mathbf{S}_{n}\right),\mathbb{P}_{\bm{\Theta}}\left( \cdot\mid\mathbf{S}_{n}\right)\right)\right]$ $\displaystyle\leq\mathcal{R}_{\mathrm{icl}}\left(\bm{\vartheta}\right)+K(\bm{ \vartheta},\bm{\Theta}).$ (33) $$

By definition of the risk, we have

$$ $\widehat{\mathcal{R}}_{\mathrm{icl}}\left(\bm{\vartheta}\right)=\frac{1}{N_{ \mathrm{icl}}}\sum_{n=1}^{N_{\mathrm{icl}}}\underbrace{d_{\mathrm{TV}}\left( \mathbb{P}\left(\cdot\mid\mathbf{S}_{n}\right),\mathbb{P}_{\bm{\vartheta}} \left(\cdot\mid\mathbf{S}_{n}\right)\right)}_{=g_{n}\left(\mathbf{S}_{n}\right )}=\frac{1}{N_{\mathrm{icl}}}\sum_{n=1}^{N_{\mathrm{train}}}g_{n}\left(\mathbf {S}_{n}\right)=f\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N_{\mathrm{icl}}} \right)=f\left(S\right).$ $$

Using Section D.7.3, we know that

$$ $\lvert g_{n}\left(\mathbf{S}_{n}\right)\rvert\leq\sqrt{2\max\{\log{(d)}+\frac{ 2B_{U}}{\tau},\log{\left(\frac{1}{p_{\mathrm{min}}}\right)}\}}\coloneqq c_{4}.$ $$

Similarly to Section 4.1, and using the fact that $S=\left(\mathbf{S}_{1},\ldots,\mathbf{S}_{N_{\mathrm{icl}}}\right)$ is a Markov chain, we can show that choosing $\mathbf{c}\in\mathbb{R}^{N_{\mathrm{icl}}}$ with all entries equal to $\frac{2c_{4}}{N_{\mathrm{icl}}}$ ensures that $f$ verifies the condition in Section D.4.1, i.e.,

$$ $\forall S,\Sigma,\quad f(S)-f(\Sigma)\leq\sum_{n=1}^{N_{\mathrm{icl}}}\mathbf{ c}_{n}\mathbbm{1}_{\{\mathbf{S}_{n}\neq\bm{\Sigma}_{n}\}}.$ $$

Putting everything together, we can apply Section D.7.2 which leads to

$$ $\forall u\geq 0,\quad\mathbb{P}\left(\lvert f(S)-\mathbb{E}_{S}\left[f(S) \right]\rvert\geq u\right)\leq 2\exp{\left(\frac{-2u^{2}}{t_{\mathrm{min}} \lVert\mathbf{c}\rVert_{2}^{2}}\right)}.$ (34) $$

Let $u\geq 0$. We have the following events ordering

$$ $\displaystyle\left(\mathbb{E}_{S}\left[f(S)\right]-f(S)\geq u\right)$ $\displaystyle\subseteq\left(\mathbb{E}_{S}\left[f(S)\right]-f(S)\geq u\right) \cup\left(f(S)-\mathbb{E}_{S}\left[f(S)\right]\geq u\right)$ $\displaystyle=\left(\left|f(S)-\mathbb{E}_{S}\left[f(S)\right]\right|\geq u \right).$ $$

Hence, as $u$ was taken arbitrary and using Eq. 34, we have

$$ $\forall u\geq 0,\quad\mathbb{P}\left(\mathbb{E}_{S}\left[f(S)\right]-f(S)\geq u \right)\leq 2\exp{\left(\frac{-2u^{2}}{t_{\mathrm{min}}\lVert\mathbf{c}\rVert_ {2}^{2}}\right)}.$ $$

We recall that by definition

$$ $f(S)=\widehat{\mathcal{R}}_{\mathrm{icl}}\left(\bm{\vartheta}\right)\text{ and }\mathcal{R}_{\mathrm{icl}}\left(\bm{\vartheta}\right)=\mathbb{E}_{S}\left[ \widehat{\mathcal{R}}_{\mathrm{icl}}\left(\bm{\vartheta}\right)\right].$ $$

Moreover, the inequality on the probability holds for any $u\geq 0$, we can choose $u$ such that

$$ $\displaystyle\delta=2\exp{\left(\frac{-2u^{2}}{t_{\mathrm{min}}\mathbf{c} \rVert_{2}^{2}}\right)}$ $\displaystyle\iff\frac{-2u^{2}}{t_{\mathrm{min}}\lVert\mathbf{c}\rVert_{2}^{2} }=\log{\left(\frac{\delta}{2}\right)}\iff u^{2}=\frac{1}{2}t_{\mathrm{min}} \lVert\mathbf{c}\rVert_{2}^{2}\log{\left(\frac{2}{\delta}\right)}$ $\displaystyle\iff u=\frac{1}{\sqrt{2}}\sqrt{t_{\mathrm{min}}}\lVert\mathbf{c} \rVert_{2}\sqrt{\log{\left(\frac{2}{\delta}\right)}}.$ $$

Using the fact that

$$ $\lVert\mathbf{c}\rVert_{2}=\sqrt{\sum_{n=1}^{N_{\mathrm{icl}}}\mathbf{c}_{n}^{ 2}}=\sqrt{\sum_{n=1}^{N_{\mathrm{icl}}}\left(\frac{2c_{4}}{N_{\mathrm{icl}}} \right)^{2}}=\sqrt{\sum_{n=1}^{N_{\mathrm{icl}}}\frac{4c_{4}^{2}}{N_{\mathrm{ icl}}^{2}}}=\sqrt{\frac{4c_{4}^{2}}{N_{\mathrm{icl}}}}=\frac{2c_{4}}{\sqrt{N_{ \mathrm{icl}}}}.$ $$

Using the fact that $c_{4}=\sqrt{2\max\{\log{(d)}+\frac{2B_{U}}{\tau},\log{\left(\frac{1}{p_{
\mathrm{min}}}\right)}\}}$ (Section D.7.3), we obtain

$$ $\displaystyle u$ $\displaystyle=\frac{1}{\sqrt{2}}\frac{2c_{4}}{\sqrt{N_{\mathrm{icl}}}}\sqrt{t_ {\mathrm{min}}}\sqrt{\log{\left(\frac{2}{\delta}\right)}}=\frac{\sqrt{2}c_{4}} {\sqrt{N_{\mathrm{icl}}}}\sqrt{t_{\mathrm{min}}}\sqrt{\log{\left(\frac{2}{ \delta}\right)}}$ $\displaystyle=\frac{2\sqrt{t_{\mathrm{min}}}\sqrt{\max\{\log{(d)}+\frac{2B_{U} }{\tau},\log{\left(\frac{1}{p_{\mathrm{min}}}\right)}\}}}{\sqrt{N_{\mathrm{ train}}}}\sqrt{\log{\left(\frac{2}{\delta}\right)}}$ $\displaystyle=\bar{B}\sqrt{\frac{t_{\mathrm{min}}}{N_{\mathrm{icl}}}}\sqrt{ \log{\left(\frac{2}{\delta}\right)}},$ $$

where we define

$$ $\bar{B}=2\sqrt{\max\{\log{(d)}+\frac{2B_{U}}{\tau},\log{\left(\frac{1}{p_{ \mathrm{min}}}\right)}\}}.$ $$

Putting everything together, we have

$$ $\mathbb{P}\left(\mathcal{R}_{\mathrm{icl}}\left(\bm{\vartheta}\right)-\widehat {\mathcal{R}}_{\mathrm{icl}}\left(\bm{\vartheta}\right)\geq\bar{B}\sqrt{\frac{ t_{\mathrm{min}}}{N_{\mathrm{icl}}}}\sqrt{\log{\left(\frac{2}{\delta}\right)}} \right)\leq\delta.$ $$

Taking the opposite event leads to the following inequality with probability at least $1-\delta$

$$ $\mathcal{R}_{\mathrm{icl}}\left(\bm{\vartheta}\right)\leq\widehat{\mathcal{R}} _{\mathrm{icl}}\left(\bm{\vartheta}\right)+\bar{B}\frac{\sqrt{t_{\mathrm{min}} }}{\sqrt{N_{\mathrm{icl}}}}\sqrt{\log{\left(\frac{2}{\delta}\right)}}.$ $$

Going back to the decomposition of the risk in Section D.7.4 and rearranging the terms, we obtain

$$ $\mathcal{R}_{\mathrm{icl}}\left(\bm{\Theta}\right)\leq\widehat{\mathcal{R}}_{ \mathrm{icl}}\left(\bm{\vartheta}\right)+K(\bm{\Theta},\bm{\vartheta})+\bar{B} \frac{\sqrt{t_{\mathrm{min}}}}{\sqrt{N_{\mathrm{icl}}}}\sqrt{\log{\left(\frac{ 2}{\delta}\right)}}.$ $$

As the left-hand side and the bound function of $\bar{B}$ do not depend on $\bm{\vartheta}$, we can put them both on the left side of the inequality and then take the infimum on $\bm{\vartheta}$. Rearranging the terms to keep only $\widehat{\mathcal{R}}_{\mathrm{icl}}\left(\bm{\Theta}\right)$ on the left side of the inequality leads to

$$ $\mathcal{R}_{\mathrm{icl}}\left(\bm{\Theta}\right)\leq\inf_{\bm{\vartheta}\in \mathcal{W}_{\mathrm{mc}}}\{\widehat{\mathcal{R}}_{\mathrm{icl}}\left(\bm{ \vartheta}\right)+K(\bm{\vartheta},\bm{\Theta})\}+\bar{B}\sqrt{\frac{t_{ \mathrm{min}}}{N_{\mathrm{icl}}}}\sqrt{\log{\left(\frac{2}{\delta}\right)}},$ $$

which concludes the proof.
∎

###### Proof.

## Appendix E Additional Experiments

### E.1 Experimental Setup and Tokenization

##### Experimental setup.

To ensure a fair validation of our theoretical results, we conduct our experiments on some of the most recent and widely used LLMs: Gemma 2B (Team et al., ), Llama2 7B & 13B (Touvron et al., ), Llama3 8B, Llama3.2 1B & 3B (Dubey et al., ), and Mistral 7Bv0.1 (Jiang et al., ).

##### Tokenization.

As the models we consider have different tokenizations, we need to do this step with extra care as it is a crucial part of the experimental procedure.
Indeed, LLMs’ ability to handle numerical values has been proved to be dependent on the tokenization algorithm (Singh & Strouse, ; Ali et al., ; Gruver et al., ).
The most widely used tokenization algorithm to-date, *BPE* (Sennrich et al., ), tends to assign tokens to arbitrary $3$-digits numbers based on their occurrences in large-scale corpora, and the tokenizer’s vocabulary size. As highlighted by (Gruver et al., ), this artifact severely hinders LLMs’ ability to predict numerical values in-context.
This is the case for popular LLMs such as GPT-3 (Brown et al., ). Newer models (LLama3, GPT-3.5, GPT-4) however, tend to have hard-coded rules on top of *BPE*, making them able to encode all $3$-digits numbers with their own token. Although this feature would accelerate the ICL procedure by eliminating the need for the *Hierarchy-PDF* algorithm in (Liu et al., ),the under-representability of larger numbers in the training data could be an issue. Other tokenization techniques that are numerical values-focused has been presented in the literature (Golkar et al., ; Wu et al., ), paving the way for another research direction that may benefit our method.

##### Rodmap.

In the rest of this section, we extend our experiments to study the following setups:

- •
In Section E.2: impact of the number of states $d$;
- •
In Section E.3: extension to Markov chains with $p_{\mathrm{min}}=0$;
- •
In Section E.4: impact of the tokenization;
- •
In Section E.5: extension to dynamical systems.

### E.2 Impact of the Number of States d 𝑑 d italic_d

We further analyze the effect of the number of states $d$ on the risk and consider randomly generated $d$-state transition matrices in Fig. 9. After a first stage of stagnation, the risk tends to take the correct scaling law coefficient. As in (Liu et al., ), we notice that considering randomly generated transition matrices seems to be difficult for an LLM to learn when there are more than $9$ states. We interpret this behavior as the distribution shift term in Eq. 3. Indeed, the lack of structure in these transition matrices can hinder the correct decay of this term. Note also that the increase in $d$ tends to implicitly increase $t_{\mathrm{min}}$, which could have an impact on the upper bound on $\mathcal{R}_{\mathrm{icl}}$ (both in the generalization term and in the distribution shift term). We will now consider more structured Markov chains, and look at their impact on decay.

Figure: Figure 9: Impact of the number of states $d$. We plot the risk $\mathcal{R}_{\mathrm{icl}}$ as functions of $N_{\mathrm{icl}}$, with $95\%$ confidence intervals. Upper Left. $2-$states Markov transition matrices. Upper Right. $4-$states Markov transition matrices. Lower Left. $6-$states Markov transition matrices. Lower Right. $8-$states Markov transition matrices.
Refer to caption: x6.png

### E.3 More Structured Markov Chains

In this section, we empirically verify our theoretical results on more general Markov chains that do not verify $p_{\mathrm{min}}>0$.

#### E.3.1 Random Walks

Random walks are a simple example of more structured Markov chains. Although we still have the possibility of discretizing the kernel of
Markov chains with infinite state spaces as it is done in (Liu et al., ), we consider two types of random walks on finite state spaces.

Figure: Figure 10: Constrained random walk with $d=3$.
Refer to caption: x11.png

##### Constrained random walk.

We define the transition matrix $P$ of a constrained random walk of $d$ states as in Eq. 35. We draw the probabilistic graph in Fig. 10 for the case $d=3$.

$$ $P_{ij}=\begin{cases}1,&\text{if }i=0\text{ and }j=1,\\ 1,&\text{if }i=\text{d}-1\text{ and }j=\text{d}-2,\\ 0.5,&\text{if }1\leq i\leq\text{d}-2\text{ and }j=i-1,\\ 0.5,&\text{if }1\leq i\leq\text{d}-2\text{ and }j=i+1,\\ 0,&\text{otherwise}.\end{cases}$ (35) $$

Fig. 11 highlights the scaling laws of Eq. 3, as well as the $\log(d)$ dependency. As before, the best-performing models generalize almost perfectly.

Figure: Figure 11: Constrained random walks. We plot the risk $\mathcal{R}_{\mathrm{icl}}$ as functions of $N_{\mathrm{icl}}$, with $99\%$ confidence intervals. We consider different size $d$. Upper Left. Llama2 7B Upper Right. Llama2 13B Lower Left. Mistral 7Bv0.1 Lower Right. Gemma 2B
Refer to caption: x12.png

##### Polygonal random walk.

We define the transition matrix $\mathbb{P}$ of a polygonal random walk of $d$ states as in Eq. 36. We draw the probabilistic graph in Fig. 12 for the case $d=4$.

$$ $P_{ij}=\begin{cases}0.5,&\text{if }j=(i+1)\mod\text{d}\text{ (clockwise transition)},\\ 0.5,&\text{if }j=(i-1)\mod\text{d}\text{ (counterclockwise transition)},\\ 0,&\text{otherwise}.\end{cases}$ (36) $$

We draw the same conclusions as above for this second type of random walk, in Fig. 13.

Figure: Figure 12: Polygonal random walk with $d=4$.
Refer to caption: x17.png

Figure: Figure 13: Polygonal random walks. We plot the risk $\mathcal{R}_{\mathrm{icl}}$ as functions of $N_{\mathrm{icl}}$, with $99\%$ confidence intervals. We consider different size $d$. Upper Left. Llama2 7B Upper Right. Llama2 13B Lower Left. Mistral 7Bv0.1 Lower Right. Gemma 2B
Refer to caption: x18.png

#### E.3.2 Inner Cliques and Outer Rims

##### Inner Cliques and Outer Rims.

We also want to test our method on the class of Markov chain put forward in (Wolfer & Kontorovich, ) to derive their lower bound. Let $\eta>0$ and $d=3k$ for some $k\in\mathbb{N}$, and define the collection of Markov matrices $\mathcal{H}_{\eta}=\{\bm{M}_{\eta,\bm{\tau}}:\bm{\tau}\in\{0,1\}^{d/3}\}$. Every element of this set consists of an inner clique
and an outer rim. $\bm{M}_{\eta,\bm{\tau}}$ is the block matrix defined as follows,

$$ $\bm{M}_{\eta,\bm{\tau}}=\begin{pmatrix}C_{\eta}&R_{\bm{\tau}}\\ R_{\bm{\tau}}^{\intercal}&L_{\bm{\tau}}\end{pmatrix},$ $$

where
$C_{\eta}\in\mathbb{R}^{d/3\times d/3}$,
$L_{\bm{\tau}}\in\mathbb{R}^{2d/3\times 2d/3}$,
and
$R_{\bm{\tau}}\in\mathbb{R}^{d/3\times 2d/3}$
are given by

$$ $L_{\bm{\tau}}=\frac{1}{8}\operatorname{diag}\left(7-4\tau_{1}\varepsilon,7+4 \tau_{1}\varepsilon,\dots,7-4\tau_{d/3}\varepsilon,7+4\tau_{d/3}\varepsilon \right),$ $$

$$ $C_{\eta}=\begin{pmatrix}\frac{3}{4}-\eta&\frac{\eta}{d/3-1}&\ldots&\frac{\eta} {d/3-1}\\ \frac{\eta}{d/3-1}&\frac{3}{4}-\eta&\ddots&\vdots\\ \vdots&\ddots&\ddots&\frac{\eta}{d/3-1}\\ \frac{\eta}{d/3-1}&\ldots&\frac{\eta}{d/3-1}&\frac{3}{4}-\eta\\ \end{pmatrix},$ $$

$$ $R_{\bm{\tau}}=\frac{1}{8}\begin{pmatrix}1+4\tau_{1}\varepsilon&1-4\tau_{1} \varepsilon&0&\ldots&\ldots&\ldots&0\\ 0&0&1+4\tau_{2}\varepsilon&1-4\tau_{2}\varepsilon&0&\ldots&0\\ \vdots&\vdots&\vdots&\vdots&\vdots&\vdots&\vdots\\ 0&\ldots&\ldots&\ldots&0&1+4\tau_{d/3}\varepsilon&1-4\tau_{d/3}\varepsilon\end {pmatrix}.$ $$

We provide in Fig. 14 a probabilistic graph of the case $\bm{M}_{\eta,\mathbb{0}}$ and $d=9$.

Figure: Figure 14: Probabilistic graph of $\bm{M}_{\eta,\mathbb{0}}$ when $d=9$.
Refer to caption: x23.png

Fig. 15 compares different LLMs with the frequentist method, on the case depicted in Fig. 15 with $\eta=0.02$. Although the frequentist method achieves a lower loss, the power laws seem to be the same with LLMs.

Figure: Figure 15: We plot the risk $\mathcal{R}_{\mathrm{icl}}$ as functions of $N_{\mathrm{icl}}$, with $95\%$ confidence intervals. Upper Left. Llama2 7B Upper Right. Llama2 13B Lower Left. Mistral 7Bv0.1 Lower Right. Gemma 2B
Refer to caption: x24.png

### E.4 Recent Models: Impact of the Tokenization

As explained in Section E.1, models like Llama 3 tokenize 3-digit numbers with a single token. This saves a lot of inference compute time, but not necessarily in terms of performance when considering Markov chains with a few number of states $d$, since we have to separate the states by a comma to force tokenization into a single digit (e.g. the transitions $\texttt{1}\to\texttt{0}\to\texttt{1}$ will be prompted as 1,0,1 ($5$ tokens) instead of 101 ($1$ token). In Fig. 16, we reproduce the same experiment as in Fig. 5(left), but with Llama 3 models. The scaling laws are quite good, but much less so than those obtained with Gemma 2B and Mistral 7Bv0.1 on the same inputs. On the other hand, with these models, it can be extremely interesting to consider Markov chains with many states, as we did in Fig. 6(right). In the next section, we will use LLama3 to learn other dynamic systems presented in Liu et al. ().

Figure: Figure 16: In-context scaling laws for LLama3 herd of models. We plot the risk $\mathcal{R}_{\mathrm{icl}}$ as functions of $N_{\mathrm{icl}}$, with $95\%$ confidence intervals.

### E.5 Dynamical Systems

We consider four of the dynamic systems highlighted in (Liu et al., ) : a geometric Brownian motion, a correlated Gaussian, an uncorrelated Gaussian and an uncorrelated uniform processes. We display in Fig. 17 the risks of LLama3 8B and the frequentist method, which once again highlight the emerging capacity of in-context learning.

Figure: Figure 17: LLama3 8B on dynamical systems. We plot the risks $\mathcal{R}_{\mathrm{icl}}$ as functions of $N_{\mathrm{icl}}$ for LLama3 8B and the frequentist approach (Wolfer & Kontorovich, ) with $95\%$ confidence intervals. Upper Left. Geometric Brownian motion. Upper Right. Correlated Gaussian. Lower Left. Uncorrelated Gaussian. Lower Right. Uncorrelated Uniform.

## Peer Reviews

confidence: 4
contribution: 2
initial_rating: 5
presentation: 2
questions: Overall this work is very well written, which is the reason why the reviewer gives a 5 rather than a 3. The reviewer believes that this work is not very relevant to the LLM community but more relevant to the traditional learning theory (a.k.a. VC theory) community (given that the author changes the way this work is presented by replacing most of the LLMs to autoregressive models and maybe draw connections in a milder way).
soundness: 3
strengths: The strength is the theoretical results look pretty solid. And the author writes this paper in a very clear fashion. making it very readable. Also the results follow from the uniform concentration bound of MCs, presented in a rather classical learning theoretic (a.k.a. VC style) fashion.  I believe this result is relevant to the learning theory community although I cannot decide how much technical innovations are made here. The reviewer believes that this result adapt previous results by many other learning theory researchers who develop theory on estimating the transition kernel of MC given single path observations.
summary: This work studies the learning theoretical properties of auto-regressive model ( which the author claim to be LLM ) on Markov Chains.
In particular, they prove the convergence of MC and the generalization guarantees of learning the parameter $\Theta$. They also carried out numerical experiments on it.
weaknesses: The major weakness is the connection to LLMs. The first thing is whether the class F is sufficiently large to include some instances of LLMs. Right now it seems only takes a single input $v_{I}$ instead of $v_{I-1},v_{I-2},\ldots,v_{I-k}$. Though it may not be feasible anymore to learn MC due to the Markovian properties after we make this change.  However, real world language might not be treated as Markovian, which is a very stylized assumption here. The reviewer believes this will affect the impact of this work in the LLM community.

Another huge concern is that $F$ is regardless of the structure of the model itself. It can either be an RNN, Transformer, or a LSTM, and the result continues to hold. It can even be non-NN model. This does not actually reveal why LLM is a powerful machine since it highly depends on the NN as its backbone. Therefore these limitations significantly affect its contribution to the modern LLM theory community.

Hence, the reviewer suggests that instead of connecting such work to LLM, the author might be able to use the Auto-regressive model as the title, which is deemed more proper. And this model might include LLM as a special instance. At the current stage, the reviewer does not think LLM community will put a lot of focus on this work due to its over-general problem setup.

---

confidence: 3
contribution: 2
initial_rating: 5
presentation: 2
questions: I have a few questions that would make it easier for me to understand the results of the paper and its impact:
1) What is the connection between the first and second part of the paper? Are the results of the first part important for the derivation of the generalization bounds? If so, what are the key steps when the equivalence proved in the first part is useful in the second part? What is the intuition?
2) I struggle to understand the implication of the results of the first part for LLMs. In particular, what does it mean for LLMs to converge to their stationary distribution? Does that mean that the model's loss has converged to some minima? Does that mean that the LLM inference performance cannot be improved further?
3) I was curious about the choice of the TV distance in the risk definition (2). Would it be easy to move to some more popular loss choice for LLMs such as the cross-entropy loss? Intuitively, it shouldn't be too hard since cross-entropy loss is basically KL divergence, which in turn is connected to TV distance through Pinsker's inequality.
soundness: 3
strengths: The paper is well written. I was not able to check all the proofs but the math seems sound to me and the results are interesting.
summary: In this paper, the authors first enstablish the equivalence between autoregressive models and first-order Markov chains with number of states proportional to $T^K$, where $T$ is the alphabet size and $K$ is the context window, proving results about the stationary distribution of such chains. In the second part of the paper, the authors prove pre-training and in-context generalization bounds for LLMs, validating them with several experiments.
weaknesses: My main concern is that it is not clear to me what is the connection between the first part (equivalence between autoregressive models and Markov chains) and the second part (generalization bounds) of the paper. As it is, the paper looks like two different papers glued together.

---

confidence: 2
contribution: 3
initial_rating: 5
presentation: 3
questions: * I believe that Fig.3(d) on line 243 might be a typo for Fig.3(c). Setting that aside, what is the meaning of Fig.3(c)? If the parameter $K$ is only assigned to Llama and GPT, there seems to be no additional information added to Proposition 3.3. Could the authors explain how to evaluate the specific value of $\epsilon$ in LLMs?

* Fig.4(d) presents the temperature dependence of $\epsilon$, but how was this obtained? I may have missed something, but I would appreciate clarification from the authors. It is obvious that convergence is faster at high temperatures, so I am curious about the functional form of $\epsilon(T)$. 

* The probability distribution formula on line 327 seems redundant.

* In evaluating the generalization bound, it is assumed that the pre-training data is generated from the Marton coupling. Is this condition essential for obtaining the bound?

* In Fig.5(right), the context length $N_\text{icl}$ dependence of the risk is presented for several values of $t_\text{min}$. While the results for small $N_\text{icl}$ deviate from the scaling law, the theoretical prediction is $\sqrt{t_\text{min}/N_\text{icl}}$. Did the authors attempt to plot the results as a function of $t_\text{min}/N_\text{icl}$ or $N_\text{icl}/t_\text{min}$ to check for a universal curve, indicating a crossover?
soundness: 3
strengths: * This paper introduces a unique approach by modeling LLMs as finite-state Markov chains. This approach provides a clear explanation of the inference process and convergence properties of LLMs to a stationary distribution and also provides a new perspective on understanding LLM behavior theoretically. This approach is expected to expand our understanding of the overall model structure of existing LLM schemes, such as autoregressive models with self-attention mechanisms.
* A major contribution is the derivation of generalization bounds for pre-training and in-context learning, applying the concentration inequality from Markov chain theory to gain a quantitative understanding of LLM's learning characteristics. This increases confidence in the accuracy and inference capabilities of LLMs and is also helpful for comparing different LLMs.
summary: This paper theoretically characterizes the inference mechanism of large language models (LLMs) as a finite-state Markov chain, providing insights into LLM properties based on the transition kernel of the associated Markov chain. Specifically, by modeling an LLM as a Markov chain, the authors show that the output distribution of the LLM converges to a specific stationary distribution and that the convergence rate depends on certain parameters in the LLM. They also derive generalization bounds for the pre-training and in-context learning of LLMs and experimentally verify the behavior of some recent LLMs using these theoretical results.
weaknesses: * As noted above, while modeling LLMs as a Markov chain provides a new perspective, there is no new development in Markov chain theory itself. The author's theoretical framework is limited to an extension of existing Markov chain theory, and it remains unclear to what extent this framework fully captures the complex structure and dynamic properties unique to LLMs. Due to the multilayered structure and self-attention mechanisms within LLMs, it is unclear to what extent these can be accurately presented using Markov chains.
* The effect of temperature parameters on convergence rate is analyzed, but the influence of other hyperparameters and model structure, such as depth, number of heads, and layer-specific settings, on convergence and inference performance, is not examined in detail. Consequently, the paper provides insufficient guidance for optimal parameter design in LLMs.

Meta-review: The paper brings a learning theory viewpoint to the standard equivalence between language models (LLMs or others, of window size K) and Markov chains (of state size |V|^K). It later connects the existence of a stationary distribution of Markov chains to the the inference power of LLMs.

Main concerns after author feedback remained around whether the theoretical framework truly captures transformer-specific properties of LLMs. The work suffers from over-claiming in this aspect, even affecting the title of the paper. The main equivalence in Proposition 3.1 (and results of Section 3) have nothing to do with transformers but holds for any neural network which (in an autoregressive fashion) predicts the next token based on previous K tokens.

As suggested by Reviewer ugPy, it would be better to decouple this into two papers, separating the (in my view not novel results of Section 3) and the more interesting results of Section 4, or at least deemphasize Section 3 as being only a warm-up for the main results in Section 4.
The author feedback phase led to constructive discussion and improvements in clarity, but nevertheless couldn't fully resolve the main concerns.

Decision: Reject