The LZ78 Source

Naomi Sagan, Amir Dembo, Tsachy Weissman · OpenReview

Abstract

This paper introduces the LZ78 source, a novel class of non-stationary, non-Markovian stochastic processes derived from the Lempel-Ziv compression algorithm. We prove that these sources possess a unique "Jensen gap"—a fundamental limit where finite-memory predictors can never reach the true entropy rate—making them a uniquely challenging and discriminative benchmark for evaluating how Transformers learn in-context. Our experiments demonstrate that Transformers significantly outperform classical baselines and generalize effectively to real-world genomic sequences.

Introduction

In the study of Information Theory and Machine Learning, researchers often rely on stationary, ergodic sources, such as Markov chains, to model data. However, real-world data—ranging from natural language to genomic sequences—is rarely stationary; it often features dependencies that grow over time. While the LZ78 algorithm is a cornerstone of universal compression, its potential as a generative source has remained largely unexplored.

We identify a critical gap: the lack of synthetic benchmarks that are mathematically tractable yet sufficiently complex to test the limits of In-Context Learning (ICL). Standard Markov benchmarks are often "too easy" due to their fixed memory requirements. The LZ78 source, by contrast, requires a context that expands as the sequence grows, providing a realistic "stress test" for modern AI models like Transformers.

Methods and Data

The LZ78 source is defined through a constructive process involving an evolving prefix tree.

The LZ78 Prefix Tree Construction

  1. Tree Growth: The source "grows" an LZ78 tree. Each node in the tree is assigned a probability parameter $\Theta$ drawn i.i.d. from a prior distribution $\Pi$.
  2. Sequential Assignment: To generate the next symbol, the process traverses the tree based on previous symbols. If it hits a leaf, it adds a new node, assigns it a new $\Theta$, and returns to the root.
The LZ78 prefix tree structure evolves as the sequence grows, requiring expanding context for accurate prediction.

Experimental Setup

We trained small Transformer models (1–5 layers) using the NanoGPT framework to evaluate their ability to learn these sequences in-context. These models were compared against classical baselines, including Context Tree Weighting (CTW) and fixed-order Markov models.

The datasets used include:

  • Synthetic LZ78 Sources: Generated using various priors, such as the Jeffreys prior (Dirichlet(0.5, 0.5)) and Dirac-Dirichlet mixtures to simulate long-range dependencies.
  • Real-World Genomic Data: Sequences from Human Chromosome 1 were used to test the generalization of models trained on synthetic LZ78 data to biological sequences.

Theoretical Framework: The Jensen Gap

The paper's primary theoretical contribution is the characterization of the "Jensen gap." Because entropy is a concave function, the entropy of the average parameter $H(\mathbb{E}[\Theta])$ is strictly greater than the average entropy $\mathbb{E}[H(\Theta)]$.

We prove that any finite-state predictor (such as a Markov model) will converge to the higher value $H(\mathbb{E}[\Theta])$, while the LZ78 source's true entropy rate is the lower value $\mathbb{E}[H(\Theta)]$. This gap represents a permanent penalty for models with finite memory, highlighting why the LZ78 source is a "substantially harder and more discriminative benchmark" for ICL.

Key Results

  • Transformer Superiority: Transformers with 3–5 layers significantly outperformed classical CTW and fixed-order Markov models. They achieved a lower log-loss than any CTW depth tested, suggesting they learn the underlying LZ-based dependency structure rather than simple statistics.
  • Depth Threshold: A clear performance jump was observed between 2-layer and 3-layer Transformers, indicating a minimum architectural complexity required to handle the expanding context of the LZ78 source.
  • Generalization to Genomics: Models trained on the LZ78 source exhibited performance comparable to CTW on real human genomic data, suggesting that the LZ78 source is a powerful proxy for non-Markovian structures in nature.

Conclusion

The LZ78 source provides a rigorous framework for testing the limits of in-context learning. By bridging the gap between tractable synthetic models and the complexity of real-world data, it offers a new frontier for understanding how Transformers process non-stationary information. Future work will explore extensions to other universal compressors, such as LZ77, and further refine the learning curves of modern architectures.

Summary updated

Abstract

We study a family of processes generated according to sequential probability assignments induced by the LZ78 universal compressor. We characterize entropic and distributional properties such as their entropy and relative entropy rates, finite-state compressibility and log loss of their realizations, and the empirical distributions that they induce. Though not quite stationary, these sources are "almost stationary and ergodic;" similar to stationary and ergodic processes, they satisfy a Shannon-McMillan-Breiman-type property: the normalized log probability of their realizations converges almost surely to their entropy rate. Further, they are locally "almost i.i.d." in the sense that the finite-dimensional empirical distributions of their realizations converge almost surely to a deterministic i.i.d. law. However, unlike stationary ergodic sources, the finite-state compressibility of their realizations is almost surely strictly larger than their entropy rate by a "Jensen gap." We present simulations demonstrating the theoretical results. Among their potential uses, these sources allow to gauge the performance of sequential probability models on non-Markovian non-stationary data.
BibTeX
@misc{sagan2025lz,
  author = {Naomi Sagan and Amir Dembo and Tsachy Weissman},
  title = {{The LZ78 Source}},
  year = {2025},
  eprint = {2503.10574},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.10574},
}
Figure