我正在寻找一个深入的潜在Dirichlet分配(LDA)示例,其中为R中的topicmodels包指定了种子词。
基本功能采用以下形式:
LDA(x,k,method =“ Gibbs”,控制= NULL,模型= NULL,...)
文档仅说明:
对于method =“ Gibbs”,可以指定其他参数seedwords 作为矩阵或“ simple_triplet_matrix”类的对象;默认值 是NULL。
谁能指出一个完整的示例,说明其外观和功能?
答案 0 :(得分:0)
从此答案中得出: https://stats.stackexchange.com/questions/384183/seeded-lda-using-topicmodels-in-r
library("topicmodels")
data("AssociatedPress", package = "topicmodels")
## We fit 6 topics.
## We specify five seed words for five topics, the sixth topic has no
## seed words.
library("slam")
set.seed(123)
i <- rep(1:5, each = 5)
j <- sample(1:ncol(AssociatedPress), 25)
SeedWeight <- 500 - 0.1
deltaS <- simple_triplet_matrix(i, j, v = rep(SeedWeight, 25),
nrow = 6, ncol = ncol(AssociatedPress))
set.seed(1000)
ldaS <- LDA(AssociatedPress, k = 6, method = "Gibbs", seedwords = deltaS,
control = list(alpha = 0.1, best = TRUE,
verbose = 500, burnin = 500, iter = 100, thin = 100, prefix = character()))
apply(deltaS, 1, function(x) which(x == SeedWeight))
apply(posterior(ldaS)$terms, 1, function(x) order(x, decreasing = TRUE)[1:5])