Repository navigation
fix: drop stale topic aspects when topics are recalculated - #2550
Open
raashish1601 wants to merge 1 commit into
Open
raashish1601 wants to merge 1 commit into
raashish1601 wants to merge 1 commit into
Conversation
After update_topics() without a representation_model, merge_topics() and topic reduction recalculated the main representation but left the old topic_aspects_ in place, keyed by the old topic ids. Clear the aspects before recalculating so that only aspects from the current representation_model remain. Fixes MaartenGr#2531
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #2531
update_topics()setsrepresentation_modelto whatever is passed in, so afterupdate_topics(docs, vectorizer_model=...)it isNone. A latermerge_topics()(or topic reduction) then recalculates the main representation but not the aspects. The old entries intopic_aspects_stay as they were and keep pointing at the old topic ids, so after a merge every topic past the merged one shows the aspects of a different topic._extract_topics()now clearstopic_aspects_before recalculating representations for a new set of topics. Aspects that are still inrepresentation_modelget recalculated as before. Aspects whose model is gone are dropped instead of being left attached to the wrong topics.Calling
update_topics()by itself doesn't change the topics, so the aspects it keeps still line up and that path is unchanged.Two tests in
tests/test_representation/test_representations.py:MMRaspect for the new topics (already worked, now covered)update_topics()with a custom vectorizer leaves no aspect keyed by old topics. This one fails on master.I ran
tests/test_representation,tests/test_bertopic.py,tests/test_variationsandtests/test_reductionon Linux (Python 3.12), plusruff checkandruff format --check.Before submitting