in hypernymysuite/pattern.py [0:0]
def __init__(self, patterns_filename):
# first read in the normal stuff
super(PPMIModel, self).__init__(patterns_filename)
# now let's transform the matrix
tr_matrix = sparse.dok_matrix(self.matrix.shape)
# actually do the transformation
for (l, r) in self.matrix.keys():
pmi_lr = (
np.log(self.N)
+ np.log(self.matrix[(l, r)])
- np.log(self.p_w[l])
- np.log(self.p_c[r])
)
# ensure it's /positive/ pmi
ppmi_lr = np.clip(pmi_lr, 0.0, 1e12)
tr_matrix[(l, r)] = ppmi_lr
self.matrix = tr_matrix