Extract document-topic and topic-word weights from a fitted model
Source:R/utils.R
optop_as_theta_phi.RdAdapter 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)Methods (by class)
optop_as_theta_phi(TopicModel): Workhorse for alltopicmodelsfits (LDA and CTM alike): theta and phi come fromtopicmodels::posterior(), identifiers from thedocumentsandtermsslots.optop_as_theta_phi(LDA):topicmodels::LDAfits delegate to theTopicModelmethod.optop_as_theta_phi(LDA_VEM): VEM fits delegate to theTopicModelmethod.optop_as_theta_phi(LDA_Gibbs): Gibbs fits delegate to theTopicModelmethod.optop_as_theta_phi(CTM):topicmodels::CTMfits delegate to theTopicModelmethod.optop_as_theta_phi(CTM_VEM): CTM VEM fits delegate to theTopicModelmethod.optop_as_theta_phi(textmodel_lda): seededlda fits: one method coversseededlda::textmodel_lda(),seededlda::textmodel_seededlda()andseededlda::textmodel_seqlda(), since all three constructors return objects of classtextmodel_ldaexposingthetaandphi.optop_as_theta_phi(nlp_topic_fit): NLPstudio fits: theta and phi come from the storeddtw(document-topic) andtww(topic-word) weight matrices, identifiers fromdoc_idsandvocab. When the weights are not stored, the adapter recurses into the rawmodel_objectif present.optop_as_theta_phi(optop_warplda): text2vec WarpLDA fits, wrapped byoptop_warplda(): theta is the matrix the user kept fromfit_transform(), phi ismodel$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 withoptop_warplda(). Registered on the R6 class so that raw objects never fall through to thetopicmodelsLDAmethod (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.