You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: bertopic/_bertopic.py
+28-12Lines changed: 28 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -2532,38 +2532,51 @@ def visualize_documents(
2532
2532
2533
2533
defvisualize_document_datamap(
2534
2534
self,
2535
-
docs: List[str],
2535
+
docs: List[str]=None,
2536
2536
topics: List[int] =None,
2537
2537
embeddings: np.ndarray=None,
2538
2538
reduced_embeddings: np.ndarray=None,
2539
2539
custom_labels: Union[bool, str] =False,
2540
2540
title: str="Documents and Topics",
2541
2541
sub_title: Union[str, None] =None,
2542
2542
width: int=1200,
2543
-
height: int=1200,
2544
-
**datamap_kwds,
2543
+
height: int=750,
2544
+
interactive: bool=False,
2545
+
enable_search: bool=False,
2546
+
topic_prefix: bool=False,
2547
+
datamap_kwds: dict= {},
2548
+
int_datamap_kwds: dict= {},
2545
2549
):
2546
2550
"""Visualize documents and their topics in 2D as a static plot for publication using
2547
2551
DataMapPlot. This works best if there are between 5 and 60 topics. It is therefore best
2548
2552
to use a sufficiently large `min_topic_size` or set `nr_topics` when building the model.
2549
2553
2550
2554
Arguments:
2551
2555
topic_model: A fitted BERTopic instance.
2552
-
docs: The documents you used when calling either `fit` or `fit_transform`
2556
+
docs: The documents you used when calling either `fit` or `fit_transform`.
2553
2557
topics: A selection of topics to visualize.
2554
-
Not to be confused with the topics that you get from .fit_transform. For example, if you want to visualize only topics 1 through 5: topics = [1, 2, 3, 4, 5]. Documents not in these topics will be shown as noise points.
2558
+
Not to be confused with the topics that you get from `.fit_transform`.
2559
+
For example, if you want to visualize only topics 1 through 5:
2560
+
`topics = [1, 2, 3, 4, 5]`. Documents not in these topics will be shown
2561
+
as noise points.
2555
2562
embeddings: The embeddings of all documents in `docs`.
2556
2563
reduced_embeddings: The 2D reduced embeddings of all documents in `docs`.
2557
2564
custom_labels: If bool, whether to use custom topic labels that were defined using
2558
-
`topic_model.set_topic_labels`.
2559
-
If `str`, it uses labels from other aspects, e.g., "Aspect1".
2565
+
`topic_model.set_topic_labels`.
2566
+
If `str`, it uses labels from other aspects, e.g., "Aspect1".
2560
2567
title: Title of the plot.
2561
2568
sub_title: Sub-title of the plot.
2562
2569
width: The width of the figure.
2563
2570
height: The height of the figure.
2564
-
**datamap_kwds: All further keyword args will be passed on to DataMapPlot's
2565
-
`create_plot` function. See the DataMapPlot documentation
2566
-
for more details.
2571
+
interactive: Whether to create an interactive plot using DataMapPlot's `create_interactive_plot`.
2572
+
enable_search: Whether to enable search in the interactive plot. Only works if `interactive=True`.
2573
+
topic_prefix: Prefix to add to the topic number when displaying the topic name.
2574
+
datamap_kwds: Keyword args be passed on to DataMapPlot's `create_plot` function
2575
+
if you are not using the interactive version.
2576
+
See the DataMapPlot documentation for more details.
2577
+
int_datamap_kwds: Keyword args be passed on to DataMapPlot's `create_interactive_plot` function
2578
+
if you are using the interactive version.
2579
+
See the DataMapPlot documentation for more details.
0 commit comments