Rhobots
BERTopic-Style Topic Modelling in Pure R
🤖 Rhobots
The full BERTopic pipeline — transformer embeddings, UMAP dimensionality reduction, HDBSCAN density clustering, and class-based TF-IDF — running entirely in R. No Python. No conda. No reticulate.
📦 CRAN v0.1.6 🔬 MIT License 🖥️ R ≥ 4.1 🪟 Windows · 🍎 macOS · 🐧 Linux
The Pipeline
Rhobots implements the four-stage BERTopic pipeline as a set of modular, pluggable R objects. Each stage can be swapped out independently — use PCA instead of UMAP, k-means instead of HDBSCAN, or bring your own representation model.
<span class="icon">📝</span>
<div class="label">Embed</div>
<div class="pkg">torch · safetensors</div>
→
<span class="icon">📉</span>
<div class="label">Reduce</div>
<div class="pkg">uwot · UMAP</div>
→
<span class="icon">🔵</span>
<div class="label">Cluster</div>
<div class="pkg">Rcpp · HDBSCAN</div>
→
<span class="icon">🏷️</span>
<div class="label">Represent</div>
<div class="pkg">c-TF-IDF · POS</div>
Resources
Hands-on
Full Tutorial
A complete walkthrough on 3,328 African research abstracts — from raw text to labelled topics, quality sweep, interactive visualisations, and LLM-generated topic names.
How it works
How UMAP Works
Step-by-step technical explainer with illustrations: the manifold hypothesis, fuzzy membership weights, SGD optimisation, and the effect of every parameter.
How it works
How HDBSCAN Works
Core distances, mutual reachability distance, Borůvka MST, the condensed cluster tree, EOM extraction, and what every parameter actually controls.
Why Rhobots?
<span class="fi">🐍</span>
<p><strong>No Python dependency.</strong> The entire pipeline — embeddings, UMAP, HDBSCAN,
c-TF-IDF — runs in R through <code>torch</code>, <code>uwot</code>, and <code>dbscan</code>.</p>
<span class="fi">🤗</span>
<p><strong>Any Hugging Face model.</strong> Load BERT, SciBERT, BGE, E5, SPECTER2, or any
BERT-architecture model directly from the Hub with <code>load_hf_bert()</code>.</p>
<span class="fi">🔢</span>
<p><strong>Automatic topic count.</strong> HDBSCAN finds the right number of topics for your
data — no need to pre-specify <em>k</em>.</p>
<span class="fi">🔍</span>
<p><strong>Hyperparameter sweep.</strong> <code>sweep_topics()</code> evaluates many
parameter combinations in one call, reusing cached embeddings.</p>
<span class="fi">🌿</span>
<p><strong>Noise-aware.</strong> Documents that don't fit any topic get label <em>−1</em>
rather than being forced into a cluster.</p>
<span class="fi">🔌</span>
<p><strong>Pluggable architecture.</strong> Swap any stage — use PCA instead of UMAP,
k-means instead of HDBSCAN, or a custom representation model.</p>
How It Compares
LDA (topicmodels) |
STM (stm) |
Rhobots | |
|---|---|---|---|
| Needs Python | No | No | No |
| Pre-trained embeddings | No | No | Yes |
| Topic count specified | Yes (fixed k) | Yes (fixed k) | Automatic |
| Handles noise | No | No | Yes (label −1) |
| Non-linear structure | No | No | Yes (UMAP + HDBSCAN) |
| Domain-specific encoders | No | No | Yes (any HF model) |
| Hyperparameter sweep | No | No | Yes |
Installation
Step 1 — Install from CRAN:
install.packages("Rhobots")Step 2 — Install the torch backend (once per machine, ~560 MB download):
library(Rhobots)
rhobots_install()
# Restart your R session when promptedWindows users must first install the Microsoft Visual C++ Redistributable 2022 before running rhobots_install().
Step 3 — Try the built-in demo:
rhobots_demo()The demo downloads four Gutenberg books, embeds them, sweeps parameters, fits a topic model, and produces an interactive visualisation — no data files needed.
Quick Start
library(Rhobots)
# 1. Load a sentence encoder
enc <- load_hf_bert("sentence-transformers/all-MiniLM-L6-v2")
# 2. Embed your documents (result cached to disk)
emb <- embed_texts_cached(enc, docs, cache_file = "emb.rds", normalize = TRUE)
# 3. Sweep parameters to find the best combination
sw <- sweep_topics(docs, emb,
n_neighbors = c(10, 15, 20),
n_components = c(5, 10),
min_pts = c(10, 20, 30))
print(sw)
# 4. Fit with the best parameters
fit <- fit_bertopic(docs, emb,
umap_n_neighbors = sw$best$n_neighbors,
umap_n_components = sw$best$n_components,
hdbscan_min_pts = sw$best$min_pts)
# 5. Inspect topics
print(fit)
visualize_barchart(fit)
visualize_topics(fit)Citation
If you use Rhobots in research, please cite:
van der Pol, J.P.G. (2026). Rhobots: BERTopic-Style Topic Modeling Without Python.
R package version 0.1.6. https://github.com/JPvdP/Rhobots
The algorithm is based entirely on the Python BERTopic package by Maarten Grootendorst.