MaartenGr / MaartenGr/BERTopic
AttributeError: 'OpenAIBackend' object has no attribute 'encode'
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.8k
- Forks
- 920
- Avg merge
- 22h 24m
- Merged PRs (30d)
- 5
Description
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)
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 by checking the BERTopic OpenAIBackend API and the installed BERTopic version against the reported encode call, then reproduce the example with AzureOpenAI. The issue is done when the embedding backend can be used with the shown workflow and BERTopic fit_transform completes without the AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100