'BERTopic' object has no attribute 'topics' issue
fatihbozdag opened this issue · 1 comments
fatihbozdag commented
Greetings,
Following the sample code on Bertopic and KeyphraseVectorizers, I got AttributeError: 'BERTopic' object has no attribute 'topics'
!pip install keyphrase-vectorizers
!pip install bertopic
!pip install --upgrade joblib==1.1.0
from keyphrase_vectorizers import KeyphraseCountVectorizer
from bertopic import BERTopic
import pandas as pd
df = pd.read_csv('/content/university.csv')
docs = df["text_field"]
keyphrase_topic_model = BERTopic(vectorizer_model=KeyphraseCountVectorizer())
keyphrase_topics, keyphrase_probs = keyphrase_topic_model.fit_transform(docs)
/usr/local/lib/python3.7/dist-packages/bertopic/vectorizers/_ctfidf.py:69: RuntimeWarning: divide by zero encountered in true_divide
idf = np.log((avg_nr_samples / df)+1)
keyphrase_topic_model.topic
AttributeError Traceback (most recent call last)
[<ipython-input-18-cdb7ccda80a7>](https://localhost:8080/#) in <module>
----> 1 keyphrase_topic_model.topics
AttributeError: 'BERTopic' object has no attribute 'topics'
Why does sample code fail in my case?
fatihbozdag commented
so the solution is, rather than keyphrase_topic_model.topic
, it should be keyphrase_topic_model.topic_info()