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

Method get_topic

bertopic/_bertopic.py:1622–1648  ·  view source on GitHub ↗

Return top n words for a specific topic and their c-TF-IDF scores. Arguments: topic: A specific topic for which you want its representation full: If True, returns all different forms of topic representations for a topic, including aspects R

(self, topic: int, full: bool = False)

Source from the content-addressed store, hash-verified

1620 return self.topic_representations_
1621
1622 def get_topic(self, topic: int, full: bool = False) -> Union[Mapping[str, Tuple[str, float]], bool]:
1623 """Return top n words for a specific topic and their c-TF-IDF scores.
1624
1625 Arguments:
1626 topic: A specific topic for which you want its representation
1627 full: If True, returns all different forms of topic representations
1628 for a topic, including aspects
1629
1630 Returns:
1631 The top n words for a specific word and its respective c-TF-IDF scores
1632
1633 Examples:
1634 ```python
1635 topic = topic_model.get_topic(12)
1636 ```
1637 """
1638 check_is_fitted(self)
1639 if topic in self.topic_representations_:
1640 if full:
1641 representations = {"Main": self.topic_representations_[topic]}
1642 aspects = {aspect: representations[topic] for aspect, representations in self.topic_aspects_.items()}
1643 representations.update(aspects)
1644 return representations
1645 else:
1646 return self.topic_representations_[topic]
1647 else:
1648 return False
1649
1650 def get_topic_info(self, topic: int | None = None) -> pd.DataFrame:
1651 """Get information about each topic including its ID, frequency, and name.

Callers 15

hierarchical_topicsMethod · 0.95
get_document_infoMethod · 0.95
generate_topic_labelsMethod · 0.95
_create_topic_vectorsMethod · 0.95
test_full_modelFunction · 0.80
test_online_cvFunction · 0.80
test_get_topicFunction · 0.80
generate_readmeFunction · 0.80
visualize_heatmapFunction · 0.80
visualize_documentsFunction · 0.80
visualize_term_rankFunction · 0.80

Calls 1

check_is_fittedFunction · 0.90

Tested by 3

test_full_modelFunction · 0.64
test_online_cvFunction · 0.64
test_get_topicFunction · 0.64