SciTech-BigDataAIML-Statistical Model-Topics Model主题模型-LDA(Latent Dirichilet Allocation, 潜在狄利克雷分布) Model

SciTech-BigDataAIML-Algorithm-Heuristic启发式-

Statistical Model(统计概率模型) 的一种
Topics Model(主题模型)

LDA(Latent Dirichilet Allocation) Topics Model主题模型。

LDA(Latent Dirichilet Allocation, 潜在狄利克雷分布)是一种 Topics Model(主题模型),
用于在Large Scale Docs(大量文档)自动发现Hidden Topics(隐藏主题)。
在NLP和Text Analysis上, LDA被广泛应用于文本分类、文档聚类、信息检索等场景。

LDA的核心思想

Doc(每篇文档) 看作由 Topics(多个主题)构成,
而 Topic(每个主题)又由 Terms(一组单词)按一定Distribution(概率分布)生成.

from gensim import corpora,models
#假设已经有文本数据
texts=[ ["human","interface","computer"],
        ["survey","user","computer","system","response"] ]

#创建词典和语料库
dictionary=corpora.Dictionary(texts)
corpus=[dictionary.doc2bow(text) for text in texts]

#使用LDA进行主题分析
lda_model=models.LdaModel(corpus, num_topics=2, id2word=dictionary, passes=10)
topics=lda_model.print_topics(num_words=3)
for topic in topics:
    print(topic)


得到Output(输出)

[(0, '0.177*"computer" + 0.176*"user" + 0.176*"survey"'),
 (1, '0.230*"computer" + 0.228*"interface" + 0.228*"human"')]

posted @ 2024-11-11 12:35  abaelhe  阅读(109)  评论(0)    收藏  举报