我試圖複製你的問題,但在我的情況(使用非常小的語料庫),我找不到三個總和之間的任何區別。
我依然會分享我的情況下,任何人嘗試過的路徑要複製我使用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}
當然這不是一個代表性的例子,因爲它太小了。所以如果可以的話,也許提供一些關於你的語料庫的更多細節。
總的來說,我會認爲這應該總是如此。我的第一直覺是,也許空的文件會改變的總和,但也並非如此,因爲空文件只是產生一個主題分佈相同的阿爾法(這是有道理的):
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成爲決定主題分佈的形狀的參數。所以基本上,alpha影響我們如何繪製主題分佈。這就是爲什麼選擇不同的阿爾法也會給你稍有不同的結果
lda.show_topics()
但我不明白爲什麼在文檔概率總和應爲1差異,任何LDA模型或任何類型的文檔。