Latent Dirichlet Allocation(LDA)是一个在文本建模中很著名的模型,可以用于浅层语义分析,在文本聚类中是一个很有用的模型。即在仅观察到文档词语的条件下,挖掘出文本所属的主题等一系列信息。
要求:读取属于2个主题的多篇文章,进行相关分析。
一、 数据
本实验数据取自30篇论文的摘要部分,这些论文的主题为co-clustering或者CCA。用这30个txt文件生成语料库。
二、 实验过程、结果与分析
2.1 topic-word矩阵
其余部分省略。每个词下方的第1行表示cluster 1,第2行表示cluster 2,显示了词属于不同主题的可能性。
2.2 聚类结果
Gibbssampling中设置了两个cluster,其中document[1]属于cluster 1的可能性远大于属于cluster 2的可能性,而document [22]则属于cluster 1和cluster 2的可能性大致相等。
三、 参考文献
[1]Rickjin. LDA数学八卦
[2]lda(主题模型)R语言
附录:源码(R程序 lda.R)
##加载lda包
library(lda)
##---读取30个文档到docs----取自30篇论文的摘要,来自co-clustering和CCA两个主题
D <- 30
d1 = readLines("d1.txt")
d2 = readLines("d2.txt")
d3 = readLines("d3.txt")
d4 = readLines("d4.txt")
d5 = readLines("d5.txt")
d6 = readLines("d6.txt")
d7 = readLines("d7.txt")
d8 = readLines("d8.txt")
d9 = readLines("d9.txt")
d10 = readLines("d10.txt")
d11 = readLines("d11.txt")
d12 = readLines("d12.txt")
d13 = readLines("d13.txt")
d14 = readLines("d14.txt")
d15 = readLines("d15.txt")
d16 = readLines("d16.txt")
d17 = readLines("d17.txt")