MaartenGr / MaartenGr/BERTopic
Add multi-label support for topics_per_class
- Dominant language
- Python
- Stars
- 7.8k
- Forks
- 920
- Avg merge
- 22h 24m
- Merged PRs (30d)
- 5
Description
Hi! I'm working with a multi-label dataset, and I'm trying to use the `topics_per_class` function. However, I noticed that the function only supports single labels. It would be great if the function could support multi-label datasets as well.
Maybe by adding an optional argument called `problem_type`, which could be set to either `"multi-label"` or `"single-label"`, or by just checking the `classes[0]` type to be equal to `list` and change the behavior of the function based on that.
Personally to make it work I changed the lines:
https://github.com/MaartenGr/BERTopic/blob/845d423bdef44a4a68fc0b1c9362f97237035d3c/bertopic/_bertopic.py#L769-L772
with
```python
labels_list=set([label for labels_article in classes for label in labels_article])
for _, class_ in tqdm(enumerate(labels_list), disable=not topic_model.verbose):
# Calculate c-TF-IDF representation for a specific timestamp
selection = documents[documents.Class.apply(lambda c: class_ in c)]
```
Contributor guide
Research direction
Start in bertopic/_bertopic.py around lines 769-772 and trace the topics_per_class entry point to understand how classes are currently iterated and selected. Compare the reported single-label behavior with the proposed multi-label selection, then define the supported input shape and confirm that topics_per_class produces per-label results for multi-label datasets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100