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

Method get_mappings

bertopic/_bertopic.py:4923–4948  ·  view source on GitHub ↗

Get mappings from either the original topics or the second-most recent topics to the current topics. Arguments: original_topics: Whether we want to map from the original topics to the most recent topics or from th

(self, original_topics: bool = True)

Source from the content-addressed store, hash-verified

4921 self.mappings_ = np.hstack([topics.copy(), topics.copy()]).tolist()
4922
4923 def get_mappings(self, original_topics: bool = True) -> Mapping[int, int]:
4924 """Get mappings from either the original topics or
4925 the second-most recent topics to the current topics.
4926
4927 Arguments:
4928 original_topics: Whether we want to map from the
4929 original topics to the most recent topics
4930 or from the second-most recent topics.
4931
4932 Returns:
4933 mappings: The mappings from old topics to new topics
4934
4935 Examples:
4936 To get mappings, simply call:
4937 ```python
4938 mapper = TopicMapper(topics)
4939 mappings = mapper.get_mappings(original_topics=False)
4940 ```
4941 """
4942 if original_topics:
4943 mappings = np.array(self.mappings_)[:, [0, -1]]
4944 mappings = dict(zip(mappings[:, 0], mappings[:, 1]))
4945 else:
4946 mappings = np.array(self.mappings_)[:, [-3, -1]]
4947 mappings = dict(zip(mappings[:, 0], mappings[:, 1]))
4948 return mappings
4949
4950 def add_mappings(self, mappings: Mapping[int, int], topic_model: BERTopic):
4951 """Add new column(s) of topic mappings.

Callers 6

test_mergeFunction · 0.80
test_deleteFunction · 0.80
partial_fitMethod · 0.80
delete_topicsMethod · 0.80
_map_predictionsMethod · 0.80
_map_probabilitiesMethod · 0.80

Calls

no outgoing calls

Tested by 2

test_mergeFunction · 0.64
test_deleteFunction · 0.64