Description Usage Arguments Value Note Examples
Fit sentence-based topic models for all of some of a corpus, with the ability to fit topics around a specified word or phrase.
1 2 | ttt_fit_topics(tok, years = NULL, ntopics = 20, topic = NULL,
filename = NULL, quiet = FALSE)
|
tok |
A quanteda 'tokens' object |
years |
If specified, restrict topic models to specified years only (requires 'tok' to include a 'docvars' of "year" or similar). |
ntopics |
Number of topics to be fitted. This should be reasonably large, to allow words not strongly associated with any primary topics to be allocated to latter, effectively meaningless topics. |
topic |
If specified, construct topic models around the specified phrase. |
filename |
If specified, the topic model is saved to the nominated file and can be re-loaded with 'x <- readRDS(filename)'. |
quiet |
If 'TRUE', display progress information on screen. |
An topicmodels object of class 'LDA'.
This function may take a long time to execute; please be patient.
1 2 3 4 5 6 7 8 9 | library(quanteda)
dat <- data_corpus_inaugural %>% # from quanteda
corpus_reshape (to = "sentences") # convert documents to sentences
tok <- tokens (dat, remove_numbers = TRUE, remove_punct = TRUE,
remove_separators = TRUE)
tok <- tokens_remove(tok, stopwords("english"))
x <- ttt_fit_topics (tok, ntopics = 5)
topicmodels::get_terms(x, 20)
x <- ttt_fit_topics (tok, years = 1789:1900, ntopics = 5)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.