# 语义聚类

语义聚类是一种文本挖掘方法，它按含义将词、句子或文档分组：先把每个条目转换为稠密向量（嵌入），再对在该空间中向量彼此接近的条目进行聚类，而不是把共享词频等表面特征的条目分到一组。<sup>[1](https://peerj.com/articles/cs-2078/)</sup> “语义”这一步将它和经典的基于特征的聚类区分开来：TF-IDF 表示无法考虑词在句子中的位置和上下文，而 BERT 等 Transformer 表示则两者都能纳入。<sup>[2](https://link.springer.com/article/10.1186/s40537-022-00564-9)</sup> 基于统计频率的打分同样会遗漏多义（一个词有多个含义）和同义（多个词有同一含义）问题，而基于嵌入的分组正是为解决这些问题而设计的。<sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC8421191/)</sup>

| 关键事实 | 细节 |
| --- | --- |
| 标准相似度度量 | 嵌入向量之间的余弦相似度，得到一个对称的 n × n 矩阵，取值在 −1 与 1 之间<sup>[1](https://peerj.com/articles/cs-2078/)</sup> |
| 典型流程 | 嵌入文档，用 UMAP 降维，用 HDBSCAN 或 k-means 聚类<sup>[4](https://handsonllm-hands-on-large-language-models-40.mintlify.app/chapters/chapter-05-clustering-topics)</sup> |
| 嵌入与 TF-IDF 对比 | 在四种算法和三个数据集上，BERT 表示在 36 项聚类指标中的 28 项上优于 TF-IDF<sup>[2](https://link.springer.com/article/10.1186/s40537-022-00564-9)</sup> |
| 深度聚类准确率 | SDEC 在 AG News 上达到 85.7% 的准确率，在 Yahoo! Answers 上达到 53.63%<sup>[5](https://arxiv.org/abs/2508.15823)</sup> |
| 20 Newsgroups 基准 | 在 N = 1,500 时，使用 OpenAI 3-Small 嵌入报告的最佳 ARI 为 0.4922，NMI 为 0.6516<sup>[6](https://pypi.org/project/semantic-clusterer/)</sup> |
| 长度约束 | 最初的基于 BERT 的句子变换器模型大约接受 75 至 512 个词元；更长的文本会被截断，导致表示质量下降；不过，基于 ModernBERT 的句子变换器等较新架构能接受多得多的词元（至少可达 8192 个）<sup>[7](https://link.springer.com/article/10.1007/s11227-025-07414-4)</sup> |

## 工作原理

该方法建立在向量空间假设之上：含义相似的条目在嵌入空间中占据彼此接近的位置。输入可以是词嵌入、句子嵌入或文档嵌入。句子级工作通常使用 BERT 的孪生式改造；该模型用孪生网络和三元组网络结构训练，以得到语义上有意义的句子嵌入，再用余弦相似度进行比较；这样就不必把每个句子对都直接送入 BERT。<sup>[1](https://peerj.com/articles/cs-2078/)</sup> 这类模型在微调时以[余弦相似度](https://www.edgepedia.org/zh/cosine-similarity)作为回归目标，并通过 CLS 词元、平均池化或最大池化生成嵌入；在语义文本相似度任务上，它们的表现优于 InferSent 和通用句子编码器（Universal Sentence Encoder）。<sup>[7](https://link.springer.com/article/10.1007/s11227-025-07414-4)</sup>

余弦相似度衡量两个向量之间的夹角，返回 −1 到 1 之间的值，从而得到聚类所依赖的对称相似度矩阵。<sup>[1](https://peerj.com/articles/cs-2078/)</sup>

## 实施方法

常见流程分三步：嵌入文档、降维、聚类。<sup>[4](https://handsonllm-hands-on-large-language-models-40.mintlify.app/chapters/chapter-05-clustering-topics)</sup> 在一个示例中，NLP 研究摘要的 384 维句子变换器嵌入用 UMAP（min_dist = 0.0，metric = 'cosine'）降至 5 维，再用 HDBSCAN（min_cluster_size = 50）聚类，得到 156 个簇。<sup>[4](https://handsonllm-hands-on-large-language-models-40.mintlify.app/chapters/chapter-05-clustering-topics)</sup> 一项针对“矢量化—降维—聚类”流程（BERT 或 Doc2Vec、PCA 或 UMAP、K-Means 或 HDBSCAN）的大规模实证配置研究发现：无论采用哪种算法，BERT 嵌入经 UMAP 降维到不少于 15 维后，都能为聚类提供良好基础；UMAP 优于 PCA，而调整其设置影响不大；HDBSCAN 总体表现最佳，K-Means 略低；性能主要由矢量化部分决定。<sup>[8](https://aclanthology.org/2023.nejlt-1.7.pdf)</sup>

算法选择决定了簇数量如何确定。k-means 等划分方法显式接受 k；层次聚类则接受一个阈值 t，由它间接决定类别数量。<sup>[1](https://peerj.com/articles/cs-2078/)</sup> HDBSCAN 不需要预先指定簇数量，能处理不同密度，并将离群点标记为 −1。<sup>[4](https://handsonllm-hands-on-large-language-models-40.mintlify.app/chapters/chapter-05-clustering-topics)</sup> 当存在标签时，用调整兰德指数（Adjusted Rand Index）和调整互信息（Adjusted Mutual Information）验证质量，二者优势互补；当真实标签由大型等规模簇组成时，ARI 更有优势。<sup>[8](https://aclanthology.org/2023.nejlt-1.7.pdf)</sup> [深度聚类](https://www.edgepedia.org/zh/deep-clustering)工作在这一指标集合中增加了聚类准确率（Clustering Accuracy）和归一化互信息（Normalized Mutual Information）。<sup>[5](https://arxiv.org/abs/2508.15823)</sup> 没有标签时，轮廓系数可指导概念数量或树状图切割高度等选择。<sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC8421191/)</sup> [算法](https://www.edgepedia.org/zh/algorithm)选择与簇数量相互影响：在一项短文本研究中，对于簇较少的数据集，k-means 表现最佳；对于簇较多的数据集，层次凝聚聚类表现最佳；在受测的全部 8 个数据集上，较旧版本的通用句子编码器在两项指标上均比新版本高出几个百分点。<sup>[9](https://ar5iv.labs.arxiv.org/html/2102.00541)</sup><sup> • </sup><sup>[10](https://doi.org/10.48550/arxiv.1803.11175)</sup>

## 起源

没有已发表的文献确定是谁最先在 NLP 中提出“语义聚类”这一术语；其谱系反而经由若干有名目的前驱技术来追溯。早期的一项信息检索技术——潜在语义索引——通过奇异值分解，将大型词项—文档矩阵分解为约 50 至 150 个正交因子，把词项和文档表示为“语义”空间中的向量，以克服词汇匹配不精确的问题。<sup>[11](https://dl.acm.org/doi/abs/10.1145/57167.57214)</sup> 兰道尔（Landauer）和杜迈（Dumais）在《Psychological Review》（1997）上将这一研究方向形式化为知识获取的潜在语义分析理论。<sup>[12](https://doi.org/10.1037/0033-295x.104.2.211)</sup> 1992 年的《词空间》（Word Space）论文把词表示为高维共现空间中的点，这是词嵌入聚类的直接前驱。<sup>[13](https://proceedings.neurips.cc/paper/1992/file/d86ea612dec96096c5e0fcc8dd42ab6d-Paper.pdf)</sup> 名词按其条件动词分布进行聚类，所用距离为 KL 距离（Kullback–Leibler distance），并结合确定性退火。<sup>[14](http://www.cs.columbia.edu/~vh/courses/LexicalSemantics/Similarity/pereira-acl93.pdf)</sup> 通过从解析语料中聚类相似词构建了一部同义词词典，它比罗热同义词词典（Roget Thesaurus）显著更接近 WordNet。<sup>[15](https://dl.acm.org/doi/10.3115/980691.980696)</sup> 霍夫曼（Hofmann）的概率潜在语义分析（2001，《Machine Learning》）将 LSA 视为其关键前驱，并把分布聚类列为一种相关方法。<sup>[16](https://doi.org/10.1023/a:1007617005950)</sup> 现代嵌入时代源自米科洛夫（Mikolov）及其同事的 word2vec skip-gram 工作（2013，arXiv）；该工作本身将分布式词表示追溯至鲁梅尔哈特（Rumelhart）、辛顿（Hinton）和威廉姆斯（Williams，1986）。<sup>[17](https://doi.org/10.48550/arxiv.1310.4546)</sup>

## 变体

若干有名目的变体将嵌入与聚类结合。格鲁滕多斯特（Grootendorst）描述的 BERTopic（2022，arXiv）是流行的 BERT → UMAP → HDBSCAN 主题模型，HDBSCAN 是其默认聚类算法。<sup>[8](https://aclanthology.org/2023.nejlt-1.7.pdf)</sup><sup> • </sup><sup>[18](https://doi.org/10.48550/arxiv.2203.05794)</sup> BERTopic 通过 c-TF-IDF 扩展该流程以进行主题表示，该方法将每个簇视为单个文档，并允许替换嵌入、降维、聚类和表示组件。<sup>[4](https://handsonllm-hands-on-large-language-models-40.mintlify.app/chapters/chapter-05-clustering-topics)</sup> 安格洛夫（Angelov）描述的 Top2Vec（2020，arXiv）利用文档与词的联合语义嵌入来寻找主题向量：它识别文档向量的稠密簇，并把附近的词用作主题词。<sup>[19](https://doi.org/10.48550/arxiv.2008.09470)</sup> 深度聚类在聚类步骤中加入表示学习：SDEC 将改进的自编码器（均方误差加余弦相似度损失）与 Transformer 嵌入，以及带分布损失的软分配聚类层相结合。<sup>[5](https://arxiv.org/abs/2508.15823)</sup> WEClustering 用小批量 K-means 将 1024 维 BERT 词嵌入聚类为“概念”，把词汇表从数万个词缩减到不足一百个概念。<sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC8421191/)</sup> 库苏帕蒂（Kusupati）及其同事描述的[套娃表示学习](https://www.edgepedia.org/zh/matryoshka-representation-learning)（Matryoshka representation learning，2022，arXiv）在完整嵌入维度 d 的 O(log(d)) 个不同表示尺寸上优化原始对比损失，得到紧凑但精度相当的表示。<sup>[20](https://doi.org/10.48550/arxiv.2205.13147)</sup> 在此基础上，一项 2025 年的层次新闻聚类方法利用套娃嵌入的高维部分判断两篇文章是否报道同一事件，利用中间维度判断是否属于同一话题，利用较低维度判断是否属于同一主题。<sup>[21](https://aclanthology.org/2025.acl-long.124.pdf)</sup> 另外，ESMC 利用一个发现：多模态大语言模型中文本词元的隐藏状态与相应特征密切相关，并用这些嵌入按照任意用户定义的标准执行聚类。<sup>[22](https://ojs.aaai.org/index.php/AAAI/article/view/39867)</sup>

## 应用

有文献记载的应用集中在摘要和主题分析。在抽取式摘要中，一个应用于 Score-BERT 句子嵌入的 K-means 模块从不同语义簇中挑选高分句子，从而使所选句子的语义冗余更少；该模型在 CNN/DailyMail 上用 ROUGE 与六个基线进行了评估。<sup>[23](https://www.nature.com/articles/s41598-024-66306-4)</sup> 两步式 [Sentence-BERT](https://www.edgepedia.org/zh/sentence-bert) 方法先嵌入词目，再在余弦距离上运行平均连接（average linkage）的凝聚聚类，并用生成式语言模型为所得主题命名；该方法被应用于行业新闻的信息计量分析，作为 LDA 的替代方案。<sup>[24](https://aurora-journals.com/library_read_article.php?id=75348)</sup> 其他常被引用的应用领域，如病历分组或代码检索，不在本文所综述研究的覆盖范围内。

## 局限与替代方案

经典替代方案——词袋或 TF-IDF 聚类——无法处理多义和同义问题，并受维度灾难困扰：对于大型语料库，维度可达数万到数百万，产生稀疏矩阵，而传统聚类算法对此处理不佳。<sup>[3](https://pmc.ncbi.nlm.nih.gov/articles/PMC8421191/)</sup> 基于嵌入的聚类也有自身的失效模式。欧氏距离可能无法捕捉高维文本中的语义关系，因此 k-means 和层次聚类经常产生次优分组；DBSCAN 和 HDBSCAN 等基于密度的算法能检测任意形状的簇并处理噪声，但在高维数据中往往表现不佳；而 Louvain 模块度最大化等基于图的社区发现，则把文档当作相似度网络中的节点进行划分。<sup>[5](https://arxiv.org/abs/2508.15823)</sup> 句子变换器模型受最大词元数限制，通常根据训练情况为 75 至 512 个词元；更长的文本会被截断，产生不完整的表示和较低的聚类性能，这促使人们对长文档采用句子级或块级的嵌入聚合。<sup>[7](https://link.springer.com/article/10.1007/s11227-025-07414-4)</sup> 与布莱（Blei）、吴恩达（Ng）和乔丹（Jordan）提出的 LDA（2003，《Journal of Machine Learning Research》）相比，基于嵌入的流程用生成式概率模型换取表示质量。<sup>[24](https://aurora-journals.com/library_read_article.php?id=75348)</sup><sup> • </sup><sup>[25](https://doi.org/10.5555/944919.944937)</sup> 最佳 UMAP 维度在各研究中仍未定论：一项流程研究建议使用 15 维或更多，而一项长文本研究发现 5 维为最佳。<sup>[8](https://aclanthology.org/2023.nejlt-1.7.pdf)</sup><sup> • </sup><sup>[7](https://link.springer.com/article/10.1007/s11227-025-07414-4)</sup>

## References

1. [Experimental study on short-text clustering using transformer-based semantic similarity measure](https://peerj.com/articles/cs-2078/)
2. [The performance of BERT as data representation of text clustering](https://link.springer.com/article/10.1186/s40537-022-00564-9)
3. [WEClustering: word embeddings based text clustering technique for large datasets](https://pmc.ncbi.nlm.nih.gov/articles/PMC8421191/)
4. [Chapter 5: Text Clustering and Topic Modeling (Hands-On Large Language Models)](https://handsonllm-hands-on-large-language-models-40.mintlify.app/chapters/chapter-05-clustering-topics)
5. [SDEC: Semantic Deep Embedded Clustering](https://arxiv.org/abs/2508.15823)
6. [semantic-clusterer v0.1.0 (PyPI)](https://pypi.org/project/semantic-clusterer/)
7. [Optimizing SBERT for long text clustering: two novel approaches with empirical insights](https://link.springer.com/article/10.1007/s11227-025-07414-4)
8. [An Empirical Configuration Study of a Common Document Clustering Pipeline](https://aclanthology.org/2023.nejlt-1.7.pdf)
9. [Short Text Clustering with Transformers](https://ar5iv.labs.arxiv.org/html/2102.00541)
10. [Cer, Daniel and colleagues (2018). Universal Sentence Encoder. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1803.11175)
11. [Using latent semantic analysis to improve access to textual information (Deerwester et al., CHI 1990)](https://dl.acm.org/doi/abs/10.1145/57167.57214)
12. [Thomas K. Landauer, Susan T. Dumais (1997). A solution to Plato's problem: The latent semantic analysis theory of acquisition, induction, and representation of knowledge.. Psychological Review.](https://doi.org/10.1037/0033-295x.104.2.211)
13. [Word Space (Schütze, NIPS 1992)](https://proceedings.neurips.cc/paper/1992/file/d86ea612dec96096c5e0fcc8dd42ab6d-Paper.pdf)
14. [Distributional Clustering of English (Pereira, Tishby & Lee, ACL 1993)](http://www.cs.columbia.edu/~vh/courses/LexicalSemantics/Similarity/pereira-acl93.pdf)
15. [Automatic retrieval and clustering of similar words (Lin, ACL 1998)](https://dl.acm.org/doi/10.3115/980691.980696)
16. [Thomas Hofmann (2001). Unsupervised Learning by Probabilistic Latent Semantic Analysis. Machine Learning.](https://doi.org/10.1023/a:1007617005950)
17. [Mikolov, Tomas and colleagues (2013). Distributed Representations of Words and Phrases and their Compositionality. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1310.4546)
18. [Grootendorst, Maarten (2022). BERTopic: Neural topic modeling with a class-based TF-IDF procedure. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2203.05794)
19. [Angelov, Dimo (2020). Top2Vec: Distributed Representations of Topics. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2008.09470)
20. [Kusupati, Aditya and colleagues (2022). Matryoshka Representation Learning. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2205.13147)
21. [Hierarchical Level-Wise News Article Clustering via Multilingual Matryoshka Embeddings](https://aclanthology.org/2025.acl-long.124.pdf)
22. [ESMC: MLLM-Based Embedding Selection for Explainable Multiple Clustering](https://ojs.aaai.org/index.php/AAAI/article/view/39867)
23. [Automatic summarization model based on clustering algorithm](https://www.nature.com/articles/s41598-024-66306-4)
24. [Two-step semantic clustering of embeddings as an alternative to LDA for infometric analysis of industry news](https://aurora-journals.com/library_read_article.php?id=75348)
25. [David M. Blei, Andrew Y. Ng, Michael I. Jordan (2003). Latent dirichlet allocation. Journal of Machine Learning Research.](https://doi.org/10.5555/944919.944937)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Language and vision AI › Natural language processing › NLP tasks and methods › Semantic analysis and decomposition

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/semantic-clustering

English original: https://www.edgepedia.org/semantic-clustering
