|
3 | 3 |
|
4 | 4 | from ..models.abstract_helper_models.base import BaseModel, TrainingStatus |
5 | 5 | from ..utils import TMDataset |
6 | | -from ._interactive import (_visualize_topic_model_2d, |
7 | | - _visualize_topic_model_3d, _visualize_topics_2d, |
8 | | - _visualize_topics_3d) |
| 6 | +from ._interactive import ( |
| 7 | + _visualize_topic_model_2d, |
| 8 | + _visualize_topic_model_3d, |
| 9 | + _visualize_topics_2d, |
| 10 | + _visualize_topics_3d, |
| 11 | +) |
9 | 12 | from ._octis_visuals import OctisWrapperVisualModel |
10 | 13 |
|
11 | 14 |
|
@@ -43,7 +46,7 @@ def visualize_topics_as_wordclouds( |
43 | 46 | hasattr(model, "topic_dict") and model._status == TrainingStatus.SUCCEEDED |
44 | 47 | ), "Model must have been trained with topics extracted." |
45 | 48 |
|
46 | | - topics = model.get_topics() |
| 49 | + topics = model.topic_dict |
47 | 50 |
|
48 | 51 | for topic_id, topic_words in topics.items(): |
49 | 52 | # Generate a word frequency dictionary for the topic |
@@ -153,24 +156,24 @@ def visualize_topics( |
153 | 156 | use_average: bool = True, |
154 | 157 | ): |
155 | 158 | """ |
156 | | - Visualize topics in either 2D or 3D space using UMAP, t-SNE, or PCA dimensionality reduction techniques. |
157 | | -
|
158 | | - Args: |
159 | | - model (AbstractModel): The trained topic model instance. |
160 | | - model_output (dict, optional): The output of the topic model, typically including topic-word distributions and document-topic distributions. Required if the model does not have an 'output' attribute. |
161 | | - dataset (TMDataset, optional): The dataset used for training the topic model. Required if the model does not have an 'output' attribute. |
162 | | - three_dim (bool, optional): Flag to visualize in 3D if True, otherwise in 2D. Defaults to False. |
163 | | - reduce_first (bool, optional): Indicates whether to perform dimensionality reduction on embeddings before computing topic centroids. Defaults to False. |
164 | | - reducer (str, optional): Choice of dimensionality reduction technique. Supported values are 'umap', 'tsne', and 'pca'. Defaults to 'umap'. |
165 | | - port (int, optional): The port number on which the visualization dashboard will run. Defaults to 8050. |
166 | | - embedding_model_name (str, optional): Name of the embedding model used for generating document embeddings. Defaults to "all-MiniLM-L6-v2". |
167 | | - embeddings_folder_path (str, optional): Path to the folder containing precomputed embeddings. If not provided, embeddings will be computed on the fly. |
168 | | - embeddings_file_path (str, optional): Path to the file containing precomputed embeddings. If not provided, embeddings will be computed on the fly. |
169 | | -
|
170 | | -
|
171 | | - Returns: |
172 | | - None |
173 | | - The function launches a Dash server to visualize the topic model. |
| 159 | + Visualize topics in either 2D or 3D space using UMAP, t-SNE, or PCA dimensionality reduction techniques. |
| 160 | +
|
| 161 | + Args: |
| 162 | + model (AbstractModel): The trained topic model instance. |
| 163 | + model_output (dict, optional): The output of the topic model, typically including topic-word distributions and document-topic distributions. Required if the model does not have an 'output' attribute. |
| 164 | + dataset (TMDataset, optional): The dataset used for training the topic model. Required if the model does not have an 'output' attribute. |
| 165 | + three_dim (bool, optional): Flag to visualize in 3D if True, otherwise in 2D. Defaults to False. |
| 166 | + reduce_first (bool, optional): Indicates whether to perform dimensionality reduction on embeddings before computing topic centroids. Defaults to False. |
| 167 | + reducer (str, optional): Choice of dimensionality reduction technique. Supported values are 'umap', 'tsne', and 'pca'. Defaults to 'umap'. |
| 168 | + port (int, optional): The port number on which the visualization dashboard will run. Defaults to 8050. |
| 169 | + embedding_model_name (str, optional): Name of the embedding model used for generating document embeddings. Defaults to "all-MiniLM-L6-v2". |
| 170 | + embeddings_folder_path (str, optional): Path to the folder containing precomputed embeddings. If not provided, embeddings will be computed on the fly. |
| 171 | + embeddings_file_path (str, optional): Path to the file containing precomputed embeddings. If not provided, embeddings will be computed on the fly. |
| 172 | +
|
| 173 | +
|
| 174 | + Returns: |
| 175 | + None |
| 176 | + The function launches a Dash server to visualize the topic model. |
174 | 177 |
|
175 | 178 | """ |
176 | 179 | if not isinstance(model, BaseModel): |
|
0 commit comments