MaartenGr / MaartenGr/BERTopic
Why does `visualize_topics` use `n_neighbors=2`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.8k
- Forks
- 920
- Avg merge
- 22h 24m
- Merged PRs (30d)
- 5
Description
Hi Maarten,
Just wondering why the UMAP module in `visualize_topics` uses `n_neighbors=2` rather than something like 15?
https://github.com/MaartenGr/BERTopic/blob/424cefc68ede08ff9f1c7e56ee6103c16c1429c6/bertopic/plotting/_topics.py#L79
A value of 2 results in a lot of topics sitting directly on top of one another, whereas higher values give better topic spread and are more reminiscent of the topic spread when visualizing documents.
*n_neighbors=2*

*n_neighbors=15*

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
Read bertopic/plotting/_topics.py around line 79 and compare the n_neighbors=2 setting with the document visualization path. Reproduce the two configurations shown in the issue; done means documenting the rationale or agreeing on a defined default or change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data-visualization, machine-learning
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100