Skip to contents

Adapter generic behind optop_select() and the discrepancy indices: every supported topic-model class is reduced to the common contract list(theta, phi, K, docs, terms), with \(\theta\) the \(J \times K\) document-topic matrix (rows summing to 1), \(\phi\) the \(K \times W\) topic-word matrix (rows summing to 1), \(K\) the number of topics, docs the \(J\) document identifiers matching the rows of \(\theta\), and terms the \(W\) vocabulary entries matching the columns of \(\phi\). Document identifiers are mandatory: alignment to the data is always by identifier, never positional. Adding support for a new topic-model implementation means adding a method for its class; the contract is enforced by .optop_validate_theta_phi().

Usage

optop_as_theta_phi(model)

# S3 method for class 'TopicModel'
optop_as_theta_phi(model)

# S3 method for class 'LDA'
optop_as_theta_phi(model)

# S3 method for class 'LDA_VEM'
optop_as_theta_phi(model)

# S3 method for class 'LDA_Gibbs'
optop_as_theta_phi(model)

# S3 method for class 'CTM'
optop_as_theta_phi(model)

# S3 method for class 'CTM_VEM'
optop_as_theta_phi(model)

# S3 method for class 'textmodel_lda'
optop_as_theta_phi(model)

# S3 method for class 'nlp_topic_fit'
optop_as_theta_phi(model)

# S3 method for class 'optop_warplda'
optop_as_theta_phi(model)

# S3 method for class 'WarpLDA'
optop_as_theta_phi(model)

# Default S3 method
optop_as_theta_phi(model)

# S3 method for class 'optop_theta_phi'
optop_as_theta_phi(model)

Arguments

model

A fitted topic model.

Value

A list with elements theta, phi, K, docs and terms as described above.

Methods (by class)

  • optop_as_theta_phi(TopicModel): Workhorse for all topicmodels fits (LDA and CTM alike): theta and phi come from topicmodels::posterior(), identifiers from the documents and terms slots.

  • optop_as_theta_phi(LDA): topicmodels::LDA fits delegate to the TopicModel method.

  • optop_as_theta_phi(LDA_VEM): VEM fits delegate to the TopicModel method.

  • optop_as_theta_phi(LDA_Gibbs): Gibbs fits delegate to the TopicModel method.

  • optop_as_theta_phi(CTM): topicmodels::CTM fits delegate to the TopicModel method.

  • optop_as_theta_phi(CTM_VEM): CTM VEM fits delegate to the TopicModel method.

  • optop_as_theta_phi(textmodel_lda): seededlda fits: one method covers seededlda::textmodel_lda(), seededlda::textmodel_seededlda() and seededlda::textmodel_seqlda(), since all three constructors return objects of class textmodel_lda exposing theta and phi.

  • optop_as_theta_phi(nlp_topic_fit): NLPstudio fits: theta and phi come from the stored dtw (document-topic) and tww (topic-word) weight matrices, identifiers from doc_ids and vocab. When the weights are not stored, the adapter recurses into the raw model_object if present.

  • optop_as_theta_phi(optop_warplda): text2vec WarpLDA fits, wrapped by optop_warplda(): theta is the matrix the user kept from fit_transform(), phi is model$topic_word_distribution.

  • optop_as_theta_phi(WarpLDA): Guard for raw text2vec WarpLDA R6 objects: they do not retain the document-topic matrix, so they must be wrapped with optop_warplda(). Registered on the R6 class so that raw objects never fall through to the topicmodels LDA method (the R6 class chain contains "LDA" and "TopicModel").

  • optop_as_theta_phi(default): Unsupported classes fail with the list of supported engines.

  • optop_as_theta_phi(optop_theta_phi): Internal container built by the held-out tools: the adapter contract stored as-is.