def plsa_model title lda_model lda_dict num_topics title np array lda_

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def plsa_model(title, lda_model, lda_dict, num_topics):
title = np.array([lda_dict.token2id[x] for x in title.split() if x in lda_dict.token2id])
F = lda_model.state.sstats.T
Nt, Nd = np.zeros(num_topics), 0.0
for w in title:
ndwt = F[w] * 0.01
q = ndwt.sum()
ndwt /= q
Nd += q
Nt += ndwt
return np.argmax(Nt)
plsa_model = functools.partial(plsa_model, lda_model=lda_model, lda_dict=lda_dict, num_topics=100)
def new_ldazation(title, lda_model, lda_dict):
title = np.array([lda_dict.token2id[x] for x in title.split() if x in lda_dict.token2id])
if title.any():
q = lda_model.state.sstats.T[title]
q = (q.T / q.sum(axis=1)).T
return np.argmax(q.sum(axis=0))
return -1
new_ldazation = functools.partial(new_ldazation, lda_model=lda_model, lda_dict=lda_dict)