MaartenGr / BERTopic

Leveraging BERT and c-TF-IDF to create easily interpretable topics.
https://maartengr.github.io/BERTopic/
MIT License
5.76k stars 716 forks source link

Can't update model name when use notebook #2030

Open Tongzhao9417 opened 4 weeks ago

Tongzhao9417 commented 4 weeks ago

I have a quick question: I use openai embedding to generate the text-embedding. I found I couldn't update the model name unless I restart the jupyter kernal. But it's ok when I switch to python (not jupyter). Here is an example code

import openai
from bertopic.backend import OpenAIBackend
client = openai.OpenAI(api_key="sk-xxxxx")
embedding_model = OpenAIBackend(client, 'text-embedding-3-large')
print(embedding_model.embedding_model)

Here is screenshot from notebook and python:

notebook:

image

python script:

image image
MaartenGr commented 4 weeks ago

This shouldn't be possible (I think) if you are using the exact same environments in both the Python and Jupyter examples. Are they somehow different?

Tongzhao9417 commented 4 weeks ago

This shouldn't be possible (I think) if you are using the exact same environments in both the Python and Jupyter examples. Are they somehow different?

Thank for your reply. I use same environments (VScode and same virtual env). Here is my example code. example_code.zip

How to reproduction: At the notebook, run the code and print the model name.

And then, modify the model name (e.g., text-embedding-3-large to text-embedding-ada-002) and run again. You can see the print also text-embedding-3-large not text-embedding-ada-002

MaartenGr commented 4 weeks ago

Just tried it with the latest version of BERTopic (v0.16.2) and OpenAI (v1.30.5) and it's working without any issues for me.

Tongzhao9417 commented 4 weeks ago

Just tried it with the latest version of BERTopic (v0.16.2) and OpenAI (v1.30.5) and it's working without any issues for me.

Thank you for your work. I switch to another IDE (pycharm) and create a new environment and update to latest bertopic and openai. It's still can't change model. Maybe it's a problem with jupyter and ipykernal.

I paste full reproduction process in case someone have same issue

image