MaartenGr / MaartenGr/BERTopic

metric= "cosine" error reported

Open
#2,217 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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 wanted to set cosine to represent the distance parameter when I personalized hdbscan. This instantiation didn't go wrong, but I passed the instantiation hdbscan_model into BERTopic(). Unrecognized metric 'cosine'

### Reproduction

```python
from bertopic import BERTopic
hdbscan_model = HDBSCAN(
min_cluster_size=200,,
min_samples=20,
metric='cosine',
prediction_data=True
)
topic_model = BERTopic(embedding_model=transformer_model,
#min_topic_size=3,
verbose=True,
umap_model=umap_model,
hdbscan_model=hdbscan_model,
ctfidf_model=ctfidf_model,
representation_model=representation_model,
#top_n_words=10,
#min_topic_size=10,
#nr_topics=None,
#low_memory=False,
#calculate_probabilities=True
)
topics,probs=topic_model.fit_transform(sentences,embeddings=embeddings)
```

### BERTopic Version

0.16.4

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 by running the supplied HDBSCAN and BERTopic reproduction with BERTopic 0.16.4, focusing on where the custom hdbscan_model is accepted during fit_transform. Trace the handling of the metric='cosine' configuration and compare the reported error with HDBSCAN's supported metrics. Done means cosine works through this integration or the incompatibility is clearly reported and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.