如何解决Gensim困惑度得分提高
我正在尝试针对不同数量的主题在Spyder中计算困惑度得分,以便通过gensim找到最佳的模型参数。
但是,困惑度得分并没有像[1]那样下降。 此外,似乎有更多的人遇到了这个确切的问题,但据我所知没有解决方案。
有人对解决问题有任何想法吗?
代码:
X_train,X_test = train_test_split(corpus,train_size=0.9,test_size=0.1,random_state=1)
topic_range = [10,20,25,30,40,50,60,70,75,90,100,150,200]
def lda_function(X_train,X_test,dictionary,nr_topics):
ldamodel2 = gensim.models.LdaModel(X_train,id2word=dictionary,num_topics=nr_topics,alpha='auto',eta=0.01,passes=10
iterations=500,random_state=42)
return 2**(-1*ldamodel2.log_perplexity(X_test))
log_perplecs = [lda_function(X_train,nr_topics=topic) for topic in topic_range]
print("\n",log_perplecs)
fig1,ax1 = plt.subplots(figsize=(7,5))
ax1.scatter(x=topic_range,y=log_perplecs)
fig1.tight_layout()
fig1.savefig(output_directory + "Optimal Number of Topics (Perplexity Score).pdf",bbox_inches = 'tight')```
[1]: https://i.stack.imgur.com/jFiF1.png
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。