小编Bal*_*ala的帖子

主题建模 - 将具有前2个主题的文档指定为类别标签 - sklearn Latent Dirichlet Allocation

我现在正在通过LDA(Latent Dirichlet Allocation)主题建模方法来帮助从一组文档中提取主题.从我从下面的链接中理解的,这是一种无监督的学习方法,用提取的主题对每个文档进行分类/标记.

非负矩阵分解和潜在Dirichlet分配的主题提取

在该链接中给出的示例代码中,定义了一个函数来获取与所识别的每个主题相关联的顶部单词.

sklearn.__version__
Run Code Online (Sandbox Code Playgroud)

出[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)
Run Code Online (Sandbox Code Playgroud)

我的问题是这个.是否有构建模型LDA的任何组件或矩阵,我们可以从哪里获得文档主题关联

例如,我需要找到与每个文档关联的前2个主题作为该文档的文档标签/类别.是否有任何组件可以在文档中查找主题分布,类似于在主题中 model.components_查找单词分布.

python python-2.7 lda topic-modeling scikit-learn

9
推荐指数
1
解决办法
3337
查看次数

标签 统计

lda ×1

python ×1

python-2.7 ×1

scikit-learn ×1

topic-modeling ×1