Inferensys

Glossary

BERTopic

A modern topic modeling technique that leverages pre-trained transformer embeddings and class-based TF-IDF to create dense clusters representing coherent topics.
ML engineer managing model training cluster on laptop, GPU utilization visible, technical deep learning setup.
NEURAL TOPIC MODELING

What is BERTopic?

BERTopic is a modern topic modeling technique that leverages pre-trained transformer embeddings and class-based TF-IDF to create dense clusters representing coherent, easily interpretable topics.

BERTopic is a modular topic modeling algorithm that generates document embeddings using pre-trained transformer models like Sentence-BERT, then clusters these high-dimensional vectors with HDBSCAN to identify dense semantic groups. Unlike traditional generative models such as Latent Dirichlet Allocation (LDA), it does not assume a fixed number of topics or rely on bag-of-words representations, instead preserving contextual meaning through deep neural embeddings.

After clustering, BERTopic applies a class-based variant of TF-IDF (c-TF-IDF) to extract topic representations, treating all documents in a cluster as a single combined document to identify the most salient terms. This approach produces highly coherent, human-interpretable topics while maintaining the flexibility to model dynamic topic evolution and incorporate custom embedding models for domain-specific corpora.

MODULAR TOPIC MODELING

Key Features of BERTopic

BERTopic is a modern topic modeling technique that leverages pre-trained transformer embeddings and class-based TF-IDF to create dense clusters representing coherent topics. Its modular design allows for flexible component swapping at each stage of the pipeline.

01

Document Embedding

The pipeline begins by converting documents into dense vector representations using pre-trained transformer models. By default, BERTopic uses sentence-transformers to generate semantically rich embeddings that capture contextual meaning beyond simple keyword frequencies.

  • Supports any Hugging Face embedding model
  • Can integrate spaCy, Gensim, or Word2Vec models
  • Enables multilingual topic modeling with cross-lingual embeddings
  • Preserves semantic similarity: documents with similar meaning cluster together even with different vocabulary
02

Dimensionality Reduction

High-dimensional embeddings are reduced to a lower-dimensional space to combat the curse of dimensionality. BERTopic defaults to UMAP (Uniform Manifold Approximation and Projection), which preserves both local and global data structure better than traditional PCA.

  • Default UMAP preserves neighborhood structure for clustering
  • Optional PCA or t-SNE for specific use cases
  • Handles sparse high-dimensional data efficiently
  • Critical step: poor reduction leads to fragmented or merged topics
03

Cluster-Based Topic Discovery

Reduced embeddings are clustered using HDBSCAN, a density-based algorithm that automatically identifies clusters of varying densities and marks outliers as noise. Unlike K-Means, HDBSCAN does not require pre-specifying the number of topics.

  • Noise points are treated as outliers, not forced into topics
  • Automatically discovers the natural number of topics
  • Handles clusters of different shapes and densities
  • Outlier reduction improves topic coherence by excluding ambiguous documents
04

Class-Based TF-IDF (c-TF-IDF)

Instead of calculating term importance across individual documents, BERTopic computes class-based TF-IDF where each topic cluster is treated as a single aggregated document. This identifies words that are frequent within a topic but rare across all topics.

  • Formula: weights term frequency by inverse class frequency
  • Produces highly discriminative topic-word distributions
  • Enables dynamic topic labeling from top-ranked terms
  • Outperforms standard TF-IDF for topic representation by modeling inter-topic distinctiveness
05

Topic Representation & Fine-Tuning

BERTopic offers multiple strategies for generating human-readable topic labels beyond raw c-TF-IDF keywords. The Maximal Marginal Relevance (MMR) algorithm balances term relevance with diversity to avoid redundant keywords.

  • KeyBERTInspired: uses embedding similarity to refine keywords
  • Part-of-Speech filtering: retains only nouns and adjectives
  • GPT-based labeling: generates natural language topic names via LLMs
  • Zero-shot topic merging: consolidates similar topics using semantic similarity thresholds
06

Dynamic Topic Modeling

BERTopic extends static topic modeling to temporal analysis by tracking how topics evolve over time. Documents are binned by timestamp, and topic frequencies are calculated per time slice to model topic evolution without retraining separate models.

  • Topics over Time: visualizes topic frequency trends
  • Merging and splitting detection: identifies topic drift
  • Normalizes for varying document volumes across time periods
  • Enables longitudinal analysis of thematic shifts in document streams
BERTopic

Frequently Asked Questions

Explore common questions about BERTopic, a modern topic modeling technique that leverages transformer embeddings and class-based TF-IDF to create dense, coherent topic clusters.

BERTopic is a modern topic modeling technique that leverages pre-trained transformer embeddings and class-based TF-IDF (c-TF-IDF) to create dense clusters representing coherent topics. Unlike traditional models like LDA that rely on bag-of-words representations, BERTopic operates in three distinct stages. First, it converts documents into high-dimensional vector embeddings using sentence transformers, capturing deep semantic context. Second, it reduces the dimensionality of these embeddings using UMAP (Uniform Manifold Approximation and Projection) to preserve both local and global data structure. Third, it applies HDBSCAN, a density-based clustering algorithm, to identify dense regions of semantically similar documents while treating outliers as noise. Finally, it extracts topic representations by treating all documents in a cluster as a single combined document and applying c-TF-IDF, which weights terms based on their frequency within a topic relative to their frequency across all topics. This modular architecture allows BERTopic to discover topics with arbitrary shapes, handle noise effectively, and produce highly interpretable topic-word distributions without requiring a pre-specified number of topics.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.