MaartenGr / MaartenGr/BERTopic
option to recalculate c_tf_idf_, topic_representations_ and representative_docs_ after merging after merging models
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.8k
- Forks
- 920
- Avg merge
- 22h 24m
- Merged PRs (30d)
- 5
Description
Hello!
I have been using the merged models to avoid RAM limitations.
After merging my models into a new model, I found that there are no representative documents in model.get_topic_info() and also model.hierarchical_topics(docs) is not working. I solved the problem with the help of:
``` python
# Create a df with the following columns ["Document", "Topic", "ID"]
docs = data["text_caption"].values
topics = data["topic"].values
ids = range(len(docs))
images = None
documents = pd.DataFrame({"Document": docs, "Topic": topics, "ID": ids, "Image": images})
documents_per_topic = documents.groupby(['Topic'], as_index=False).agg({'Document': ' '.join})
merged_model_8.c_tf_idf_, words = merged_model_8._c_tf_idf(documents_per_topic)
merged_model_8.topic_representations_ = merged_model_8._extract_words_per_topic(words, documents, merged_model_8.c_tf_idf_, calculate_aspects=False)
merged_model_8._save_representative_docs(documents)
```
It would be good to have a function/option that does this automatically.
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 with the model merge flow and the mentioned entry points: get_topic_info(), hierarchical_topics(docs), _c_tf_idf, _extract_words_per_topic, and _save_representative_docs. Trace how merged models retain or rebuild these representations, then verify that the resulting model has representative documents and that hierarchical_topics(docs) works without manual recalculation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100