Pointwise Mutual Information › Worked Example: Computing PMI by Hand

Michael BrenndoerferUpdated March 21, 20263 min read
Language AI HandbookAll chapters
Part 3 of 67Distributional Semantics
Chapter 17Pointwise Mutual Information › Worked Example: Computing PMI by Hand
Reading section 6 of 13 · Worked Example: Computing PMI by Hand · 3 minSection 6 of 13 · 3 min

Book contents

Section 6 of 13 · 3 min read

Pointwise Mutual Information › Worked Example: Computing PMI by HandOne section · Sections in this chapter6 / 13 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Let's work through a small example to build intuition. Consider a tiny corpus of four sentences:

"The cat chases mice." "The dog chases cats." "Cats and dogs are common pets." "Mice fear cats."

Using a window size of 1 (immediate neighbors only), we count co-occurrences and compute PMI for the pair (cat, chases).

Suppose after counting we have:

  • count(cat,chases)=2\text{count}(\text{cat}, \text{chases}) = 2
  • count(cat)=4\text{count}(\text{cat}) = 4 (total number of co-occurrence events in which "cat" participates)
  • count(chases)=3\text{count}(\text{chases}) = 3 (total number of co-occurrence events in which "chases" participates)
  • N=20N = 20 (total co-occurrence events across all word pairs)

The estimated probabilities are:

P(cat,chases)=220=0.10P(cat)=420=0.20P(chases)=320=0.15\begin{aligned} P(\text{cat}, \text{chases}) &= \frac{2}{20} = 0.10 \\[4pt] P(\text{cat}) &= \frac{4}{20} = 0.20 \\[4pt] P(\text{chases}) &= \frac{3}{20} = 0.15 \end{aligned}

The expected joint probability under the independence assumption would be:

P(cat)⋅P(chases)=0.20×0.15=0.030P(\text{cat}) \cdot P(\text{chases}) = 0.20 \times 0.15 = 0.030

Computing PMI:

PMI(cat,chases)=log⁡20.100.030=log⁡23.33≈1.74\text{PMI}(\text{cat}, \text{chases}) = \log_2 \frac{0.10}{0.030} = \log_2 3.33 \approx 1.74

A PMI of 1.74 bits means "cat" and "chases" co-occur about 3.3 times more often than chance would predict. This represents a meaningful association: the corpus provides evidence that cats chase things.

Now compare this with the pair (the, chases). Suppose "the" appears so frequently that P(the)=0.25P(\text{the}) = 0.25, but co-occurs with "chases" only about as often as expected by chance. Under near-independence, the ratio is close to 1 and:

PMI(the,chases)=log⁡2P(the,chases)P(the)⋅P(chases)≈log⁡21.0=0\text{PMI}(\text{the}, \text{chases}) = \log_2 \frac{P(\text{the}, \text{chases})}{P(\text{the}) \cdot P(\text{chases})} \approx \log_2 1.0 = 0

PMI correctly reveals that "the" and "chases" have no special relationship, even though "the" may appear many times near "chases" in absolute terms.

Working Through the Count Formula

Let's also verify the count-based formula directly to make sure the algebra is clear. From the derivation above:

PMI(w,c)=log⁡2count(w,c)⋅Ncount(w)⋅count(c)\text{PMI}(w, c) = \log_2 \frac{\text{count}(w, c) \cdot N}{\text{count}(w) \cdot \text{count}(c)}

Plugging in the values from the (cat, chases) example:

PMI(cat,chases)=log⁡22×204×3=log⁡24012=log⁡23.33≈1.74\begin{aligned} \text{PMI}(\text{cat}, \text{chases}) &= \log_2 \frac{2 \times 20}{4 \times 3} \\[4pt] &= \log_2 \frac{40}{12} \\[4pt] &= \log_2 3.33 \\[4pt] &\approx 1.74 \end{aligned}

The count-based formula gives the same result as the probability-based formula, as expected. In code, you will typically use the count-based form because it avoids explicitly computing probabilities and works directly with the co-occurrence matrix.

Understanding the PPMI Conversion

Now suppose we also compute PMI for a pair with only one co-occurrence, where both words are relatively rare. Say count(w1,w2)=1\text{count}(w_1, w_2) = 1, count(w1)=2\text{count}(w_1) = 2, count(w2)=2\text{count}(w_2) = 2, and N=20N = 20:

PMI(w1,w2)=log⁡21×202×2=log⁡25≈2.32\begin{aligned} \text{PMI}(w_1, w_2) &= \log_2 \frac{1 \times 20}{2 \times 2} \\[4pt] &= \log_2 5 \\[4pt] &\approx 2.32 \end{aligned}

This PMI of 2.32 is higher than the (cat, chases) PMI of 1.74, even though the evidence is much thinner: a single co-occurrence vs. two. This illustrates the rare-word bias. PPMI retains this value as-is, which is why minimum count thresholds are important in practice.

And for a pair that never co-occurs, count(w,c)=0\text{count}(w, c) = 0:

PMI(w,c)=log⁡20⋅Ncount(w)⋅count(c)=log⁡20=−∞\text{PMI}(w, c) = \log_2 \frac{0 \cdot N}{\text{count}(w) \cdot \text{count}(c)} = \log_2 0 = -\infty

PPMI converts this to 0, handling the undefined case cleanly.