Why t-SNE / UMAP are preferred over the other listed options
- Bar charts of token frequencies: show token counts and distributional properties of the corpus, but do not capture geometric relationships in embedding space.
- Time series analysis: suited to temporal trends and sequence behavior, not spatial neighborhood structure in vector embeddings.
- Cumulative distribution functions (CDFs): summarize similarity-score distributions, but cannot reveal cluster topology or neighborhood relationships.
Practical recommendations
- Preprocess embeddings: standard scale and optionally apply PCA (e.g., to 50 dims) before UMAP/t-SNE to speed computation and reduce noise.
- Choose the right tool:
- UMAP: usually the default—faster, scales well, preserves more global relationships.
- t-SNE: useful when you need very clear local clusters; requires careful hyperparameter tuning.
- Reproducibility: set random seeds—both UMAP and t-SNE are stochastic.
- Visual cues: color points by label, token type, cluster assignment, or model-derived scores (e.g., attention weight or prediction confidence) to make semantic structure obvious.
- Compute or load embeddings (one vector per token/sentence).
- Optionally apply PCA to reduce to ~50 dimensions.
- Fit UMAP or t-SNE to 2D/3D.
- Plot with colors/markers reflecting labels or cluster assignments.
- t-SNE:
perplexity: typically 5–50. Smaller values emphasize very local structure; larger values reveal broader groupings.learning_rate: often between 100 and 1000.n_iter: at least 500–1000; more iterations can improve stability.
- UMAP:
n_neighbors: controls local vs. global structure (small → very local, large → more global). Typical values: 5–50.min_dist: controls how tightly points are packed (lower → tighter clusters).
- Look for coherent clusters where semantically similar tokens/sentences are near each other.
- Use colors/markers for known labels (e.g., POS tags, concept labels, or predicted classes) to validate semantic separation.
- Beware of over-interpreting absolute distances—UMAP/t-SNE emphasize relative neighborhood relationships, not exact metric preservation.
- Validate clusters quantitatively (e.g., silhouette score, cluster purity) rather than relying solely on visual appearance.
t-SNE and UMAP are stochastic. To ensure reproducibility and comparability, set
random_state/seed, log hyperparameters (e.g., perplexity, n_neighbors, min_dist), and, when appropriate, run multiple seeds to check stability.- For visualizing relationships between concepts in LLM learned representations, prefer UMAP or t-SNE, with UMAP as a practical default for exploratory work and larger datasets.
- Combine dimensionality reduction with preprocessing (PCA), color/annotate points by labels or scores, and validate findings with quantitative metrics.