Skip to contents

Return standardized hyperparameters stored on an object returned by fit_topic_model(). The accessor uses package-level names so users do not need to remember backend-specific argument names.

Usage

get_topic_hyperparameters(x)

Arguments

x

An object returned by fit_topic_model().

Value

A data.table with columns:

parameter

Standardized parameter name: "k", "alpha", or "beta".

value

Stored parameter value. Scalar symmetric priors are shown as scalars; non-scalar priors are preserved as vectors. NA means the parameter is not available or not applicable for the fitted model.

source_section

Where the value came from: e.g. "argument", "model", "fit", or "model_object".

source_name

Backend-native argument, slot, or field name.

Details

alpha is the document-topic prior and beta is the topic-word prior, using the notation common in LDA. Engines that do not expose an equivalent prior return NA for that row instead of dropping it, so the table has a stable shape across engines. Objects created before hyperparameters were stored on nlp_topic_fit objects return a best-effort fallback with a warning; refit the model with the current package version to recover backend-native hyperparameter sources.

Examples

dtm <- methods::as(
  Matrix::Matrix(
    matrix(c(1, 0, 1,  1, 1, 0,  0, 1, 1,  1, 1, 1),
           nrow = 4, byrow = TRUE),
    sparse = TRUE
  ),
  "dgCMatrix"
)
colnames(dtm) <- paste0("term", 1:3)
fit <- fit_topic_model(
  dtm, engine = "text2vec", model = "lda", k = 2,
  control = list(
    model = list(doc_topic_prior = 0.1, topic_word_prior = 0.01),
    fit = list(n_iter = 25, progressbar = FALSE)
  )
)
get_topic_hyperparameters(fit)
#>    parameter  value source_section      source_name
#>       <char> <AsIs>         <char>           <char>
#> 1:         k      2       argument                k
#> 2:     alpha    0.1          model  doc_topic_prior
#> 3:      beta   0.01          model topic_word_prior