Is there a way to calculate the perplexity of BERTopic? I am unable to find any such thing in the BERTopic library and in other places.
Asked
Active
Viewed 520 times
0
-
did you manage to find out how? – Allanckw Mar 11 '23 at 10:29
1 Answers
2
I managed to figure it out how to get the log perplexity, and then convert it back
import numpy as np
model = BERTopic(top_n_words =15,
calculate_probabilities=True)
topics, probs = model.fit_transform(docs) # docs = dataset
log_perplexity = -1 * np.mean(np.log(np.sum(probs, axis=1)))
perplexity = np.exp(log_perplexity)

Allanckw
- 641
- 1
- 6
- 17