Does BERTopic sort the topics in amny order?
- User
Does BERTopic sort the topics in amny order?
- Assistant
BERTopic does not automatically sort topics in any specific order (like by frequency, coherence, or topic number) after modeling. Here’s what happens:
Topic Numbers Are Arbitrary BERTopic assigns numeric labels (e.g., 0, 1, 2, ...) to topics, but these are not sorted by importance or frequency. The numbering simply depends on how HDBSCAN clusters the embeddings.
Default Order in Outputs When you call functions like get_topic_info(), BERTopic returns a dataframe of topics sorted by topic number by default, not by size or importance.
Sorting by Frequency/Size You can manually sort topics by their size (frequency of documents assigned to them) using: pythonCopyEdittopic_info = topic_model.get_topic_info() topic_info.sort_values(by="Count", ascending=False)
This will give you the most frequent topics first.
Custom Sorting If you want topics sorted by coherence or another metric, you need to compute that metric separately and reorder them.
Would you like me to share a code snippet that automatically reorders BERTopic topics by frequency (and updates all references like topic_model.get_topic() accordingly)?