How do I cluster 3 Million high-dimensional Sentence Embeddings?

I used a transformer model to generate normalized 768-dimensional float32 vectors from 3 million sentences. This rounds up to roughly 9 GB of data. To progress further in my analysis, I want to cluster the data to highlight different key points and trends.

Now I initially wanted to apply PCA to the dataset, as 768 dimensions is pretty much, but the transformer model generated embeddings with not extreme enough covariance.
Thus, PCA could change the semantics too much for an analysis to be accurate.

I went directly to clustering algorithms and initially tried to apply sklearn.cluster.HDBSCAN which would have needed way too much RAM---around 72 TBi if I remember correctly. Then I tried out sklearn.cluster.OPTICS, which "only" needed about 70 GB, but as I "only" have 32 GB of RAM I needed to use 50 GB swap space, which didn't go well as you can imagine.

Does it make sense to try out k-means clustering, should I go to 16-bit floats for the embeddings, or still apply PCA?

Should I try out something else in this context?

Note: As this question was flagged "off topic" on Stack Overflow, I'm gonna try here ;)

reddit.com
u/spaceweed27 — 15 hours ago
▲ 5 r/AskStatistics+2 crossposts

How do I cluster 3 Million high-dimensional Sentence Embeddings?

I used a transformer model to generate normalized 768-dimensional float32 vectors from 3 million sentences. This rounds up to roughly 9 GB of data. To progress further in my analysis, I want to cluster the data to highlight different key points and trends.

Now I initially wanted to apply PCA to the dataset, as 768 dimensions is pretty much, but the transformer model generated embeddings with not extreme enough covariance.
Thus, PCA could change the semantics too much for an analysis to be accurate.

I went directly to clustering algorithms and initially tried to apply sklearn.cluster.HDBSCAN which would have needed way too much RAM---around 72 TBi if I remember correctly. Then I tried out sklearn.cluster.OPTICS, which "only" needed about 70 GB, but as I "only" have 32 GB of RAM I needed to use 50 GB swap space, which didn't go well as you can imagine.

Does it make sense to try out k-means clustering, should I go to 16-bit floats for the embeddings, or still apply PCA?

Should I try out something else in this context?

Note: As this question was flagged "off topic" on Stack Overflow, I'm gonna try here ;)

reddit.com
u/spaceweed27 — 15 hours ago

As a Stoner I have to say, this shit fucking sucks!

Literally a worse version of the concert version, which only really worked on stage.

Bro took everything good out of the masterpiece and filled it with a (based) political message, which just doesn't fucking fit musically. He really fell off the last years as a musician, and tbh as a lyricist aswell.

u/spaceweed27 — 2 months ago