简体   繁体   English

使用 ldamulticore 确定 log_perplexity 以获得最佳主题数

[英]Determining log_perplexity using ldamulticore for optimum number of topics

I am trying to determine the optimum number of topics for my LDA model using log perplexity in python.我正在尝试使用 python 中的日志困惑来确定我的 LDA 模型的最佳主题数。 That is, I am graphing the log perplexity for a range of topics and determining the minimum perplexity.也就是说,我正在绘制一系列主题的日志困惑度并确定最小困惑度。 However, the graph I have obtained has negative values for log perplexity, when it should have positive values between 0 and 1.但是,我获得的图表对 log perplexity 具有负值,当它应该具有介于 0 和 1 之间的正值时。

#calculating the log perplexity per word as obtained by gensim code 
##https://radimrehurek.com/gensim/models/atmodel.html
#parameters: pass in trained corpus
#return: graph of perplexity per word for varying number of topics
parameter_list = range(1, 500, 100)
grid ={}

for parameter_value in parameter_list:
model = models.LdaMulticore(corpus=corpus, workers=None, id2word=None, 
                            num_topics=parameter_value, iterations=10)
grid[parameter_value]=[]

perplex=model.log_perplexity(corpus, total_docs=len(corpus))
grid[parameter_value].append(perplex)


df = pd.DataFrame(grid)
ax = plt.figure(figsize=(7, 4), dpi=300).add_subplot(111)
df.iloc[0].transpose().plot(ax=ax,  color="#254F09")
plt.xlim(parameter_list[0], parameter_list[-1])
plt.ylabel('Perplexity')
plt.xlabel('topics')
plt.show()     

The perplexity must be between 0 and 1. What you are computing is the log -perplexity.困惑度必须介于 0 和 1 之间。您正在计算的是对困惑度。 It is negative because the logarithm of a number in the (0,1) range is below zero.它是负数,因为 (0,1) 范围内的数字的对数低于零。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM