Skip to content

Instantly share code, notes, and snippets.

@paceaux
Created April 18, 2026 20:01
Show Gist options
  • Select an option

  • Save paceaux/71d71f57b04beb592cca8a20460a0d6d to your computer and use it in GitHub Desktop.

Select an option

Save paceaux/71d71f57b04beb592cca8a20460a0d6d to your computer and use it in GitHub Desktop.
Positive Pointwise Mutual Information
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