Python Gensim困惑分数增加

Python Gensim困惑分数增加,python,python-3.x,gensim,lda,perplexity,Python,Python 3.x,Gensim,Lda,Perplexity,我试图计算Spyder中不同主题数量的困惑分数,以便使用gensim找到最佳模型参数 然而,困惑分数并没有像预期的那样下降[1]。 此外,似乎有更多的人遇到了这个问题,但据我所知,没有解决办法 有人知道如何解决这个问题吗 代码: 为什么你认为在你的情况下困惑会开始减少?我认为这个问题在很大程度上属于论坛,是重复的 X_train, X_test = train_test_split(corpus, train_size=0.9, test_size=0.1, random_state=1) t

我试图计算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, X_test, dictionary, 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