Skip to main content
Question 5. When analyzing the output of a transformer-based language model, which technique would be most effective for visualizing the relationship between different concepts in the model’s learned representations? Options: t-SNE or UMAP dimensionality reduction, bar charts of token frequencies, time series analysis, or cumulative distribution functions? Answer: t-SNE or UMAP dimensionality reduction. These nonlinear dimensionality-reduction techniques are the most effective ways to visualize relationships between concepts in high-dimensional embedding spaces. They project high-dimensional token or sentence embeddings into 2D or 3D while preserving neighborhood (local) relationships, enabling inspection of semantic similarity, clustering, and concept separation.
Use UMAP or t-SNE to explore semantic clusters in embedding spaces. For exploratory visualization, UMAP is typically faster and preserves more global structure; t-SNE often produces clearer local clusters but can be slower and requires careful tuning of perplexity.
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.
Comparison table 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.
Example workflow (high-level)
  1. Compute or load embeddings (one vector per token/sentence).
  2. Optionally apply PCA to reduce to ~50 dimensions.
  3. Fit UMAP or t-SNE to 2D/3D.
  4. Plot with colors/markers reflecting labels or cluster assignments.
Example: PCA + UMAP
Example: PCA + t-SNE
Hyperparameter tips
  • 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).
Interpretation guidance
  • 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.
Summary
  • 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.
Links and references

Watch Video