MaartenGr / MaartenGr/BERTopic
logger.warning() formatting issue in topic_model.save()
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.8k
- Forks
- 920
- Avg merge
- 22h 24m
- Merged PRs (30d)
- 5
Description
Hi Maarten,
I'm getting the following error trying to save a topic model without an embedding model pointer.
```python
from sklearn.datasets import fetch_20newsgroups
from bertopic import BERTopic
# Documents to train on
docs = fetch_20newsgroups(subset='all', remove=('headers', 'footers', 'quotes'))['data'][0:500]
topic_model = BERTopic().fit(docs)
topic_model.save("model_dir", serialization="safetensors", save_ctfidf=True, save_embedding_model=False)
```
```
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[1], line 8
5 docs = fetch_20newsgroups(subset='all', remove=('headers', 'footers', 'quotes'))['data'][0:500]
6 topic_model = BERTopic().fit(docs)
----> 8 topic_model.save("model_dir", serialization="safetensors", save_ctfidf=True, save_embedding_model=False)
File c:\path\lib\site-packages\bertopic\_bertopic.py:2998, in BERTopic.save(self, path, serialization, save_embedding_model, save_ctfidf)
2996 save_embedding_model = self.embedding_model._hf_model
2997 elif not save_embedding_model:
-> 2998 logger.warning("You are saving a BERTopic model without explicitly defining an embedding model."
2999 "If you are using a sentence-transformers model or a HuggingFace model supported"
3000 "by sentence-transformers, please save the model by using a pointer towards that model."
3001 "For example, `save_embedding_model=sentence-transformers/all-mpnet-base-v2`", RuntimeWarning)
3003 # Minimal
3004 save_utils.save_hf(model=self, save_directory=save_directory, serialization=serialization)
TypeError: warning() takes 2 positional arguments but 3 were given
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example and start in bertopic/_bertopic.py at BERTopic.save(), around the logger.warning call shown in the traceback. Check the logging call's arguments and verify that saving without an embedding model completes while still emitting the intended warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100