MaartenGr / MaartenGr/BERTopic

model.visualize_hierarchical_documents now shows whole topics

Open
#1,502 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
7.8k
Forks
920
Avg merge
22h 24m
Merged PRs (30d)
5

Description

![image](https://github.com/MaartenGr/BERTopic/assets/41793074/d0e64ec0-8d86-4f7c-acb6-b4e2e057c473)
![image](https://github.com/MaartenGr/BERTopic/assets/41793074/1440a9f9-9cfc-448a-82a0-871ae6805301)
![image](https://github.com/MaartenGr/BERTopic/assets/41793074/7976bce5-8585-44f4-8307-ee8e44156822)

As a result of the topic modeling, I got 40 topics.
And in the topic data frame, I can identify topics 10 and 13.
You can also see them in the topic distance visualization, Hierarchical topic clustering analysis still shows these two topics.

![image](https://github.com/MaartenGr/BERTopic/assets/41793074/be52d51c-84f4-4d7d-97ec-22d1639fb351)

However, when I run topic_model.visualize_hierarchical_documents(), I lose random topics. Whenever I change the number of topics while adjusting the superparameters, I lose 1-2 topics each time.
At first I suspected that the number of documents in a topic was too small to be visualized, but even topics with fewer documents than topics 10 and 13 were visualized.

I followed the steps in the following article.
https://maartengr.github.io/BERTopic/api/plotting/hierarchical_documents.html#bertopic.plotting._hierarchical_documents.visualize_hierarchical_documents
In the above article, I don't see any missing topics.

What could be the problem and how can I fix it?
I'm running with bertopic 0.15.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report points to topic_model.visualize_hierarchical_documents(), BERTopic 0.15.0, the topic data frame, and the hierarchical topic clustering visualization. Start by reproducing the missing-topic behavior with the reported version and compare the topics shown by each visualization. Done means the hierarchical document visualization consistently includes the topics present in the model.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.