MaartenGr / MaartenGr/BERTopic
Can't get updated topic_embeddings_ when using pre-calculated document embeddings?
Nobody has claimed this yet.
- 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 can use the `update_topics` function by passing in the appropriate documents and my manually generated topic labels, and using the auto-generated embeddings. This works as intended and I get the updated `topic_embeddings_`.
`topic_model.update_topics(docs, topics=topics)`
However, if I calculate the document embeddings myself and pass them to BERTopic like so:
`topic_model.fit_transform(docs, embeddings=embeddings)`
then the `topic_embeddings_` are not updated after using `update_topics`. This is because the call to `_create_topic_vectors` within `update_topics` is done without any arguments being passed, and would normally use `self.embedding_model`, which is None when I define my own embeddings.
How should I perform the update to get new `topic_embeddings_` in this case?
Could a kwarg for passing pre-calculated embeddings to `update_topics` be added?
### BERTopic Version
Version: 0.16.4
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 inspecting update_topics and its call to _create_topic_vectors, then reproduce the behavior using fit_transform with pre-calculated embeddings. Trace how the embedding model is stored and used during the update. Done means the documented pre-calculated-embedding workflow updates topic_embeddings_ consistently, with coverage for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- 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