ttt_fit_topics: ttt_topics

Description Usage Arguments Value Note Examples

Description

Fit sentence-based topic models for all of some of a corpus, with the ability to fit topics around a specified word or phrase.

Usage

1
2
ttt_fit_topics(tok, years = NULL, ntopics = 20, topic = NULL,
  filename = NULL, quiet = FALSE)

Arguments

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.

Value

An topicmodels object of class 'LDA'.

Note

This function may take a long time to execute; please be patient.

Examples

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)

mpadge/texttimetravel documentation built on Nov. 14, 2020, 11:31 a.m.