Scripts2026年7月6日·1 分钟阅读

BERTopic — Neural Topic Modeling with Transformers

BERTopic is a topic modeling library that uses transformer embeddings, UMAP dimensionality reduction, and HDBSCAN clustering to discover interpretable topics from text documents.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
BERTopic Overview
直接安装命令
npx -y tokrepo@latest install 56cec9fe-7913-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

BERTopic is a topic modeling technique that combines document embeddings from sentence transformers with a class-based TF-IDF procedure (c-TF-IDF) to generate coherent topic representations. Unlike LDA, it does not assume a fixed number of topics and can discover the optimal topic count automatically through density-based clustering.

What BERTopic Does

  • Discovers topics from document collections without specifying the number of topics in advance
  • Represents each topic with interpretable keywords derived from c-TF-IDF scores
  • Supports dynamic topic modeling to track how topics evolve over time
  • Enables hierarchical topic merging for exploring topic granularity
  • Generates topic visualizations including intertopic distance maps and bar charts

Architecture Overview

BERTopic's pipeline has four stages. First, documents are embedded into dense vectors using a sentence transformer (or any custom embedding model). Second, UMAP reduces the embedding dimensionality while preserving local structure. Third, HDBSCAN clusters the reduced embeddings into groups, with outliers assigned to a noise topic. Fourth, c-TF-IDF computes per-topic word importance scores to produce human-readable topic labels. Each stage is modular and can be swapped with alternatives (PCA instead of UMAP, k-means instead of HDBSCAN, KeyBERT for representation).

Self-Hosting & Configuration

  • Install with pip install bertopic (includes sentence-transformers, umap-learn, hdbscan)
  • Configure the embedding model via BERTopic(embedding_model='all-MiniLM-L6-v2') or pass a custom model
  • Adjust UMAP and HDBSCAN parameters for cluster granularity and noise handling
  • Save and load trained models with topic_model.save() and BERTopic.load()
  • Use GPU-accelerated embeddings for faster processing on large corpora

Key Features

  • Modular design: swap out embedding, reduction, clustering, and representation components independently
  • Dynamic topic modeling tracks topic evolution across timestamps
  • Online learning mode for incremental updates without retraining from scratch
  • Multi-modal support: combine text with images for visual topic modeling
  • LLM-enhanced topic labels using GPT or other language models for more descriptive names

Comparison with Similar Tools

  • Gensim LDA — classic probabilistic topic model requiring a fixed topic count; BERTopic discovers topics automatically with richer representations
  • Top2Vec — similar embedding-based approach; BERTopic adds c-TF-IDF for more interpretable topics and offers more customization
  • Scikit-learn NMF/LDA — lightweight but limited to bag-of-words; BERTopic uses contextual embeddings
  • CorEx — information-theoretic topic model supporting anchored topics; BERTopic is more flexible with modern transformers
  • LDA2Vec — combines LDA with word2vec; less actively maintained than BERTopic

FAQ

Q: How many documents does BERTopic need to produce good topics? A: Generally a few hundred documents suffice, but quality improves with thousands. Very small corpora (under 100 docs) may not cluster well.

Q: Can I specify the number of topics? A: Yes. Set nr_topics to reduce topics after fitting, or use min_topic_size and HDBSCAN parameters to control granularity during clustering.

Q: Does BERTopic support languages other than English? A: Yes. Use a multilingual embedding model (e.g., paraphrase-multilingual-MiniLM-L12-v2) and BERTopic will discover topics in any language.

Q: Can I update a trained model with new documents? A: Yes. BERTopic supports online learning via partial_fit() and transform() to incorporate new documents without full retraining.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产