MCPcopy Create free account
hub / github.com/Sirwenhao/Deep-Learning-Notes / ppmi

Function ppmi

NLP/Deep_Learning_Advanced_NLP/chap02_005_ppmi.py:5–21  ·  view source on GitHub ↗
(C, verbose=False, eps=1e-8)

Source from the content-addressed store, hash-verified

3
4
5def ppmi(C, verbose=False, eps=1e-8):
6 M = np.zeros_like(C, dtype=np.float32)
7 N = np.sum(C)
8 S = np.sum(C, axis=0)
9 total = C.shape[0] * C.shape[1]
10 cnt = 0
11
12 for i in range(C.shape[0]):
13 for j in range(C.shape[1]):
14 pmi = np.log2(C[i, j] * N / (S[j]*S[i]) + eps)
15 M[i, j] = max(0, pmi)
16
17 if verbose:
18 cnt += 1
19 if cnt % (total//100+1) == 0:
20 print('%.1f%% done' % (100*cnt/total))
21 return M
22
23

Callers 1

chap02_006_ppmi.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected