Created
September 9, 2021 01:33
-
-
Save rsimd/78da4d0a9b22c39209bf71be44c023c4 to your computer and use it in GitHub Desktop.
term-score for topic models, 間違いがあれば指摘してくれると助かります。
This file contains 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 | |
from scipy.special import softmax as np_softmax | |
def term_score(beta:np.array, dtype=np.float32) -> np.array: | |
"""reference: http://db-event.jpn.org/deim2011/proceedings/pdf/f4-1.pdf | |
""" | |
β = np.array(beta) | |
(K,V) = beta.shape | |
if not (K-0.3) < beta.sum() < (K+0.3): | |
β = np_softmax(beta, axis=-1) | |
logβ = np.log(β) | |
Z = (1/K) * np.sum(logβ, axis=0) | |
score = β * (logβ - Z) | |
return score.astype(dtype) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment