MaartenGr / MaartenGr/BERTopic

find_topics(topic) crashes if topic is a 1-element list

Open
#2,475 0 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

`topic_model.find_topics(topic)` crashes if `topic` is a list with 1 string only.

It works if `topic` is a string or a list of strings with `len>1`

### Reproduction

```python
from bertopic import BERTopic
from sklearn.datasets import fetch_20newsgroups

docs = fetch_20newsgroups(subset='all', remove=('headers', 'footers', 'quotes'))['data']

topic_model = BERTopic()
topics, probs = topic_model.fit_transform(docs)
similar_topics, similarities = topic_model.find_topics(["internet"], top_n=50)
```

### BERTopic Version

0.17.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 provided BERTopic reproduction with find_topics(["internet"], top_n=50), then inspect the find_topics entry point and its handling of single-item lists. Done means the one-element-list call completes consistently with the string and multi-item-list forms, with regression coverage for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, scikit-learn
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.