# NOT RUN {
if (requireNamespace("text2vec", quietly = TRUE)) {
# }
# NOT RUN {
library(recipes)
library(modeldata)
data(okc_text)
okc_rec <- recipe(~ ., data = okc_text) %>%
step_lda(essay0)
okc_obj <- okc_rec %>%
prep()
juice(okc_obj) %>%
slice(1:2)
tidy(okc_rec, number = 1)
tidy(okc_obj, number = 1)
# Changing the number of topics.
recipe(~ ., data = okc_text) %>%
step_lda(essay0, essay1, num_topics = 20) %>%
prep() %>%
juice() %>%
slice(1:2)
# Supplying A pre-trained LDA model trained using text2vec
library(text2vec)
tokens <- word_tokenizer(tolower(okc_text$essay5))
it <- itoken(tokens, ids = seq_along(okc_text$essay5))
v <- create_vocabulary(it)
dtm <- create_dtm(it, vocab_vectorizer(v))
lda_model <- LDA$new(n_topics = 15)
recipe(~ ., data = okc_text) %>%
step_lda(essay0, essay1, lda_models = lda_model) %>%
prep() %>%
juice() %>%
slice(1:2)
# }
# NOT RUN {
}
# }
Run the code above in your browser using DataLab