| hf_cluster_texts | R Documentation |
Perform k-means clustering on text embeddings.
hf_cluster_texts(data, k = 3, ...)
data |
A data frame with an 'embedding' column (from hf_embed_text). |
k |
Integer. Number of clusters. Default: 3. |
... |
Additional arguments passed to stats::kmeans(). |
The input data frame with an added 'cluster' column.
## Not run:
library(ggplot2)
# Cluster documents
docs_clustered <- docs_embedded |>
hf_cluster_texts(k = 3)
# Reduce dimensions and visualize
library(uwot)
emb_matrix <- do.call(rbind, docs_clustered$embedding)
coords <- umap(emb_matrix)
docs_clustered |>
mutate(umap_1 = coords[, 1], umap_2 = coords[, 2]) |>
ggplot(aes(umap_1, umap_2, color = factor(cluster))) +
geom_point(size = 3)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.