Skip to content
Part IA Lent Term

Zipf's Law

The Law

Zipf's Law: word frequency vs rank on both linear and log-log scales showing slope -alpha

Word frequency is inversely proportional to frequency rank. A small number of words are very frequent; a huge number of words are rare.

Basic form:

fw1rwf_w \propto \frac{1}{r_w}

where fwf_w is the frequency of word ww and rwr_w is its rank (1 = most frequent).

General form:

fwk(rw+β)αf_w \approx \frac{k}{(r_w + \beta)^\alpha}

  • fwf_w: frequency of word ww in the corpus
  • rwr_w: frequency rank (1 = most frequent)
  • α\alpha: exponent (~1.0 for English, ~1.3 for German)
  • kk, β\beta: language-specific constants

Log-Log Estimation

Taking logs of the basic form:

log(fw)=log(k)αlog(rw)\log(f_w) = \log(k) - \alpha \cdot \log(r_w)

Plotting log(frequency)\log(\text{frequency}) against log(rank)\log(\text{rank}) gives a straight line:

  • Slope = α-\alpha (estimate α\alpha from the slope)
  • Y-intercept = log(k)\log(k) (estimate k=einterceptk = e^{\text{intercept}})

Estimate α\alpha and kk by fitting a least-squares regression to the log-log plot.

The Long Tail

In a typical English corpus:

  • The top 10 words (the, of, and, to, a, …) account for ~25% of all tokens.
  • The top 100 words account for ~50%.
  • Thousands of words appear only once (hapax legomena).
  • The tail is very long: a huge number of word types each appear very few times.

Consequence for Classification

The long tail means that even a large training corpus misses many word types. Any new document is likely to contain words never seen during training. For a Naive Bayes classifier without smoothing:

P(wc)=count(w,c)wcount(w,c)=0for any unseen wP(w \mid c) = \frac{\text{count}(w, c)}{\sum_{w'} \text{count}(w', c)} = 0 \quad \text{for any unseen } w

A single unseen word makes the entire product P(c)×P(wic)P(c) \times \prod P(w_i \mid c) equal to zero. The classifier breaks.

This is why Laplace smoothing is not optional — Zipf’s Law guarantees that unseen words are ubiquitous, not rare exceptions.

Worked Example

Consider “the” (rank 1, frequency ~70,000 per million words) and “antidisestablishmentarianism” (estimated rank ~50,000, frequency < 1 per million). The ratio is roughly 70,000:1, consistent with α1\alpha \approx 1.

If a test document uses a rare word not in the training data (and there are tens of thousands of such words in the long tail), the unsmoothed NB classifier assigns probability zero to every class. Smoothing fixes this by shifting a small amount of probability mass from frequent words to the long tail.

Summary

AspectDetail
Basic Zipffw1/rwf_w \propto 1/r_w
General formfw=k/(rw+β)αf_w = k / (r_w + \beta)^\alpha
α\alpha (English)~1.0
α\alpha (German)~1.3
EstimationLeast-squares on log-log plot
Consequence for NBLong tail of unseen words kills unsmoothed classifier

Past paper questions: y2024p3q7 (feature engineering sub-question)