Pointwise Mutual Information › Worked Example: Computing PMI by Hand
Language AI HandbookAll chapters 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:
- (total number of co-occurrence events in which "cat" participates)
- (total number of co-occurrence events in which "chases" participates)
- (total co-occurrence events across all word pairs)
The estimated probabilities are:
The expected joint probability under the independence assumption would be:
Computing PMI:
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 , but co-occurs with "chases" only about as often as expected by chance. Under near-independence, the ratio is close to 1 and:
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:
Plugging in the values from the (cat, chases) example:
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 , , , and :
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, :
PPMI converts this to 0, handling the undefined case cleanly.