chainsScores: Compute scores of topic models (chains)

View source: R/functions.R

chainsScoresR Documentation

Compute scores of topic models (chains)

Description

Compute various scores (log likelihood, coherence) for a list of topic models.

Usage

chainsScores(x, window = 110, nWords = 10)

Arguments

x

a valid multiChains object, obtained through the estimation of a topic model using grow() and the argument nChains greater than 1.

window

optional. If NULL, use the default window for each coherence metric (10 for C_NPMI and 110 for C_V). It is possible to override these default windows by providing an integer or "boolean" to this argument, determining a new window size for all measures.

nWords

the number of words used to compute coherence. See coherence().

Value

A data.table with some statistics about each chain. For the coherence metrics, the value shown is the mean coherence across all topics of a chain

Parallelism

When nChains > 1, the function can take advantage of future.apply::future_lapply (if installed) to spread the computation over multiple processes. This requires the specification of a parallel strategy using future::plan(). See the examples below.

See Also

chainsDistances() coherence()

Examples

model <- LDA(ECB_press_conferences_tokens[1:10])
model <- grow(model, 10, nChains = 5)
chainsScores(model, window = 5)
chainsScores(model, window = "boolean")

# -- Parallel computation --
require(future.apply)
future::plan("multisession", workers = 2) # Set up 2 workers
chainsScores(model, window = "boolean")

future::plan("sequential") # Shut down workers


sentopics documentation built on May 31, 2023, 8:26 p.m.