I have trained a topic model using Top2Vec as follows:
import pandas as pd
from top2vec import Top2Vec
df = data = [['1', 'Beautiful hotel, really enjoyed my stay'], ['2', 'We had a terrible experience. Will not return.'], ['3', 'Lovely hotel. The noise at night, we however did not appreciate']]
df = pd.DataFrame(data, columns=['reviewID', 'Review'])
docs = df.text.tolist()
ids = df.reviewID.tolist()
model = Top2Vec(docs, speed = 'deep-learn', workers = 14, document_ids = ids)
Now I would like to reassign the topic(s) that each review was assigned back to the original df for further analyses.
I can retrieve the documents by topic as follows:
documents, document_scores, document_ids = model.search_documents_by_topic(topic_num=45, num_docs=5)
for doc, score, doc_id in zip(documents, document_scores, document_ids):
print(f"Document: {doc_id}, Score: {score}")
print("-----------")
print(doc)
print("-----------")
print()
I however get stuck when trying to retrieve all reviews, each with its assigned topic so as to reassign it to the original df.
Thank you for your help:)