BERTopic icon indicating copy to clipboard operation
BERTopic copied to clipboard

Apllying code in my own dataset

Open nassera2014 opened this issue 5 years ago • 2 comments

Hi, Thank you for this great job, i'm beginner in BERT, and i want to use your code to extract topics from arabic text (stored on MongDB), do you have an idea how can i do this? thank you so much.

BR

nassera2014 avatar Dec 07 '20 18:12 nassera2014

XLM-R from sentence-transformers is trained on 50+ languages including Arabic. To use BERTopic for Arabic text use the following code:

from bertopic import BERTopic
model = BERTopic("xlm-r-bert-base-nli-stsb-mean-tokens", verbose=True)
topics, probabilities = model.fit_transform(docs)

Of course, you will have to define docs yourself.

MaartenGr avatar Dec 08 '20 08:12 MaartenGr

@nassera2014 you may also find some luck in using the arabic-bert-base model which was pre-trained on ~8.2 Billion words.

Once you load the pre-trained model, extracting embeddings is pretty similar to Maarten's example since they both are a HuggingFace model. And after that, fit_transforming the model should be easy.

armandidandeh avatar Dec 20 '20 06:12 armandidandeh