MaartenGr / MaartenGr/BERTopic

Different number of topics for different training runs on the same dataset

Open
#1,817 13 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

Hi,

I am facing issue. If I train bertopic on a same dataset multiple times, I am getting different number of topics .

As per the discussion in this thread: https://github.com/MaartenGr/BERTopic/issues/461 . I have tried below two ways . But neither resolved the issue. In both ways running code multiple times is giving different number of topics:-

I am running programme on amazon sagemaker notebook instance.

docs : this my list of documents used in training .

(1)
from sklearn.feature_extraction.text import CountVectorizer
from umap import UMAP
from bertopic import BERTopic

vectorizer_model = CountVectorizer(ngram_range=(2, 3), stop_words='english')
umap_model = UMAP(random_state=42)
topic_model = BERTopic(vectorizer_model=vectorizer_model , umap_model=umap_model)
topics, probabilities = topic_model.fit_transform(docs)

(2)
from sklearn.feature_extraction.text import CountVectorizer
from umap import UMAP
from bertopic import BERTopic

vectorizer_model = CountVectorizer(ngram_range=(2, 3), stop_words='english')
umap_model = UMAP(n_neighbors=15, n_components=5, min_dist=0.0, metric='cosine', random_state=42)
topic_model = BERTopic(vectorizer_model=vectorizer_model , umap_model=umap_model)
topics, probabilities = topic_model.fit_transform(docs)

Thank you!

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

Reproduce the repeated BERTopic fit_transform runs in the SageMaker notebook using the two CountVectorizer and UMAP configurations shown. Read the linked issue #461 alongside the UMAP random_state settings and compare the resulting topic counts across runs. Done means identifying and documenting the remaining source of nondeterminism or confirming the expected behavior.

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
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.