MaartenGr / MaartenGr/BERTopic

find_topics returns the same topics for any keywords

Open
#1,426 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

Hello,
I have fit the BERTopic model using CUML's HDBSCAN and UMAP. I used `microsoft/codebert-base` on huggingface as the embedding model like this:

```python
model = pipeline("feature-extraction",
model="microsoft/codebert-base",
device=0)
topic_model = BERTopic(embedding_model=model,
umap_model=umap_model,
hdbscan_model=hdbscan_model,
calculate_probabilities=True,
)
topic_model = topic_model.fit(docs)

topic_model.save("models/codebert",
serialization="safetensors",
save_ctfidf=True)
```

The above code runs without any problems. This is how I load the model:

```python
embedding_model = 'microsoft/codebert-base'
model = pipeline('feature-extraction', embedding_model)
model = HFTransformerBackend(model)
topic_model = BERTopic.load("models/codebert",
embedding_model=model)
```

Although invoking the get_topic_info method from topic_model returns a list of meaningful topics, when I call find_topics, no matter what the term is, a list of the same topics is returned with almost the same probabilities. The same thing happened when I used another Huggingface model. Are there any potential workarounds?

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

Start with BERTopic.find_topics and the BERTopic.load/HFTransformerBackend path, using the CodeBERT and CUML HDBSCAN/UMAP setup shown in the report. Compare find_topics results for different keywords with get_topic_info output and verify whether loading preserves the embedding behavior; done means keyword searches return meaningfully different topics or the limitation is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
huggingface, python
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.