MaartenGr / MaartenGr/BERTopic

c_tf_idf_ is None when using zero shot topic modeling.

Open
#2,003 1 comment 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

I am using zero shot topic modeling using bertopic and i also want hierarchical topic representation but When i run the model.hierarchical_topics(array of strings) the following errors is what i get:

TypeError: 'NoneType' object is not subscriptable
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File , line 1
----> 1 model.hierarchical_topics(array of strings)

File /local_disk0/.ephemeral_nfs/cluster_libraries/python/lib/python3.10/site-packages/bertopic/_bertopic.py:975, in BERTopic.hierarchical_topics(self, docs, linkage_function, distance_function)
972 linkage_function = lambda x: sch.linkage(x, 'ward', optimal_ordering=True)
974 # Calculate distance
--> 975 embeddings = self.c_tf_idf_[self._outliers:]
976 X = distance_function(embeddings)
977 X = validate_distance_matrix(X, embeddings.shape[0])

TypeError: 'NoneType' object is not subscriptable

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

Start in _bertopic.py at BERTopic.hierarchical_topics, especially the c_tf_idf_ access around line 975, and trace how zero-shot topic modeling initializes that attribute. Reproduce the reported call with the provided document array and verify that hierarchical topic representation no longer fails when c_tf_idf_ is None.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.