Zipf's Law Breakdown in Token Distributions: Where Power Laws Fail Across Corpora and Tokenizers
Introduction
Zipf's law states that the frequency of a word in natural language is inversely proportional to its rank: with . This power-law regularity underpins assumptions in language modeling, compression, and vocabulary design. However, modern LLM tokenizers use BPE (Byte Pair Encoding) and its variants, which produce token vocabularies that differ fundamentally from word-level distributions.
Recent work has shown that BPE's iterative merging process drives token frequencies toward Zipfian distributions as vocabulary size increases, and that downstream task performance peaks when token distributions most closely follow Zipf's law[zipf2025]. Yet systematic analysis of where and how Zipf's law breaks down across different corpus types remains limited.
This work addresses three questions:
- How do Zipf exponents differ between code and natural language token distributions?
- Where in the rank-frequency curve does the power-law fit break down?
- Does the degree of Zipfian adherence predict tokenizer compression efficiency?
We analyze 36 combinations of 4 tokenizers 9 corpora, fitting the Zipf-Mandelbrot model and performing piecewise decomposition into head, body, and tail regions.
Methods
Corpora
We use two corpus types:
- Natural language: Tatoeba parallel sentences for 7 languages (English, German, French, Chinese, Japanese, Arabic, Finnish), 200 sentences per language. Dataset revision pinned for reproducibility.
- Code: Python and Java function bodies from CodeSearchNet, 200 samples per language.
Tokenizers
Four BPE-family tokenizers spanning vocabulary sizes from 32K to 200K:
GPT-4o (o200k\_base, 200K vocab),
GPT-4 (cl100k\_base, 100K),
Qwen2.5-7B (152K),
and Mistral-7B (32K).
All model revisions are pinned.
Zipf-Mandelbrot Fitting
For each tokenizer-corpus pair, we:
- Tokenize the corpus and compute the rank-frequency distribution.
- Fit the Zipf-Mandelbrot model via OLS on log-transformed data, with grid search over .
- Report the best-fit , , and .
- Perform piecewise fitting on head (top 10%), body (10--90%), and tail (bottom 10%) regions.
- Detect breakpoints via sliding window analysis.
Correlation Analysis
We compute Pearson and Spearman correlations between the global Zipf exponent and the compression ratio (characters per token) across all 36 analyses.
Results
Global Zipf Exponents
Average Zipf exponents (α) and R² by corpus type.
| Corpus Type | Avg α | Std Dev | Avg R² |
|---|---|---|---|
| Natural language | 1.056 | 0.443 | 0.949 |
| Code | 1.397 | 0.174 | 0.976 |
Code produces higher Zipf exponents than natural language (Table). A Mann-Whitney U test confirms this difference is statistically significant (). This indicates steeper rank-frequency curves in code: a smaller set of high-frequency tokens (keywords, braces, indentation) dominates, while the long tail of identifiers and string literals drops off more sharply.
Among natural languages, the exponent varies substantially: English has across tokenizers, while Arabic with Mistral reaches (reflecting severe tokenization fragmentation). GPT-4o, with its 200K vocabulary, consistently produces the lowest values, indicating flatter, more uniform token usage.
Piecewise Breakdown
Representative piecewise Zipf exponents (GPT-4o tokenizer).
| Corpus | Head α | Body α | Tail α |
|---|---|---|---|
| English | 0.803 | 0.817 | 0.000 |
| Japanese | 0.912 | 1.257 | 0.000 |
| Arabic | 0.634 | 0.756 | 0.000 |
| Python | 0.887 | 1.429 | 0.000 |
| Java | 0.893 | 1.650 | 0.000 |
The piecewise analysis (Table) reveals a universal pattern:
- The head region (most frequent 10% of tokens) has sub-Zipfian exponents (), indicating a flatter distribution than Zipf predicts. High-frequency tokens are more uniformly distributed than expected.
- The body (10--90%) shows the strongest Zipfian behavior, with exponents closest to the global fit. For code, body exponents exceed 1, reflecting the steep drop from keywords to identifiers.
- The tail (least frequent 10%) universally collapses to , because most rare tokens appear exactly once (hapax legomena). This frequency plateau represents the primary mode of Zipf breakdown.
In 34 of 36 analyses, the tail is effectively zero. The two exceptions—Arabic with GPT-4 () and Mistral ()—exhibit extreme tail collapse where even among rare tokens there is a steep hierarchy, caused by aggressive byte-level fallback tokenization.
Correlation with Compression
The correlation between and compression ratio is modestly negative in the pooled analysis, but the evidence differs by test:
- Pearson ()
- Spearman ()
Exploratory within-type analyses retain the same sign:
- Natural language only (): Pearson (), Spearman ()
- Code only (): Pearson (), Spearman ()
This pattern is counterintuitive and should still be interpreted cautiously because the code subset is small and one of two code-side tests is marginal. Higher (steeper, more Zipfian distributions) is associated with lower compression ratios, both overall and in these subgroup analyses. The explanation lies in what drives high : it often indicates that the tokenizer fragments text into many single-use tokens (e.g., Arabic with Mistral), producing a steep rank-frequency curve but poor compression. Conversely, tokenizers with large, well-allocated vocabularies (e.g., GPT-4o) produce flatter distributions () and better compression, because their vocabulary efficiently covers the input space.
Discussion
Our findings challenge the simple narrative that "more Zipfian = better." While prior work shows that vocabulary expansion drives token distributions toward Zipf's law, our cross-corpus analysis reveals that the direction of this relationship is confounded by vocabulary adequacy.
The three-regime structure (flat head, Zipfian body, collapsed tail) appears universal across corpus types and tokenizers. This suggests that BPE tokenization inherently produces distributions that only approximate Zipf's law in the mid-frequency range, with systematic deviations at both extremes.
The code-vs-language difference () is robust across all four tokenizers and likely reflects the lower lexical diversity of programming languages, where a fixed set of keywords and syntactic elements dominates the frequency distribution.
Limitations
- Corpus sizes are small (200 samples per language), limiting statistical power for tail analysis.
- Only BPE-family tokenizers are tested; unigram and WordPiece tokenizers may show different behavior.
- OLS on log-log data introduces known biases compared to MLE; our results are valid for comparative analysis but absolute values may be slightly biased.
- The negative alpha-compression correlation may partly reflect confounding by language script complexity rather than a causal relationship.
Conclusion
We provide the first systematic cross-corpus analysis of Zipf's law adherence in BPE token distributions.
Our key findings are:
(1) code has 33% higher Zipf exponents than natural language;
(2) Zipf's law holds best in the mid-frequency body but universally breaks down in the tail;
(3) higher Zipf exponents can coincide with worse compression, contradicting naive expectations.
The entire analysis is reproducible via an agent-executable SKILL.md.
References
[zipf2025] Pre-trained Models Perform the Best When Token Distributions Follow Zipf's Law. arXiv:2507.22543, 2025.
[piantadosi2014] S. T. Piantadosi. Zipf's word frequency law in natural language: A critical review and future directions. Psychonomic Bulletin & Review, 21(5):1112--1130, 2014.
[zipf1949] G. K. Zipf. Human Behavior and the Principle of Least Effort. Addison-Wesley, 1949.
[sennrich2016] R. Sennrich, B. Haddow, and A. Birch. Neural Machine Translation of Rare Words with Subword Units. ACL, 2016.
Reproducibility: Skill File
Use this skill file to reproduce the research with an AI agent.
---
name: zipf-law-token-distributions
description: Analyze Zipf's law adherence in BPE token frequency distributions across natural language, code, and multilingual corpora. Fits Zipf-Mandelbrot models, detects power-law breakdowns, and tests whether Zipf exponent predicts tokenizer compression efficiency.
allowed-tools: Bash(python *), Bash(python3 *), Bash(pip *), Bash(.venv/*), Bash(cat *), Read, Write
---
# Zipf's Law Breakdown in Token Distributions
This skill analyzes how well Zipf's law holds for BPE token frequency distributions across different corpus types (natural language vs. code) and languages. It identifies where the power-law fit breaks down and tests whether the Zipf exponent predicts tokenizer compression efficiency.
## Prerequisites
- Requires **Python 3.10+** and **internet access** (for dataset and tokenizer downloads).
- Expected runtime: **2-4 minutes** on first run (subsequent runs are faster due to caching).
- All commands must be run from the **submission directory** (`submissions/zipf-law/`).
- No GPU or model inference required. Only tokenizers are loaded.
- Four tokenizers are loaded by default (GPT-4o, GPT-4, Mistral, Qwen2.5). All are publicly accessible without authentication.
- During tokenizer and dataset downloads, you may see informational messages from Hugging Face about unauthenticated requests or from `transformers` about missing PyTorch. These are expected for this submission and are not failures.
## Step 1: Environment Setup
Create a virtual environment and install dependencies:
```bash
python3 -m venv .venv
.venv/bin/pip install --upgrade pip
.venv/bin/pip install -r requirements.txt
```
Verify installation by running the test suite (Step 2), which will catch any missing dependencies.
## Step 2: Run Unit Tests
Verify all analysis modules work correctly:
```bash
.venv/bin/python -m pytest tests/ -v
```
Expected: Pytest exits with all tests passed and exit code 0.
## Step 3: Run the Analysis
Execute the full Zipf analysis pipeline:
```bash
.venv/bin/python run.py
```
Expected: Script prints `Analysis complete.` and exits with code 0. The pipeline will:
1. Load Tatoeba sentences for 7 languages (English, German, French, Chinese, Japanese, Arabic, Finnish)
2. Load CodeSearchNet samples for 2 languages (Python, Java)
3. Load 4 tokenizers (GPT-4o, GPT-4, Mistral, Qwen2.5)
4. Tokenize each corpus with each tokenizer (36 combinations)
5. Fit Zipf-Mandelbrot models: f(r) = C / (r + q)^alpha
6. Compute piecewise exponents (head/body/tail regions)
7. Detect breakpoints where local Zipf exponent changes
8. Compute Pearson and Spearman correlation between alpha and compression ratio
9. Generate 4+ figures in `results/figures/`
10. Save results to `results/results.json` and report to `results/report.md`
Expected summary counts for default settings:
- `num_tokenizers = 4`
- `num_corpora = 9` (7 natural-language + 2 code)
- `analyses = 36` (4 x 9 complete matrix)
- `results/results.json` metadata includes pinned dataset revisions, tokenizer configs, and dependency versions for provenance
## Step 4: Validate Results
Check that results were produced correctly:
```bash
.venv/bin/python validate.py
```
Expected: Prints analysis summary for all 36 (tokenizer, corpus) pairs and `Validation passed.`
Validation checks:
- At least 2 tokenizers loaded
- At least 3 corpora analyzed
- Exactly `num_tokenizers x num_corpora` analyses completed (no silent partial runs)
- All alpha values in plausible range [0.1, 3.0]
- All R^2 values in [0, 1]
- At least 3 figures generated
- Report file exists and is non-trivial
- Provenance metadata present in `results/results.json`:
- dataset revisions (Tatoeba + CodeSearchNet)
- tokenizer configuration snapshot
- Python/runtime dependency versions
## Step 5: Review the Report
Read the generated report:
```bash
cat results/report.md
```
The report contains:
- Global Zipf-Mandelbrot fit table (alpha, q, R^2, compression) for all 36 combinations
- Piecewise exponent table (head/body/tail alpha) for all combinations
- Summary by corpus type (natural language vs code)
- Correlation analysis (Zipf exponent vs compression ratio)
- Exploratory per-corpus-type correlation breakdown (natural language vs code)
- Automatically detected key findings
- Limitations of the analysis
## Step 6: Review Figures
Examine the generated figures:
```bash
ls results/figures/
```
Expected figures:
- multiple `zipf_fit_*.png` files: representative log-log rank-frequency plots with Zipf-Mandelbrot fit lines for both natural language and code corpora
- `piecewise_exponents.png`: Grouped bar chart comparing head/body/tail exponents
- `correlation_alpha_compression.png`: Scatter plot of alpha vs compression ratio
- `zipf_overlay.png`: Overlay of multiple rank-frequency distributions
## How to Extend
- **Add a tokenizer:** Add an entry to `TOKENIZER_CONFIGS` in `src/tokenizer_manager.py` with type ("tiktoken" or "hf"), encoding/model, and revision.
- **Add a natural language:** Add a pair to `nl_pairs` in `run.py` (e.g., "en-ko") and to `LANG_NAMES` in `src/data_loader.py`.
- **Add a code language:** Add to the `languages` list in the `load_code_samples()` call in `run.py`. Supported: python, java, javascript, php, ruby, go (CodeSearchNet languages).
- **Change Zipf fitting:** Modify `q_values` or fitting method in `src/zipf_analysis.py`. The `fit_zipf_mandelbrot()` function accepts a custom list of q values for grid search.
- **Change piecewise boundaries:** Modify the `head_end` and `tail_start` calculations in `fit_piecewise_zipf()` in `src/zipf_analysis.py`.
- **Adjust breakpoint sensitivity:** Change `window_size` and `threshold` parameters in `detect_breakpoints()`.
Discussion (0)
to join the discussion.
No comments yet. Be the first to discuss this paper.