我试图复制您的问题,但在我的情况下(使用非常小的语料库),我找不到这三个总和之间的任何区别。
如果其他人想要复制问题,我仍然会分享我尝试过的路径;-)
我使用了 gensim 网站上的一些小例子,并训练了三种不同的 LDA 模型:
from gensim import corpora, models
texts = [['human', 'interface', 'computer'],
['survey', 'user', 'computer', 'system', 'response', 'time'],
['eps', 'user', 'interface', 'system'],
['system', 'human', 'system', 'eps'],
['user', 'response', 'time'],
['trees'],
['graph', 'trees'],
['graph', 'minors', 'trees'],
['graph', 'minors', 'survey']]
dictionary = corpora.Dictionary(texts)
corpus = [dictionary.doc2bow(text) for text in texts]
lda_sym = models.ldamodel.LdaModel(corpus=corpus, id2word=dictionary, num_topics=10, update_every=1,
chunksize =100000, passes=1, alpha='symmetric')
lda_asym = models.ldamodel.LdaModel(corpus=corpus, id2word=dictionary, num_topics=10, update_every=1,
chunksize =100000, passes=1, alpha='asymmetric')
lda_auto = models.ldamodel.LdaModel(corpus=corpus, id2word=dictionary, num_topics=10, update_every=1,
chunksize =100000, passes=1, alpha='auto')
现在我总结所有文档的主题概率(总共 9 个文档)
counts = {}
for model in [lda_sym, lda_asym, lda_auto]:
s = 0
for doc_n in range(len(corpus)):
s += pd.DataFrame(lda_sym[corpus[doc_n]])[1].sum()
if s < 1:
print('Sum smaller than 1 for')
print(model, doc_n)
counts[model] = s
事实上总和总是 9:
counts = {<gensim.models.ldamodel.LdaModel at 0x7ff3cd1f3908>: 9.0,
<gensim.models.ldamodel.LdaModel at 0x7ff3cd1f3048>: 9.0,
<gensim.models.ldamodel.LdaModel at 0x7ff3cd1f3b70>: 9.0}
当然这不是一个有代表性的例子,因为它太小了。因此,如果可以,也许可以提供有关您的语料库的更多详细信息。
一般来说,我认为应该始终如此。我的第一个直觉是空文档可能会改变总和,但事实并非如此,因为空文档只会产生与 alpha 相同的主题分布(这是有道理的):
pd.DataFrame(lda_asym[[]])[1]
返回
0 0.203498
1 0.154607
2 0.124657
3 0.104428
4 0.089848
5 0.078840
6 0.070235
7 0.063324
8 0.057651
9 0.052911
与
相同
lda_asym.alpha
array([ 0.20349777, 0.1546068 , 0.12465746, 0.10442834, 0.08984802,
0.0788403 , 0.07023542, 0.06332404, 0.057651 , 0.05291085])
总和为 1。
从理论的角度来看,选择不同的 alpha 将产生完全不同的 LDA 模型。
Alpha 是 Dirichlet 先验的超参数。 Dirichlet 先验是我们从中得出 theta 的分布。而theta成为决定主题分布形状的参数。所以本质上,alpha 影响我们绘制主题分布的方式。这就是为什么选择不同的 alpha 也会给你带来稍微不同的结果
lda.show_topics()
但我不明白为什么对于任何 LDA 模型或任何类型的文档,文档概率的总和应该不同于 1。