text analysis
pointwise mutual information
natural language processing
NLP
computational linguistics

Pointwise mutual information on text

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Pointwise mutual information (PMI) is a measure used in information theory and natural language processing to quantify the association between two random events. In the context of text analysis, PMI is particularly useful for identifying the strength of association between words or phrases within a corpus. This metric helps in understanding how much the presence of one word tells us about the presence of another, relative to a baseline of their independent occurrences.

Technical Explanation

PMI between two words, w1w_1 and w2w_2, is defined mathematically as:

PMI(w_1,w_2)=logP(w_1,w_2)P(w_1)P(w_2)\text{PMI}(w\_1, w\_2) = \log \frac{P(w\_1, w\_2)}{P(w\_1) \cdot P(w\_2)}

P(w1,w2)P(w_1, w_2) is the joint probability of both words occurring together. • P(w1)P(w_1) and P(w2)P(w_2) are the individual probabilities of each word occurring independently.

In practice, these probabilities are often estimated from a corpus:

P(w1)P(w_1) is calculated as the frequency of w1w_1 divided by the total number of words in the corpus. • P(w1,w2)P(w_1, w_2) is calculated as the frequency of the two words occurring together, divided by the total number of word pairs.

Interpretation

Positive PMI: Indicates that the two words co-occur more frequently than would be expected by chance. • Zero PMI: Suggests that the words co-occur at a rate that is expected by chance. • Negative PMI: Implies that the words co-occur less frequently than would be expected by chance.

High PMI values can be indicative of collocations or common expressions, while low (or negative) PMI values may suggest some degree of independent behavior between the words.

Considerations

  1. Sparsity: PMI can be sensitive to low-frequency events. Words that appear rarely may result in extreme PMI values.
  2. Normalization: Variants like normalized PMI (NPMI) attempt to adjust PMI values within the range of -1 and 1 for easier interpretation:
    NPMI(w_1,w_2)=PMI(w_1,w_2)logP(w_1,w_2)\text{NPMI}(w\_1, w\_2) = \frac{\text{PMI}(w\_1, w\_2)}{-\log P(w\_1, w\_2)}

Example

Consider a small corpus:

• "cat and dog" • "cat and mouse" • "dog barks" • "mouse and cheese"

Calculate the PMI for the word pair "cat" and "dog":

  1. Total Word Count = 11
  2. Frequency of "cat" = 2
  3. Frequency of "dog" = 2
  4. Frequency of "cat and dog" = 1
  5. P(cat)=211P(\text{cat}) = \frac{2}{11}
  6. P(dog)=211P(\text{dog}) = \frac{2}{11}
  7. P(cat and dog)=111P(\text{cat and dog}) = \frac{1}{11}
  8. PMI(cat, dog)=log111211211=log141210.97\text{PMI}(\text{cat, dog}) = \log \frac{\frac{1}{11}}{\frac{2}{11} \cdot \frac{2}{11}} = \log \frac{1}{\frac{4}{121}} \approx 0.97

Applications

  1. Collocation Extraction: PMI is a standard statistical measure for identifying collocations in texts, such as "New York" or "natural language."
  2. Sentiment Analysis: In sentiment analysis, PMI can help in assessing the sentiment association between words.
  3. Information Retrieval: It assists in retrieving documents where certain word pairs are more likely to appear together, enhancing relevancy.

Limitations

Bias Towards Rare Events: PMI tends to favor infrequent but coincidental word pairs, requiring careful handling, especially in large corpora. • Absolute Values: High absolute values can be misleading, especially if the words involved are of low frequency.

Summary Table

AspectExplanation/Value
FormulaPMI(x,y)=logP(x,y)P(x)P(y)\text{PMI}(x, y) = \log \frac{P(x, y)}{P(x) \cdot P(y)}
Range-\infty to \infty
Positive ValueIndicative of association
Zero ValueIndicative of independence
Negative ValueIndicative of repulsion
NormalizationNPMI adjusts within -1 to 1 range: NPMI(x,y)=PMI(x,y)logP(x,y)\text{NPMI}(x, y) = \frac{\text{PMI}(x, y)}{-\log P(x, y)}
ApplicationsCollocation detection, Sentiment analysis, Information retrieval
LimitationsSensitivity to rare events

In conclusion, pointwise mutual information is a versatile and informative metric utilized in various fields of text analysis. It is crucial to consider both its strengths in identifying meaningful associations and its potential limitations due to rare word occurrences, ensuring that results are both accurate and applicable.


Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.