Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'OpenAIBackend' object has no attribute 'encode' #2136

Open
mahmawad opened this issue Sep 4, 2024 · 1 comment
Open

AttributeError: 'OpenAIBackend' object has no attribute 'encode' #2136

mahmawad opened this issue Sep 4, 2024 · 1 comment

Comments

@mahmawad
Copy link

mahmawad commented Sep 4, 2024

Hi,
I still get this error message despite I use the last commit & version from bertopic, could you please help ?

Code:

import openai
from bertopic.backend import OpenAIBackend
from openai import AzureOpenAI
client = AzureOpenAI(
api_version = "2023-09-15-preview",
api_key =os.getenv("OPENAI_API_KEY").strip(),
azure_endpoint ="https://x-.openai.azure.com/",
)
embedding_model = OpenAIBackend(client,"text-embedding-3-large")

embeddings = embedding_model.encode(df['PreprocessedText'].tolist(), show_progress_bar=True)

from bertopic import BERTopic

Initialize and train BERTopic model

topic_model = BERTopic(
embedding_model=embedding_model,
vectorizer_model=vectorizer_model,
umap_model=umap_model,
calculate_probabilities=True,
#hdbscan_model=hdbscan_model,
representation_model=representation_model,
verbose=True,
nr_topics=10
)

Fit the topic model and transform the data

topics, probs = topic_model.fit_transform(df['PreprocessedText'].values)

@MaartenGr
Copy link
Owner

The encode method that you refer to is specific to sentence-transformers package. You would have to use embed instead. I would advise checking out the source code and see which methods are available: https://github.com/MaartenGr/BERTopic/blob/master/bertopic/backend/_openai.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants