t-SNE
t-SNE (t-distributed Stochastic Neighbor Embedding) is a dimensionality reduction technique used to visualize high-dimensional data (like embeddings from a local LLM) in 2D or 3D scatter plots. It preserves local structure: points that are close in the original high-dimensional space stay close in the low-dimensional projection. Operators encounter t-SNE when analyzing model outputs or embedding clusters—for example, plotting sentence embeddings from a local model to see how different prompts cluster. t-SNE is computationally expensive (O(n²)) and non-deterministic; results vary with the perplexity parameter. It's not used for inference, only offline analysis.
Deeper dive
t-SNE works by converting high-dimensional Euclidean distances into conditional probabilities that represent similarities, then minimizing the Kullback-Leibler divergence between those distributions in high and low dimensions. The key parameter is perplexity (roughly the effective number of neighbors), typically set between 5 and 50. Lower perplexity emphasizes local structure; higher perplexity considers more global structure. t-SNE is stochastic—each run produces a different embedding, so operators should run multiple times to confirm patterns. It scales poorly beyond ~10,000 points; for larger datasets, UMAP is often preferred. In local AI workflows, t-SNE is applied to embedding vectors (e.g., from sentence-transformers or LLM hidden states) to inspect how the model organizes semantic concepts. It's a diagnostic tool, not part of the runtime pipeline.
Practical example
An operator extracts 768-dimensional embeddings from a local sentence-transformer model (e.g., all-MiniLM-L6-v2) for 5,000 customer support queries. Running t-SNE with perplexity=30 in Python (sklearn.manifold.TSNE) reduces each embedding to 2D. The resulting scatter plot reveals clusters: billing questions form one group, technical issues another. This helps the operator decide whether a simple classifier can route queries without a full LLM call.
Workflow example
In a local AI workflow, after generating embeddings with sentence-transformers or extracting hidden states from a Hugging Face model, the operator runs t-SNE offline in a Jupyter notebook: from sklearn.manifold import TSNE; tsne = TSNE(n_components=2, perplexity=30); X_2d = tsne.fit_transform(embeddings). The resulting 2D points are plotted with matplotlib to inspect cluster separation. This is a one-time analysis step—never part of the serving pipeline due to high latency.
Reviewed by Fredoline Eruo. See our editorial policy.