Topic modelling with Bertopic

24-05-2026

Bertopic is a topic modelling technique. We have of documents, we want to cluster similar documents and assign them relevant topics. The algorithm proposed in Bertopic is modular, making it easy to try different implementations at each step.

The general workflow ciomprises the following:

  • embedding documents
    • sentence-transformers, openai
  • reducing dimensionality of embeddings
    • UMAP
  • clustering reduced embeddings into topics
    • HDBSCAN
  • tokenization of topics
    • bag of words
  • weight tokens
    • cTF-IDF (all documents within a cluster are converted into one document)
  • represent topics with one or multiple representations

Questions:

  • which dimensionality reduction to use
    • UMAP vs t-SNE vs PCA
    • metric is cosine
    • embeddings live on a hypershpere, Euclidean distorts
    • for returns overlay, you want the 2D coordinates to be stable across reruns (UMAP is stable with a fixed seed but shifts if you add notes)
    • should you cluster in high-dim (true semantic structure) or in 2-D UMAP
    • 3D vis vs 2D vis, what are the differences?
    • what content shold be used for the embeddings?
      • does adding metadata help improve things? or does this make informaiton lossy or conflated?
      • ie adding author, tags, title?
    • do recommnedations seperate in embedding space at all
      • label-vs-cluster agreement
      • silhouette score by recommendation label (treat recommendation as the cluster assignment)
      • k-NN purity
      • linear probe (train logistic regression on the 3072-D mmbedding -> recommendation)
    • how do we handle imbalanced datasets
      • 85% of notes are BUY, 13% are HOLD, 2% are SELL

Goals:

(b) When returns data arrives, the eventual question becomes: does position in embedding space predict forward returns better than recommendation alone? That’s a regression (embedding → return) vs (one-hot recommendation → return). But scoping that now is premature — we’ll wire it in when returns land.