Skip to content
Part IA Lent Term

Heaps' Law

The Law

Heaps' Law: vocabulary size vs corpus size on linear and log-log scales showing slope beta

As a corpus grows, its vocabulary keeps growing, but with diminishing returns. No matter how much text you collect, you will always encounter new word types.

V=k×Nβ\lvert V \rvert = k \times N^\beta

  • V\lvert V \rvert: vocabulary size (number of unique types)
  • NN: total number of tokens in the corpus
  • β\beta: exponent, typically 0.4-0.6
  • kk: language-dependent constant, typically 30-100

Log-Log Estimation

Taking logs:

logV=log(k)+βlog(N)\log\lvert V \rvert = \log(k) + \beta \cdot \log(N)

Plot log(vocabulary size)\log(\text{vocabulary size}) against log(total tokens)\log(\text{total tokens}). The result is a straight line:

  • Slope = β\beta
  • Y-intercept = log(k)\log(k)

Why Growth Diminishes

When only 100 tokens have been seen, each new token is likely to be a new type. After 10,000 tokens, most new tokens are repeats of known words. After 1 million tokens, genuinely new types are rare. Yet mathematically, V\lvert V \rvert never plateaus: it grows as NβN^\beta, which is unbounded (albeit slowly).

With β=0.5\beta = 0.5: doubling NN increases V\lvert V \rvert by a factor of 20.51.412^{0.5} \approx 1.41. Quadrupling NN doubles V\lvert V \rvert.

Heaps’ Law and Zipf’s Law: The Connection

Zipf’s Law explains the shape of the frequency distribution (many rare words). Heaps’ Law explains the growth of vocabulary with corpus size (unbounded new types). Together they tell a single story: the tail of rare words is not only long but also inexhaustible. Collecting more data reduces but never eliminates the problem of unseen words.

Consequence for Classification

Smoothing is a mathematical necessity, not a pragmatic convenience. Heaps’ Law guarantees that:

  1. Any finite training corpus will have an incomplete vocabulary.
  2. New text will contain types never seen in training, regardless of training corpus size.
  3. Without smoothing, P(wc)=0P(w \mid c) = 0 for unseen words, collapsing all class probabilities to zero.

This is the theoretical justification for Laplace (add-one) smoothing: it assigns non-zero probability to the infinite set of possible but unseen word types by reserving a portion of the probability mass.

Summary

AspectDetail
Heaps’ LawV=k×Nβ\lvert V \rvert = k \times N^\beta
β\beta range0.4-0.6
kk range30-100
EstimationLeast-squares on log-log plot
ConsequenceVocabulary is effectively infinite; smoothing is mandatory

Past paper questions: y2024p3q7 (feature engineering)