MaartenGr / MaartenGr/BERTopic
TypeError:'NoneType' object is not subscriptable while calling topic_model.hierarchical_topics
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 trying zero-shot topic modelling with BERTopic. The following fit_transform ran successfully:
topic_model = BERTopic(
embedding_model="thenlper/gte-small",
min_topic_size=50,
zeroshot_topic_list=zeroshot_topic_list,
zeroshot_min_similarity=.85,
representation_model=KeyBERTInspired()
)
topics, _ = topic_model.fit_transform(docs)
topic_model.get_topic_info()
While running hierarchical_topics = topic_model.hierarchical_topics(docs), getting the following error:
TypeError:'NoneType' object is not subscriptable
Open Traceback
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[87], line 1
----> 1 hierarchical_topics = topic_model.hierarchical_topics(docs)
File /mnt/xarfuse/uid-564347/e4f2f620-seed-nspid4026531836_cgpid15010019-ns-4026531841/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
zeroshot_topic_list contains 251 topics, docs are 15k. Similar code without zeroshot works fine. Please let me know if you have any insights, thanks!
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 in bertopic.py at BERTopic.hierarchical_topics, especially the c_tf_idf access around line 975, and reproduce the failure with the zero-shot configuration shown. Compare it with the non-zero-shot case that works. Done means hierarchical_topics completes for the zero-shot model and returns the expected hierarchy without the NoneType error.
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
- Clearly specified
- Newbie friendliness
- 38/100