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)
| 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. |
no outgoing calls