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

Method get_topic_freq

bertopic/_bertopic.py:1703–1732  ·  view source on GitHub ↗

Return the size of topics (descending order). Arguments: topic: A specific topic for which you want the frequency Returns: Either the frequency of a single topic or dataframe with the frequencies of all topics Examples: To extrac

(self, topic: int | None = None)

Source from the content-addressed store, hash-verified

1701 return info.reset_index(drop=True)
1702
1703 def get_topic_freq(self, topic: int | None = None) -> Union[pd.DataFrame, int]:
1704 """Return the size of topics (descending order).
1705
1706 Arguments:
1707 topic: A specific topic for which you want the frequency
1708
1709 Returns:
1710 Either the frequency of a single topic or dataframe with
1711 the frequencies of all topics
1712
1713 Examples:
1714 To extract the frequency of all topics:
1715
1716 ```python
1717 frequency = topic_model.get_topic_freq()
1718 ```
1719
1720 To get the frequency of a single topic:
1721
1722 ```python
1723 frequency = topic_model.get_topic_freq(12)
1724 ```
1725 """
1726 check_is_fitted(self)
1727 if isinstance(topic, int):
1728 return self.topic_sizes_[topic]
1729 else:
1730 return pd.DataFrame(self.topic_sizes_.items(), columns=["Topic", "Count"]).sort_values(
1731 "Count", ascending=False
1732 )
1733
1734 def get_document_info(
1735 self,

Callers 14

_reduce_topicsMethod · 0.95
test_full_modelFunction · 0.80
test_get_topic_freqFunction · 0.80
test_extract_topicsFunction · 0.80
test_topic_reductionFunction · 0.80
generate_readmeFunction · 0.80
visualize_heatmapFunction · 0.80
visualize_topicsFunction · 0.80

Calls 1

check_is_fittedFunction · 0.90

Tested by 6

test_full_modelFunction · 0.64
test_get_topic_freqFunction · 0.64
test_extract_topicsFunction · 0.64
test_topic_reductionFunction · 0.64