Created
April 18, 2026 20:01
-
-
Save paceaux/71d71f57b04beb592cca8a20460a0d6d to your computer and use it in GitHub Desktop.
Positive Pointwise Mutual Information
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def get_ppmi(term_terms): | |
| term_terms = np.array(term_terms) | |
| total = term_terms.sum() | |
| pxy = term_terms / total | |
| px = pxy.sum(axis=1, keepdims=True) | |
| py = pxy.sum(axis=0, keepdims=True) | |
| dot = px.dot(py) | |
| pxy_dot = pxy / dot | |
| ppmi = np.log2(pxy / dot).clip(0) | |
| return ppmi | |
| tts = [[0,0,0,1], [0,0,9,0], [0,9,0,0], [1,0,0,0]] | |
| ppmi = get_ppmi(tts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment