R LDA主题模型如何获得Delta的后验



i使用r软件包主题模式运行了lda,我一直在尝试获取delta的值,在我理解的是,这是dirichlet的dirichlet参数for topics the Topics。但是,我无法访问该值。我只设法使用

获得初始值
LDA@control@delta

slot(LDA@control,"delta")

我知道如何获取后部分布的alpha(文档上的dir的参数),这只是slot(LDA,"alpha"),但是如何获得delta?

非常感谢!

topicmodels使用用于采样方法的控制参数列表,此处是gibbs采样。alpha = 50/kdelta = 0.1的默认值在control_LDA_Gibbs中假设 - 当然,您可以指定其他值。也许您尚未正确指定控件。无论如何,这里是代码的简短示例,该示例应在输出中信息中信息。我希望这有助于解决您的问题。

library(text2vec)
library(topicmodels)
library(slam) #to convert dtm to simple triplet matrix for topicmodels
ntopics <- 10
alphaprior <- 0.1
deltaprior <- 0.001
niter <- 1000
seedpar <- 0 
docssubset <- 1:500
docs <- movie_review$review[docssubset]
#Generate document term matrix with text2vec    
tokens = docs %>% 
  tolower %>% 
  word_tokenizer
it = itoken(tokens, ids = movie_review$id[docssubset], progressbar = FALSE)
vocab = create_vocabulary(it) %>%
  prune_vocabulary(term_count_min = 10, doc_proportion_max = 0.2)
vectorizer = vocab_vectorizer(vocab)
dtm = create_dtm(it, vectorizer, type = "dgTMatrix")
control_Gibbs_topicmodels <- list(
                            alpha = alphaprior
                            ,delta = deltaprior 
                            ,iter = niter
                            ,burnin = 100                           
                            ,keep = 50
                            ,nstart = 1
                            ,best = TRUE
                            ,seed = seedpar
)

ldatopicmodels <- LDA(as.simple_triplet_matrix(dtm)
                      ,k = ntopics
                      ,method = "Gibbs"
                      ,control = control_Gibbs_topicmodels 
                      )
str(ldatopicmodels)
ldatopicmodels@control@delta

相关内容

  • 没有找到相关文章

最新更新