2017-03-15 7 views
2

私はRパッケージtopicmodelsを使ってLDAを実行しました。私は、私の理解では、トピックに対する単語のディリクレのパラメータであるデルタの値を取得しようとしています。しかし、私は値にアクセスすることができませんでした。 私は単にslot(LDA,"alpha")あるR LDAトピックモデルデルタの後ろを取得する方法

[email protected]@delta 

または

slot([email protected],"delta") 

を使用して初期値Iは、事後分布のためにアルファ(書類を超える話題のためのDirのパラメータ)を取得する方法を知っているし、得ることができたが、どのようにデルタを取得するのですか?

ありがとうございます!

答えて

0

topicmodelsは、サンプリング方法の制御パラメータのリストを使用します(ここではGibbsサンプリング)。デフォルトでは、alpha = 50/kdelta = 0.1の値がcontrol_LDA_Gibbsと仮定されています。もちろん、他の値を指定することもできます。あなたのコントロールを正しく指定していない可能性があります。いずれにしても、出力のdeltapriorに関する情報を示すコードの短い例をここに示します。私はあなたの問題を解決し、解決することを願っています。

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) 

[email protected]@delta 
関連する問題