MaartenGr / MaartenGr/BERTopic
Cannot see documents chart
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.8k
- Forks
- 920
- Avg merge
- 22h 24m
- Merged PRs (30d)
- 5
Description
### Have you searched existing issues? 🔎
- [x] I have searched and found no existing issues
### Desribe the bug
I tried creating a topic model and vizualizing it with `topic_model.visualize_documents`. At first it worked. I downgraded to Python **3.11.9** recently (from Python 3.12) and now it doesn't show the axis or the embeddings in the plot. Is there some mismatch of packages that I'm missing?

Looking at the plotly figure it creates, it contains the coordinates of all embeddings like normal. The topics frequency is also correct. When opening the chrome dev console, I see the following error:
```
(index):2635 Uncaught TypeError: POt.indexOf is not a function
at Object.bqe [as parse] ((index):2635:6608)
at (index):2712:2021
at Array.forEach ()
at Vu.update ((index):2712:1938)
at new Vu ((index):2638:59901)
at bOe.exports [as plot] ((index):2712:10629)
at Kve ((index):25:370736)
at yv.plot ((index):25:369762)
at ld.drawData ((index):25:180565)
at li.syncOrAsync ((index):24:17595)
```
It seems to be from the plotly package but I cannot seem to pinpoint the exact problem since the code is minified:

### Reproduction
Code in question where I create the model:
```python
bi_encoder = SentenceTransformer("all-mpnet-base-v2")
embeddings = bi_encoder.encode(input_corpus, show_progress_bar=True)
umap_model = UMAP(n_neighbors=3, n_components=3, min_dist=0.1, metric="cosine", random_state=40)
hdbscan_model = HDBSCAN(prediction_data=True)
vectorizer_model = CountVectorizer(ngram_range=(1, 2), stop_words="english")
topic_model = BERTopic(
embedding_model=bi_encoder,
vectorizer_model=vectorizer_model,
hdbscan_model=hdbscan_model,
umap_model=umap_model,
verbose=True,
)
fig_docs = topic_model.visualize_documents(red_flag_descr, embeddings=embeddings)
fig_docs.show()
```
Versions:
```
bertopic==0.16.4
umap-learn==0.5.7
hdbscan==0.8.40
sentence-transformers==3.3.1
plotly==6.0.0
```
### BERTopic Version
0.16.4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied topic_model.visualize_documents example with the listed Python, BERTopic, and Plotly versions, then inspect the generated figure and Chrome console error. Compare the behavior around the Python 3.11.9 downgrade and Plotly 6.0.0. Done means the documents chart renders its axes and embeddings without the reported TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- plotly, python
- Domain
- data-visualization, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100