Skip to contents

sbert fits topic models of texts from their sentence embeddings. A sentence embedding places a text in a space where texts with similar meaning lie close together, whatever words they use (Reimers and Gurevych 2019), so topics found in that space group texts by what they mean rather than by the words they share. Each topic is described by its most typical texts and by its distinctive terms, scored with class-based TF-IDF (Grootendorst 2022). Topics can be fitted to whole documents or to their sentences, clauses, or phrases, compared across numbers of topics by coherence and diversity, and used to assign new texts and give each document a mixture of topics.

The embeddings come from pretrained models, each fixed to one version (see models()). A model is downloaded only when it is first needed, with model_download() or after a prompt in an interactive session, and is stored in the user cache (cache_dir()); nothing is downloaded when the package is installed or loaded. The bundled feedback_embeddings let every topic-model function run without any download.

Models and embeddings

Texts are tokenized by the 'tok' package and encoded on the ONNX Runtime through 'onnxr'; pooling, normalization, and all of the topic modeling are done in R. Each model is fixed to one revision and its files are checked by SHA-256, so every user encodes with the same model.

Preparing a corpus

Fitting and choosing topic models

The fits are deterministic: k-means starts from fixed farthest-point centers, so no random seed is involved and the same input gives the same topics.

Describing topics

Assigning topics to texts

References

Reimers, N. and Gurevych, I. (2019). Sentence-BERT: Sentence embeddings using Siamese BERT-networks. Proceedings of EMNLP-IJCNLP 2019, 3982–3992. doi:10.18653/v1/D19-1410

Grootendorst, M. (2022). BERTopic: Neural topic modeling with a class-based TF-IDF procedure. arXiv:2203.05794.

Author

Maintainer: Sonsoles López-Pernas sonsoles.lopez@uef.fi (ORCID) [copyright holder]

Authors: