Visualize Topic Distribution for a Specific Document using BERTopic
visualize_distribution.RdThis function visualizes the topic distribution for a specific document from a BERTopic model using Python's Plotly library. The visualization is saved as an interactive HTML file, which can be opened and viewed in a web browser.
Usage
visualize_distribution(
model,
text_id = 1,
probabilities,
filename = "topic_dist_interactive",
auto_open = FALSE
)Arguments
- model
A BERTopic model object. The model must have the method
visualize_distribution.- text_id
An integer specifying the index of the document for which the topic distribution is visualized. Default is 1. Must be a positive integer and a valid index within the
probabilitiesmatrix.- probabilities
A matrix or data frame of topic probabilities, with rows corresponding to documents and columns to topics. Each element represents the probability of a topic for a given document.
- filename
A character string specifying the name of the HTML file to save the visualization. Default is "topic_dist_interactive". The .html extension will be added automatically.
- auto_open
Logical. If TRUE, the HTML file will automatically open in the browser. Default is FALSE.