LLMZip: Lossless Text Compression using Large Language Models

Chandra Shekhara Kaushik Valmeekam, Krishna Narayanan, Dileep Kalathil, Jean-François Chamberland, Srinivas Shakkottai · DOI

Abstract

LLMZip demonstrates that Large Language Models (LLMs) like LLaMA-7B can be repurposed as high-performance text compressors. By integrating LLM next-token probability distributions with arithmetic coding, this framework achieves a compression ratio of approximately 0.71 bits per character (bpc). This performance significantly surpasses traditional state-of-the-art tools such as ZPAQ and establishes a new, tighter upper bound on the entropy of the English language.

Introduction

Lossless compression is fundamentally a task of sequence prediction. As Claude Shannon observed in 1951, the ability to perfectly predict the next character in a sequence eliminates the need to store it, defining the "entropy" or fundamental limit of compressibility. While traditional algorithms have progressed from simple pattern matching (e.g., DEFLATE/zlib) to complex statistical modeling (e.g., ZPAQ), they often lack the deep semantic context required to match human-level prediction. LLMZip investigates whether the superior predictive capabilities of modern LLMs can break existing compression ceilings and provide a more accurate estimation of English text information density.

Methodology

The LLMZip framework utilizes an LLM as a probability generator for a lossless coder. The process involves several key stages:

  1. Tokenization and Prediction: The system uses LLaMA-7B with a SentencePiece tokenizer. Given a context window of $M$ past tokens, the model generates a probability distribution for the subsequent token.
  2. Rank Computation: The intuition behind this approach is that a "smart" model will frequently assign the highest probabilities to the actual next token. By converting the text into a sequence of ranks (where 0 is the most likely prediction), the data becomes highly predictable.
  3. Arithmetic Coding (AC): To maximize efficiency, LLMZip employs arithmetic coding. Instead of simple rank-based storage, AC utilizes the exact probability distributions from the LLM to map the entire text into a single high-precision fractional number.
The general architecture of the LLMZip compression pipeline.

The relationship between bits per token (the LLM's raw output) and bits per character (the standard compression metric) is formally derived to account for the variable length of tokens produced by the SentencePiece tokenizer.

Experimental Setup

The performance of LLMZip was evaluated on two distinct datasets:

  • text8: A standard 100MB benchmark of cleaned Wikipedia text.
  • Project Gutenberg ("Legends of Texas"): A book published in May 2023. This "out-of-distribution" dataset ensures that the model's performance is due to generalized predictive power rather than memorization of training data, as LLaMA's training cutoff preceded this publication.

Results and Discussion

LLMZip achieves a substantial lead over traditional state-of-the-art (SOTA) compression algorithms. On the text8 dataset, LLMZip is nearly twice as efficient as ZPAQ, reaching 0.7101 bpc compared to ZPAQ's 1.4 bpc.

Compression performance metrics across different context window sizes (M).

Key observations from the results include:

  • Entropy Redefinition: The results suggest a new asymptotic upper bound for English entropy at 0.709 bpc, significantly lower than the 1.3 bpc estimate from 1978.
  • Scaling with Context: As shown in the experimental data, compression performance improves as the context window ($M$) increases from 31 to 511 tokens. This indicates that longer-range dependencies are crucial for minimizing redundancy.
  • Generalization: Even on the novel Project Gutenberg text, LLMZip outperformed all baselines (0.8426 bpc), confirming that the model has learned robust linguistic structures.

Conclusion and Limitations

While LLMZip sets new records for compression density, it faces significant practical hurdles. The primary limitation is computational overhead; inference for a 7B parameter model is slow, and increasing the context window further compounds this latency. Additionally, decompression requires the receiver to have the exact same model weights and architecture. Future research will focus on optimizing inference speed and exploring the trade-offs between model size and compression efficiency.

Summary updated

BibTeX
@misc{valmeekam2023llmzip,
  author = {Chandra Shekhara Kaushik Valmeekam and Krishna Narayanan and Dileep Kalathil and Jean-François Chamberland and Srinivas Shakkottai},
  title = {{LLMZip: Lossless Text Compression using Large Language Models}},
  year = {2023},
  eprint = {2306.04050},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2306.04050},
}
Figure