plot.ETM {topicmodels.etm} | R Documentation |
Plot functionality for an ETM object
Description
Convenience function allowing to plot
the evolution of the loss on the training / test set in order to inspect training convergence
the
ETM
model in 2D dimensional space using a umap projection. This plot uses functiontextplot_embedding_2d
from the textplot R package and plots the top_n most emitted words of each topic and the topic centers in 2 dimensions
Usage
## S3 method for class 'ETM'
plot(
x,
type = c("loss", "topics"),
which,
top_n = 4,
title = "ETM topics",
subtitle = "",
encircle = FALSE,
points = FALSE,
...
)
Arguments
x |
an object of class |
type |
character string with the type of plot to generate: either 'loss' or 'topics' |
which |
an integer vector of topics to plot, used in case type = 'topics'. Defaults to all topics. See the example below. |
top_n |
passed on to |
title |
passed on to textplot_embedding_2d, used in case type = 'topics' |
subtitle |
passed on to textplot_embedding_2d, used in case type = 'topics' |
encircle |
passed on to textplot_embedding_2d, used in case type = 'topics' |
points |
passed on to textplot_embedding_2d, used in case type = 'topics' |
... |
arguments passed on to |
Value
In case type
is set to 'topics', maps the topic centers and most emitted words for each topic
to 2D using summary.ETM
and returns a ggplot object by calling textplot_embedding_2d
.
For type 'loss', makes a base graphics plot and returns invisibly nothing.
See Also
ETM
, summary.ETM
, textplot_embedding_2d
Examples
library(torch)
library(topicmodels.etm)
path <- system.file(package = "topicmodels.etm", "example", "example_etm.ckpt")
model <- torch_load(path)
plot(model, type = "loss")
library(torch)
library(topicmodels.etm)
library(textplot)
library(uwot)
library(ggrepel)
library(ggalt)
path <- system.file(package = "topicmodels.etm", "example", "example_etm.ckpt")
model <- torch_load(path)
plt <- plot(model, type = "topics", top_n = 7, which = c(1, 2, 14, 16, 18, 19),
metric = "cosine", n_neighbors = 15,
fast_sgd = FALSE, n_threads = 2, verbose = TRUE,
title = "ETM Topics example")
plt