Learn R Programming

topicmodels.etm (version 0.1.0)

as.matrix.ETM: Get matrices out of an ETM object

Description

Convenience function to extract

  • embeddings of the topic centers

  • embeddings of the words used in the model

  • words emmitted by each topic (beta), which is the softmax-transformed inner product of word embedding and topic embeddings

Usage

# S3 method for ETM
as.matrix(x, type = c("embedding", "beta"), which = c("topics", "words"), ...)

Arguments

x

an object of class ETM

type

character string with the type of information to extract: either 'beta' (words emttied by each topic) or 'embedding' (embeddings of words or topic centers). Defaults to 'embedding'.

which

a character string with either 'words' or 'topics' to get either the embeddings of the words used in the model or the embedding of the topic centers. Defaults to 'topics'. Only used if type = 'embedding'.

...

not used

Value

a numeric matrix containing, depending on the value supplied in type either the embeddings of the topic centers, the embeddings of the words or the words emitted by each topic

See Also

ETM

Examples

Run this code
# NOT RUN {
library(torch)
library(topicmodels.etm)
path  <- system.file(package = "topicmodels.etm", "example", "example_etm.ckpt")
model <- torch_load(path)

topic.centers     <- as.matrix(model, type = "embedding", which = "topics")
word.embeddings   <- as.matrix(model, type = "embedding", which = "words")
topic.terminology <- as.matrix(model, type = "beta")
# }

Run the code above in your browser using DataLab