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 (将#修改为@)