我正在使用text2vec
包中的 LDA,并且很困惑为什么使用相同的数据时fit_transfrom
和是不同的。transform
文档指出,transform 将学习模型应用于新数据,但结果与生成的模型有很大不同fit_transform
data("movie_review")
library(stringr)
library(text2vec)
library(dpylr)
tokens = movie_review$review[1:4000] %>%
tolower %>%
word_tokenizer
it = itoken(tokens, ids = movie_review$id[1:4000], progressbar = FALSE)
v = create_vocabulary(it) %>%
prune_vocabulary(term_count_min = 10, doc_proportion_max = 0.2)
vectorizer = vocab_vectorizer(v)
dtm = create_dtm(it, vectorizer, type = "dgTMatrix")
lda_model = LDA$new(n_topics = 10, doc_topic_prior = 0.1, topic_word_prior = 0.01)
set.seed(123)
doc_topic_distr =
lda_model$fit_transform(x = dtm, n_iter = 1000,
convergence_tol = 0.001, n_check_convergence = 25,
progressbar = FALSE)
set.seed(123)
new_doc_topic_dist =
lda_model$transform(x = dtm, n_iter = 1000,
convergence_tol = 0.001, n_check_convergence = 25,
progressbar = FALSE)
head(doc_topic_distr)
head(new_doc_topic_dist)
我希望两者都doc_topic_distr
相同new_doc_topic_distr
,但它们完全不同。