主题模块 - 计算Sklearn LDA模型的相干得分?

发布于 2025-01-19 07:27:43 字数 657 浏览 0 评论 0原文

我尝试了几种方法来计算 sklearn LDA 模型的一致性分数,但没有成功。计算 sklearn LDA 模型的一致性分数的方法是什么?

当我使用标准 gensim 代码计算一致性分数时,我收到以下错误: ValueError:当前不支持此主题模型。支持的主题模型应该实现 get_topics 方法。```

这是我的代码的一部分:

count_vectorizer = CountVectorizer(stop_words='english')

  # Fit and transform the processed titles

count_data = count_vectorizer.fit_transform(training_data_preprocessed['Input'])
tf = count_data




number_topics = 5
number_words = 5

# Create and fit the LDA model
lda = LDA(n_components=number_topics)
lda.fit(tf)

# Print the topics found by the LDA model
print("Topics found via LDA:")
print_topics(lda, count_vectorizer, number_words)

I tried several things to calculate the coherence score for a sklearn LDA model, but it does not work out. What is a way to calculate the Coherence score for a sklearn LDA model?

When I use the standard gensim code to calculate the coherence score, I receive the following error: ValueError: This topic model is not currently supported. Supported topic models should implement the get_topics method.```

Here is part of my code:

count_vectorizer = CountVectorizer(stop_words='english')

  # Fit and transform the processed titles

count_data = count_vectorizer.fit_transform(training_data_preprocessed['Input'])
tf = count_data




number_topics = 5
number_words = 5

# Create and fit the LDA model
lda = LDA(n_components=number_topics)
lda.fit(tf)

# Print the topics found by the LDA model
print("Topics found via LDA:")
print_topics(lda, count_vectorizer, number_words)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铃予 2025-01-26 07:27:43

我认为您可以使用下面的代码来实现 LDA 中的一致性模型:

# import library from gensim  
from gensim.models import CoherenceModel

# instantiate topic coherence model
cm = CoherenceModel(model=lda_model_15, corpus=bow_corpus, texts=docs, coherence='c_v')

# get topic coherence score
coherence_lda = cm.get_coherence() 
print(coherence_lda)

I think you can use this code below for coherence model in LDA:

# import library from gensim  
from gensim.models import CoherenceModel

# instantiate topic coherence model
cm = CoherenceModel(model=lda_model_15, corpus=bow_corpus, texts=docs, coherence='c_v')

# get topic coherence score
coherence_lda = cm.get_coherence() 
print(coherence_lda)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文