MaartenGr / MaartenGr/BERTopic

Why does `visualize_topics` use `n_neighbors=2`

Open
#1,900 5 comments 0 reactions 0 assignees View on GitHub

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*
![image](https://github.com/MaartenGr/BERTopic/assets/39004650/e159fc4c-a510-4d85-bc6c-d3823fb6a743)

*n_neighbors=15*
![image](https://github.com/MaartenGr/BERTopic/assets/39004650/9b3aabad-fae5-4fff-8a93-384b1513d780)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.