【发布时间】:2016-03-29 12:45:46
【问题描述】:
我现在正在使用 LDA(潜在狄利克雷分配)主题建模方法来帮助从一组文档中提取主题。根据我从下面的链接中了解到的情况,这是一种无监督学习方法,可以使用提取的主题对每个文档进行分类/标记。
Topic extraction with Non-negative Matrix Factorization and Latent Dirichlet Allocation
在该链接中给出的示例代码中,定义了一个函数来获取与所识别的每个主题相关联的热门单词。
sklearn.__version__
输出[41]:'0.17'
from sklearn.decomposition import LatentDirichletAllocation
def print_top_words(model, feature_names, n_top_words):
for topic_idx, topic in enumerate(model.components_):
print("Topic #%d:" % topic_idx)
print(" ".join([feature_names[i]
for i in topic.argsort()[:-n_top_words - 1:-1]]))
print()
print("\nTopics in LDA model:")
tf_feature_names = tf_vectorizer.get_feature_names()
print_top_words(lda, tf_feature_names, n_top_words)
我的问题是这样的。是否有构建模型 LDA 的任何组件或矩阵,我们可以从中获得 文档-主题关联?
例如,我需要找到与每个文档关联的前 2 个主题作为该文档的文档标签/类别。是否有任何组件可以查找文档中的主题分布,类似于 model.components_ 用于查找主题中的单词分布。
【问题讨论】:
标签: python python-2.7 scikit-learn lda topic-modeling