Sub topic 16
Refining Topics: Reduction, Merging, and Better Labels
Assume you understand BERTopic’s embedding, clustering, and c-TF-IDF stages. Topic refinement changes how an already fitted model groups or describes documents. It does not automatically make the underlying text more meaningful, so inspect the result after every change.
Reducing the number of topics
A fitted BERTopic model may produce too many small topics. Topic reduction combines similar topics until the model reaches a target number. Similarity is usually calculated from topic representations, such as their c-TF-IDF vectors.
# Assume docs, topic_model, and topics came from fit_transform(docs)
topic_model.reduce_topics(docs, nr_topics=8)
reduced_topics = topic_model.topics_
print(topic_model.get_topic_info().head(10))Reduction is useful when a corpus contains many closely related themes. However, a smaller number is not always better. Combining “database security” with “web security” might simplify a report but remove a distinction that matters to users.
Merging topics explicitly
Use merging when you know which topics belong together. The argument is a list of groups. Each group contains topic IDs that should become one topic.
# Merge topics 2 and 5 into one topic.
topic_model.merge_topics(docs, [[2, 5]])
print(topic_model.get_topic_info().head())
print(topic_model.get_topic(2))Topic IDs can change after reduction or merging. Do not store an ID as a permanent meaning. Record the model version and inspect get_topic_info() after each operation.
| Refinement | Best use | Main risk |
|---|---|---|
| Automatic reduction | Many similar topics | Important distinctions disappear |
| Explicit merging | A domain rule identifies related topics | The rule may be subjective |
| Better representation | Existing groups are useful but poorly named | Labels can hide weak clusters |
Improving topic representations and labels
A topic’s label is a human-facing summary. Changing the representation model changes the words used to describe a topic. It does not move documents between clusters.
BERTopic can use alternative representation models, such as KeyBERTInspired, to find more representative words. You can also assign labels yourself after reviewing representative documents.
from bertopic.representation import KeyBERTInspired
# Assume topic_model has already been fitted.
representation_model = KeyBERTInspired()
topic_model.update_topics(
docs,
representation_model=representation_model,
)
labels = {
0: "Football matches",
1: "Government policy",
}
topic_model.set_topic_labels(labels)
print(topic_model.get_topic_info()[["Topic", "Name", "Count"]])The custom labels improve presentation, but they do not prove that the topic is coherent. Compare each label with its top words and representative documents.
A refinement workflow
Exercise
Why does assigning a custom label not change a document's topic assignment?
Show answer
A custom label changes only the displayed name. Document assignments come from the fitted embeddings and clustering, while labels are metadata added afterward.