Skip to contents

Overview

sbert sbert-package
sbert: Topic modeling with Sentence-BERT embeddings

Encoding text

Turn text into Sentence-BERT embeddings and compare them.

encode()
Encode texts as sentence embeddings
pool()
Pool token embeddings into sentence embeddings
topic_similarity()
Compute cosine similarity between embeddings

Models and runtime

Install the ONNX Runtime, download revision-pinned models, load custom Hugging Face exports, and manage the on-disk cache.

models()
List the pinned models
model_download()
Download a pinned model
load_model()
Load an installed pinned model
load_custom()
Load a Hugging Face embedding model outside the pinned list
model_status()
Check the installed files of a model
model_remove()
Remove a pinned model from the cache
install_runtime()
Install ONNX Runtime
cache_dir()
Locate the model cache
cache_size()
Measure the disk space of the model cache

Preparing a corpus

Deduplicate, clean, segment, and context-blend documents before modeling.

dedupe()
Collapse repeated texts and count them
clean_corpus()
Clean a corpus before encoding
strip_list_markers()
Remove list and enumeration markers from text
content_ratio()
Compute the share of letters in text
segment()
Split documents into sentences, clauses, or phrases
abbreviations()
List the abbreviations protected from sentence splitting
blend()
Blend segment embeddings with their document context
stop_words()
Get and adjust the stop-word list

Fitting topic models

Prepare a corpus once, fit topics, compare topic counts, and merge topics.

topic_corpus()
Prepare a corpus once for several topic models
topics()
Fit semantic topics to documents
compare_topics()
Compare numbers of topics and segmentation levels
fitted(<sbert_topic_sweep>)
Extract a fitted model from a topic-count comparison
reduce_topics()
Merge the topics of a model into fewer topics

Describing topics

Distinctive terms, representative texts, names, sizes, and keywords.

terms(<sbert_topic_model>)
Compute the terms of each topic
representatives()
Select representative texts for each topic
name_topics()
Name the topics of a fitted model
topic_sizes()
Compute the size of each topic
keywords()
Extract the keywords of documents

Assigning topics

Assign new documents and recover soft memberships and topic mixtures.

predict(<sbert_topic_model>)
Assign new documents to fitted topics
topic_membership()
Compute graded topic membership
topic_gamma()
Compute document-topic mixtures from segments

Evaluating topics

Coherence, diversity, and the hierarchy of topic centers.

coherence()
Score the coherence of topics
topic_diversity()
Measure the diversity of topic terms
topic_hierarchy()
Build the hierarchy of the topics of a model
summary(<sbert_topic_model>)
Summarize a topic model
summary(<sbert_topic_sweep>)
Summarize a topic-count comparison
summary(<sbert_topic_hierarchy>)
Summarize a topic hierarchy

Plots

Deterministic base-graphics displays of models, comparisons, and hierarchies.

plot(<sbert_topic_model>)
Plot a fitted topic model
plot(<sbert_topic_sweep>)
Plot a topic-count comparison
plot(<sbert_topic_hierarchy>)
Plot a topic hierarchy as a dendrogram
topic_palette()
Get colors that distinguish topics in plots

Results

Tidy tables of result objects, and their print methods.

as.data.frame(<sbert_topic_model>)
Convert a topic model to a data frame
as.data.frame(<sbert_topic_sweep>)
Convert a topic-count comparison to a data frame
as.data.frame(<sbert_topic_hierarchy>)
Convert a topic hierarchy to a data frame
as.data.frame(<sbert_topic_corpus>)
Convert a prepared topic corpus to a data frame
print(<sbert_model>)
Print a loaded model
print(<sbert_topic_corpus>)
Print a prepared topic corpus
print(<sbert_topic_model>)
Print a topic model
print(<sbert_topic_hierarchy>)
Print a topic hierarchy
print(<sbert_topic_sweep>)
Print a topic-count comparison
print(<summary.sbert_topic_model>)
Print a topic model summary
print(<summary.sbert_topic_sweep>)
Print a topic-count comparison summary
print(<summary.sbert_topic_hierarchy>)
Print a topic hierarchy summary

Data

Bundled corpora and precomputed embeddings for offline examples.

feedback_translations
AI-generated mathematics feedback with English translations
feedback_embeddings
Precomputed embeddings of 600 feedback messages
covid
COVID-19 research abstracts