Zipf’s law exercises
Extended practice, worked solutions, and transfer
← Back to the exercise catalogue · Back to the lesson checks
Zipf’s law
Preparation: the Zipf’s law lesson, text and data, and tokenization strategies.
Scope: eleven exercises cover rank-frequency calculations, log-log interpretation, lexical versus token units, rank uncertainty, fit quality, and competing explanations.
Calculate a frequency from rank
In a toy corpus, the word at rank 1 occurs 12,000 times. Assume Zipf’s law with \(\alpha=1\) is a reasonable approximation:
\[ f(r)=\frac{C}{r^\alpha}. \]
- What frequency does the model predict for the word at rank 4?
- What frequency does it predict for the word at rank 20?
- What ratio does the model predict between the frequencies at ranks 5 and 25?
- Are these values guaranteed to match observed frequencies in another corpus?
Show the solution
Here, \(C=f(1)=12,000\) and \(\alpha=1\), so \(f(r)=12,000/r\).
- Rank 4: \(12,000/4=3,000\) occurrences.
- Rank 20: \(12,000/20=600\) occurrences.
- Rank 25 is five times the rank of 5, so its predicted frequency is five times lower: \(f(5)=2,400\) and \(f(25)=480\).
- No. These are values from an approximation. Corpus size, domain, period, counting conventions, and empirical deviations from the law all affect observed frequencies.
Read the exponent from a log-log plot
Consider two synthetic points:
| Rank \(r\) | Frequency \(f(r)\) |
|---|---|
| 1 | 1,000 |
| 10 | 100 |
Assume these two points follow the model \(f(r)=C/r^\alpha\) exactly.
- Determine \(C\).
- Determine \(\alpha\).
- Write the relation after taking logarithms.
- What slope do we obtain by plotting \(\log f(r)\) against \(\log r\)?
Show the solution
At rank 1, \(f(1)=C=1,000\).
At rank 10:
\[ 100=\frac{1,000}{10^\alpha} \quad\Longrightarrow\quad 10^\alpha=10 \quad\Longrightarrow\quad \alpha=1. \]
Taking logarithms gives:
\[ \log f(r)=\log C-\alpha\log r. \]
The slope is therefore \(-\alpha=-1\). The intercept depends on \(C\) and on the chosen logarithm base.
Lexical frequencies and token frequencies
A corpus contains the word “unbelievable” 100 times. One tokenizer represents it as a single token; a different tokenizer splits it into several sub-tokens, for example “un”, “believ”, and “able”.
- Why is the rank of “unbelievable” in a lexical study not directly comparable to the rank of each of its sub-tokens?
- If a model predicts tokens, which units should be counted when studying the distribution of the units it predicts?
- Can the token-frequency distribution be derived from the word-frequency distribution alone?
Show the solution
- A lexical rank counts a word form as one unit. Sub-tokens are units defined by a tokenizer; occurrences of the same word may contribute to the frequencies of several sub-tokens.
- Count the units actually produced by the tokenizer being studied, on the specified corpus and with explicit preprocessing conventions.
- No. Segmentation depends on the tokenizer’s vocabulary and rules. The token-frequency distribution is therefore not identical to the lexical word-frequency distribution.
Does a log-log line prove a power law?
A rank-frequency plot looks approximately linear on logarithmic axes. A colleague concludes: “We have proved that language follows an exact Zipf law with exponent 1.”
- Which part of this conclusion is too strong?
- Why can estimating ranks and frequencies on the same sample create dependence between the two coordinates?
- What precaution can reduce this problem without removing every bias?
Show the solution
- An approximately straight line on a log-log plot is compatible with a power law over the observed range; it proves neither an exact law, a universal exponent of 1, nor a causal mechanism.
- A fluctuation that increases a word’s observed count raises its measured frequency and can also move it up the ranking. The two coordinates are therefore not estimated independently.
- Estimating ranks and frequencies on separate samples reduces this error correlation. It does not eliminate other biases, including those affecting exponent estimation and the long tail.
Empirical rank and probability rank
A vocabulary contains five lexical forms. The underlying probabilities (normally unknown in an ordinary study) and observed counts in a sample of 100 occurrences are provided here to construct a controlled example:
| Form | Underlying probability | Observed count |
|---|---|---|
| A | 0.40 | 34 |
| B | 0.30 | 38 |
| C | 0.15 | 15 |
| D | 0.10 | 9 |
| E | 0.05 | 4 |
Rank the forms by their underlying probabilities.
Rank them by their observed counts.
Does B ranking first in the sample prove that its true probability is higher than A’s?
Why does this matter when an estimator treats observed ranks as if they were the ranks of the underlying probabilities?
A more complex estimator reduces bias on synthetic data generated from a Zipf law, but gives variable results on real books. Can we conclude that it is better for every corpus?
Show the solution
Underlying ranking: A, B, C, D, E.
Empirical ranking: B, A, C, D, E.
No. Sampling produced a reversal between A and B. An observed ranking is a random statistic, not an exact revelation of the probability ordering.
Empirical ranks are themselves estimated from observed frequencies. Confusing them with probability ranks treats an uncertain ordering as known. Estimators built on that assumption can be biased, especially in the rare-word tail.
No. An estimator can perform well when data follow its assumed generative model, yet be unreliable when that model poorly describes real data. We must distinguish estimator bias under a given model from misspecification of the model itself.
This example is constructed for the exercise; it is not taken from a real corpus.
Does a good fit imply a universal exponent?
A study of spoken dialogue examines several units: word unigrams, bigrams, words by position within utterances, whole utterances, syntactic and pragmatic units, and some nonverbal channels. The authors report good fits to Zipf’s formula, but also find that the exponent \(\alpha\) varies across units and corpora.
- What does a goodness-of-fit measure such as \(R^2\) describe qualitatively? Why do the authors use it as a diagnostic rather than a universal criterion?
- What does the exponent \(\alpha\) describe in \(f(r)=C/r^\alpha\)?
- Why do comparable \(R^2\) values not show that all units follow the same distribution with the same exponent?
- Why should we avoid inferring one cognitive mechanism from this result?
Show the solution
- \(R^2\) quantifies, under the chosen fit, how much variation is described by the model. The authors treat it as a diagnostic: they set no universal threshold that alone decides whether a distribution “follows Zipf”. It does not measure causal validity.
- \(\alpha\) determines the slope in log-log coordinates and how quickly frequency decreases with rank.
- Two distributions can be described reasonably well by the same curve family while having different exponents. Fit quality and parameter value are distinct pieces of information.
- The fit describes a statistical regularity. The linguistic unit, corpus, and protocol influence the parameters; a causal mechanism requires independent predictions and tests.
Linders and Louwerse (2023) study the corpora and units they selected; they do not demonstrate universal invariance.
Compare a regularity with its explanations
Two studies propose different explanatory directions:
- Lestrade (2017) studies the interaction between syntactic class sizes and semantic specificity/reusability.
- Linders and Louwerse (2023) formulate a hypothesis that higher cognitive load may lead to more economical linguistic contributions and a larger exponent \(\alpha\).
Piantadosi’s (2014) critical review argues that no available account straightforwardly explains all the empirical facts or rests on sufficient independent evaluation.
Are these proposals the descriptive law itself, or hypotheses about its origin?
What experimental prediction follows from the cognitive-load hypothesis?
Why does Lestrade’s model compare syntax alone, semantics alone, and their combination?
Why does Piantadosi’s review invite us to present these proposals as competing or complementary models rather than an established explanation?
What further evidence would be needed before presenting either proposal as a general explanation?
In the semantic hypothesis, what does the trade-off between specificity and reusability mean?
Show the solution
They are explanatory proposals. The rank-frequency law describes an observed regularity; these studies investigate mechanisms that might produce it.
With unit and protocol held comparable, a condition imposing higher cognitive load should, under the hypothesis, produce a larger \(\alpha\). Corpus, sample-size, and task differences need to be controlled.
This comparison tests whether either ingredient is sufficient alone or whether their interaction is needed in the model being studied. The author reports that both combined are necessary within that framework.
Piantadosi notes that the observed regularities do not by themselves distinguish the proposed mechanisms and that no account convincingly covers all the facts reviewed. Lestrade’s and Linders–Louwerse’s proposals should therefore be presented as hypotheses with defined scope, not as a consensus.
We would need discriminating predictions, independent measures of the proposed variables, replications across corpora and tasks, and comparisons with competing explanations. Reproducing a curve is not enough.
A term that is too general poorly distinguishes referents; a term that is too specific applies to very few situations. The model proposes that a balance between discriminative power and reuse contributes to frequency. This is a hypothesis of the model, not a universal law.
These studies propose different frameworks; they do not establish one universally accepted explanation.
Compare French and English corpora without comparing whole languages
A study of child-directed speech reports the following results for two aggregated corpora:
| Corpus | Child age | Number of corpora | Word occurrences | Types | \(\alpha\) | \(\beta\) | Pearson \(r\) |
|---|---|---|---|---|---|---|---|
| British English | 2–42 months | 12 | 6,311,249 | 27,476 | 1.57 | 19.48 | 0.970 |
| French | 11–42 months | 8 | 1,540,284 | 19,327 | 1.53 | 17.98 | 0.990 |
Recall: TTR = number of types / number of occurrences. The Pearson \(r\) reported in the study correlates observed and model-expected frequencies; it is not the correlation between rank and frequency.
- Which corpus contains more occurrences and more types?
- Calculate the type-token ratio (TTR) for each corpus. Why is this ratio insufficient to conclude that French is lexically more diverse?
- The exponents \(\alpha\) are close. Can we infer that they are language-specific constants?
- Pearson’s correlation is higher for the French corpus. Can we conclude that it follows Zipf’s law “better”?
Show the solution
- The English corpus is larger and contains more types in absolute terms.
- English: \(27,476/6,311,249\approx0.00435\), or about \(0.44\%\). French: \(19,327/1,540,284\approx0.01255\), or about \(1.25\%\). Raw TTR depends strongly on text length: the corpora are not the same size or comparable-length samples. It cannot directly rank their lexical diversity.
- No. The parameters describe the distributions of these particular corpora in a child-directed-speech setting. They also depend on corpus size, composition and counting conventions.
- No. A high correlation proves neither an exact law nor a better fit under every criterion. These values do not suffice to compare languages in general.
Conclusion: these are two corpora from one study protocol, not two entire languages. A defensible comparison requires comparable corpora and sensitivity analyses for size and linguistic units.
Design a comparison of political speeches
You want to compare lexical distributions in French political-speech transcripts from two election campaigns. Corpus A contains 12 speeches and about 60,000 occurrences; corpus B contains 8 speeches and about 42,000 occurrences. The campaigns, dominant topics and transcription sources differ.
- Why would directly comparing type counts or estimated exponents be fragile?
- Define the counting conventions to fix before analysis: units, case, punctuation, apostrophes, lemmatization, proper names and quotations.
- Propose a protocol to limit the effects of length, topic, period and speaker.
- At which level should you resample to estimate uncertainty: occurrence, sentence or speech? Explain.
- Which conclusions would be unwarranted from a difference in \(\alpha\)?
Show the solution
- The corpora differ in size, number of speeches, topics and provenance. These factors can change frequencies without reflecting a stable difference in political style.
- Define one lexical unit consistently across both corpora. Document normalization, decide whether inflected forms remain distinct, and handle proper names, quotations, slogans and repeated segments consistently. Preserve the choices so the analysis can be reproduced.
- Compare subsets of similar length or use repeated subsampling at a fixed length (rarefaction); match or stratify speeches by period, topic and speaker; check sensitivity to repeated segments; publish metadata and exclusions. Do not remove function words without explaining how that changes the statistical object.
- The speech is usually the most defensible resampling (bootstrap) unit: occurrences within one speech are not independent and share a topic, speaker and context. Resampling individual occurrences could underestimate this dependence.
- A difference in \(\alpha\) proves neither an ideology, a persuasive strategy nor greater lexical richness. It describes a difference in rank-frequency concentration in these corpora under the chosen conventions. Further analyses are needed for linguistic or political interpretation.
Estimate parameters on a synthetic dataset
The following table contains rounded synthetic frequencies. It does not come from a real corpus.
| Rank \(r\) | Frequency \(f(r)\) |
|---|---|
| 1 | 261.2 |
| 2 | 204.3 |
| 3 | 167.2 |
| 5 | 121.8 |
| 10 | 71.4 |
| 20 | 38.1 |
| 50 | 15.2 |
| 100 | 7.3 |
We want to compare Zipf’s model \(f(r)=Cr^{-\alpha}\) with the Zipf-Mandelbrot model \(f(r)=C(r+\beta)^{-\alpha}\). Use a bounded nonlinear optimizer with \(C>0\), \(\alpha>0\) and \(\beta\geq0\); for reproducibility, initialize Zipf at \((C,\alpha)=(200,1)\) and Zipf-Mandelbrot at $(C,,)=(1,000,1,1).
- Fit both models by nonlinear least squares, minimizing the same sum of squared residuals on the raw frequencies.
- Record the estimated parameters and the sum of squared residuals for each model.
- Why should these results not be compared directly with a linear regression performed on logarithms?
- What does it mean that the second model recovers values close to \(C=1,200\), \(\alpha=1.1\) and \(\beta=3\)? Why is \(C\) not equal to \(f(1)\) when \(\beta>0\)?
Show the solution
With bounded nonlinear fitting on raw frequencies, the expected values are approximately:
| Model | Estimated parameters | Sum of squared residuals |
|---|---|---|
| Zipf | \(C\approx277.7\), \(\alpha\approx0.56\) | \(1,556.6\) |
| Zipf-Mandelbrot | \(C\approx1,201.5\), \(\alpha\approx1.101\), \(\beta\approx3.001\) | \(0.0016\) |
- Both fits must use the same objective function, here \(\sum_i(f_i-\hat f(r_i))^2\) on raw frequencies.
- Values may vary slightly with the optimizer, initial values and numerical tolerances. The Zipf-Mandelbrot fit recovers the parameters used to generate the data, up to rounding.
- Regression on logarithms minimizes errors in log space: it weights errors differently and does not minimize the same quantity. Estimated parameters therefore depend on the chosen objective.
- This synthetic dataset was generated from a Zipf-Mandelbrot law with those parameters. It checks that the fitting procedure can recover a known model in a controlled case; it does not prove that the model fits a real corpus. At rank 1, the denominator is (1 + β)^α, so the frequency is C/(1 + β)^α, not C. C remains a scale parameter.
Critique a fit before choosing a model
A team fits two models to the same corpus and rank range, using regression in log-log coordinates:
| Model | \(R^2\) on the fitting sample |
|---|---|
| Zipf | 0.997 |
| Zipf-Mandelbrot | 0.999 |
The team chooses Zipf-Mandelbrot and concludes that “language follows the Zipf-Mandelbrot law”.
- What does the difference in \(R^2\) actually show? Why can adding a parameter mechanically improve the in-sample fit?
- What should be examined in residuals as a function of rank?
- Why must the selected rank range be documented, with the long tail treated carefully?
- How can parameter stability and generalization be assessed?
- What cautious conclusion is appropriate if both models perform similarly on validation data?
Show the solution
- The increase in \(R^2\) only indicates that the second model describes the transformed data slightly better on this sample and under this objective. A more flexible model can improve fit without providing a better explanation or better predictions.
- Residual patterns by rank reveal systematic misspecification: unmodelled curvature, a slope break, or deviations concentrated in the first ranks or the tail. A single global \(R^2\) can hide these patterns.
- The first ranks and rare ranks have different levels of precision. Changing the selected range can change the parameters. State and justify the fitting range, and inspect sensitivity to rare ranks.
- Use uncertainty intervals, resampling methods that respect the corpus structure, and validation on texts or documents not used for fitting. Also check sensitivity to counting conventions and the objective function.
- If the out-of-sample gain is negligible, the simpler model may be preferable on grounds of parsimony. Report limitations and uncertainty rather than turning an empirical fit into a universal law.
Further reading
- Return to the Zipf’s law lesson.
- Compare with text data and tokenization strategies.
- Explore probability and information deep dives.
Sources used in these exercises
- Piantadosi (2014) — correlated errors and residual structure.
- Pilgrim & Hills (2021) — empirical rank, probability rank, and estimator bias.
- Linders & Louwerse (2023) — linguistic units and exponent variation.
- Lestrade (2017) — proposed syntax–semantics model.- Lavi-Rotbain and Arnon (2023) — multilingual child-directed-speech data used in the corpus-comparison exercise.