MaartenGr / MaartenGr/BERTopic
Errors OpenAI as a representation model and
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.8k
- Forks
- 920
- Avg merge
- 22h 24m
- Merged PRs (30d)
- 5
Description
Hi @MaartenGr
I am using bertopic==0.16.0 (with default settings) in a dedicated environment and getting the following errors:
Code:
# KeyBERT
keybert = KeyBERTInspired()
# MMR
mmr = MaximalMarginalRelevance(diversity=0.3)
representation_models = [mmr, rep_model_chatgpt]
topic_model = BERTopic(language="english",
top_n_words=100,
verbose=True,
seed_topic_list=seed_topic_list,
representation_model=representation_models,
vectorizer_model=CountVectorizer(ngram_range=(1, 3) , stop_words="english")
)
topics, probs = topic_model.fit_transform(docs)
topic_model.save('my_model')
- When I use OpenAI as a representation model, it generate the following error when trying to save the model using model.save().
Error:
2023-12-11 16:26:00,118 - BERTopic - WARNING: When you use pickle to save/load a BERTopic model,please make sure that the environments in which you saveand load the model are exactly the same. The version of BERTopic,its dependencies, and python need to remain the same.
Traceback (most recent call last):
…
TypeError: cannot pickle '_thread.RLock' object
- When tried bertopic.fit_transform() with seed_topic_list for guided topic modelling (with or without rewpresentation model). getting the following error
Error:
topics, probs = topic_model.fit_transform(docs)
File ".conda\envs\bertopic2\lib\site-packages\bertopic_bertopic.py", line 399, in fit_transform
y, embeddings = self._guided_topic_modeling(embeddings)
File ".conda\envs\bertopic2\lib\site-packages\bertopic_bertopic.py", line 3617, in _guided_topic_modeling
embeddings[indices] = np.average([embeddings[indices], seed_topic_embeddings[seed_topic]], weights=[3, 1])
File ".conda\envs\bertopic2\lib\site-packages\numpy\lib\function_base.py", line 511, in average
a = np.asanyarray(a)
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
Thanks
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
Start by reproducing the two reported failures with BERTopic 0.16.0: saving a model using the OpenAI representation model, and running fit_transform with seed_topic_list. Inspect the model.save path and _guided_topic_modeling in _bertopic.py; done means both workflows complete without the reported pickle or NumPy shape errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, 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