Add visualize_representative_images for image-only topic models#2521
Open
Gsebs wants to merge 1 commit into
Open
Add visualize_representative_images for image-only topic models#2521Gsebs wants to merge 1 commit into
Gsebs wants to merge 1 commit into
Conversation
Adds a Plotly-based visualization that steps through each topic's representative-image collage (as created by VisualRepresentation) with a slider, at readable resolution. Mirrors the structure of the other plotting functions: standalone function in bertopic/plotting/_images.py, re-exported in the plotting namespace, and a thin delegating method on BERTopic. Uses only existing dependencies (plotly + numpy). Implements the approach discussed in MaartenGr#2236. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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?
Implements the approach discussed in #2236: a Plotly visualization that steps through each topic's representative-image collage (as created by
VisualRepresentation) with a slider, at readable resolution — using only existing dependencies (plotly + numpy; no dash, no backend switch, no custom HTML/CSS), as preferred in that thread.The slider selects a topic; the title subtitle updates to the selected topic's label and the topic's collage is shown at its original resolution.
How it's structured
Follows the existing plotting conventions:
bertopic/plotting/_images.py, re-exported inbertopic.plottingBERTopic.visualize_representative_images()(placed aftervisualize_documents)docs/api/plotting/representative_images.md) + mkdocs nav entrytopics=subsetting,custom_labels(bool or aspect name), and a configurableaspectname (default"Visual_Aspect")Tests
tests/test_plotting/test_images.pymirrors the existing plotting-test idioms (parametrized over the fitted-model fixtures). Since thetestextra doesn't includevision/PIL, tests inject numpy-array images intotopic_aspects_— the function consumes anythingnp.asarrayaccepts, so real PIL collages work identically.Verified locally:
Happy to rename the function or adjust scope however you prefer, @MaartenGr — and I can attach a demo HTML if helpful.
Fixes #2236