Open Manas-Shrivastav opened 11 months ago
It might not be able to connect to the OpenAI servers. Could you perhaps try any prompt and use openai
directly to see whether it can make a connection? Also, a good tip is to follow along with the best practices. For instance, I would advise not using nr_topics="auto"
and instead use min_topic_size
since it requires fewer calls to the API.
import openai from bertopic.representation import KeyBERTInspired, MaximalMarginalRelevance, OpenAI, PartOfSpeech
KeyBERT
keybert_model = KeyBERTInspired()
GPT-3.5
prompt = """ I have a topic that contains the following documents: [DOCUMENTS] The topic is described by the following keywords: [KEYWORDS]
Based on the information above, extract a short but highly descriptive topic label of at most 5 words. Make sure it is in the following format: topic:
"""
client = openai.OpenAI(api_key="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
openai_model = OpenAI(client, model="gpt-3.5-turbo", exponential_backoff=True, chat=True, prompt=prompt)
All representation models
representation_model = { "KeyBERT": keybert_model, "OpenAI": openai_model, # Uncomment if you will use OpenAI }
from bertopic import BERTopic
topic_model = BERTopic(
Pipeline models
embedding_model=embedding_model,
umap_model=umap_model, representation_model=representation_model,
Hyperparameters
nr_topics= "auto",
min_topic_size=30,
verbose=True )
topics, probs = topic_model.fit_transform(subgroup_dfs['Pet Foods']['productMaterial'])