MCPcopy
hub / github.com/MaartenGr/BERTopic / visualize_topics

Method visualize_topics

bertopic/_bertopic.py:2541–2593  ·  view source on GitHub ↗

Visualize topics, their sizes, and their corresponding words. This visualization is highly inspired by LDAvis, a great visualization technique typically reserved for LDA. Arguments: topics: A selection of topics to visualize Not to be confuse

(
        self,
        topics: List[int] | None = None,
        top_n_topics: int | None = None,
        use_ctfidf: bool = False,
        custom_labels: bool = False,
        title: str = "<b>Intertopic Distance Map</b>",
        width: int = 650,
        height: int = 650,
    )

Source from the content-addressed store, hash-verified

2539 return new_topics
2540
2541 def visualize_topics(
2542 self,
2543 topics: List[int] | None = None,
2544 top_n_topics: int | None = None,
2545 use_ctfidf: bool = False,
2546 custom_labels: bool = False,
2547 title: str = "<b>Intertopic Distance Map</b>",
2548 width: int = 650,
2549 height: int = 650,
2550 ) -> "go.Figure":
2551 """Visualize topics, their sizes, and their corresponding words.
2552
2553 This visualization is highly inspired by LDAvis, a great visualization
2554 technique typically reserved for LDA.
2555
2556 Arguments:
2557 topics: A selection of topics to visualize
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]`.
2561 top_n_topics: Only select the top n most frequent topics
2562 use_ctfidf: Whether to use c-TF-IDF representations instead of the embeddings from the embedding model.
2563 custom_labels: Whether to use custom topic labels that were defined using
2564 `topic_model.set_topic_labels`.
2565 title: Title of the plot.
2566 width: The width of the figure.
2567 height: The height of the figure.
2568
2569 Examples:
2570 To visualize the topics simply run:
2571
2572 ```python
2573 topic_model.visualize_topics()
2574 ```
2575
2576 Or if you want to save the resulting figure:
2577
2578 ```python
2579 fig = topic_model.visualize_topics()
2580 fig.write_html("path/to/file.html")
2581 ```
2582 """
2583 check_is_fitted(self)
2584 return plotting.visualize_topics(
2585 self,
2586 topics=topics,
2587 top_n_topics=top_n_topics,
2588 use_ctfidf=use_ctfidf,
2589 custom_labels=custom_labels,
2590 title=title,
2591 width=width,
2592 height=height,
2593 )
2594
2595 def visualize_documents(
2596 self,

Callers 3

test_no_plotlyFunction · 0.95
test_topicsFunction · 0.80
test_topics_outlierFunction · 0.80

Calls 1

check_is_fittedFunction · 0.90

Tested by 3

test_no_plotlyFunction · 0.76
test_topicsFunction · 0.64
test_topics_outlierFunction · 0.64