0

正如我经常提到的,我在 230k 文档上使用 text2vec。我试图通过使用困惑来为我的文档术语矩阵找到最佳主题编号。当我一个一个地使用它时,它工作得非常好,但是当我尝试使用循环来获取它的范围从 2 到 25 时它不起作用,我不知道为什么,有人可以告诉我什么是错误的?

##Using perplexity for hold out set
t1 <- Sys.time()
perplex <- c()
for (i in 2:25){

  set.seed(17)

    lda_model <- LDA$new(n_topics = i)
    doc_topic_distr <- lda_model$fit_transform(x = dtm,  progressbar = F)

    perplex[i]  <- text2vec::perplexity(sample.dtm, topic_word_distribution = 
    lda_model$topic_word_distribution, doc_topic_distribution = new_doc_topic_distr) 
}
print(difftime(Sys.time(), t1, units = 'sec'))

INFO [2019-10-23 13:01:43] early stopping at 80 iteration
INFO [2019-10-23 13:01:45] early stopping at 20 iteration
INFO [2019-10-23 13:01:53] early stopping at 70 iteration
INFO [2019-10-23 13:01:55] early stopping at 20 iteration
Error in text2vec::perplexity(sample.dtm, topic_word_distribution = lda_model$topic_word_distribution,  : 
  nrow(topic_word_distribution) == ncol(doc_topic_distribution) is not TRUE
4

1 回答 1

0

new_doc_topic_distr这是因为您需要在循环内重新计算

于 2019-10-27T11:01:49.043 回答