Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bertopic assign topics to data frame

I have build a topic model with Bertopic. After getting topic how could I assign them to dataset.

My main aim is to convert unsupervised topic modelling to supervised multi label classification problem.

like image 341
Bhola Bsm Avatar asked Feb 23 '26 07:02

Bhola Bsm


1 Answers

You can write the topics directly with the original data set in a dataframe because the topics are output in the same order as they are contained in the docs.

import pandas as pd 
model =  BERTopic.load('path')
df = pd.DataFrame({ 'topic': model.topics_,'document': docs['id']})
like image 177
padul Avatar answered Feb 25 '26 20:02

padul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!