MaartenGr / MaartenGr/BERTopic

Topics returned from model.transform differ from model.fit_transform

Open
#905 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi,

When I run BERTopic using model.fit_transform on my dataset, it will return cluster numbers and titles that make sense for the input data. When I run the same string through the trained model using model.transform, it returns a different cluster number, though it is consistent. For example, something with "Mexican restaurant" might get assigned to topic 1 "restaurant_mexican restaurant_full service restaurant", but when I run the exact same record through model.transform, I'll get a different integer for the topic (corresponding to something totally different) and even a different probability - and these can even differ between runs of model.transform on the same trained model. Am I doing something wrong? This has been befuddling me. Note the topic numbers from model.get_topic_info and those returned from model.fit_transform do correspond with one another.

Perhaps related, but I saw a similar frustrating difference in the outputs of get_topic_info and the output when using calculate_probabilities=True, where the columns of the probability array did not correspond to the topic numbers from get_topic_info.

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 mismatch by comparing model.fit_transform, model.transform, get_topic_info, and calculate_probabilities on the same records. Trace how topic IDs and probability columns are produced and mapped; done means repeated transforms return stable assignments whose IDs and probability columns correspond to get_topic_info.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.