t-distributed Stochastic Neighbor Embedding (t-SNE) is a nonlinear dimensionality reduction technique primarily used for visualizing high-dimensional data in a low-dimensional space, typically two or three dimensions. Developed by Laurens van der Maaten and Geoffrey Hinton in 2008, it improves upon Stochastic Neighbor Embedding by employing a Student‑t distribution in the low‑dimensional map to mitigate the crowding problem. t‑SNE converts pairwise similarities between data points into joint probabilities and minimizes the Kullback–Leibler divergence between the probability distributions of the high‑dimensional and low‑dimensional embeddings, making it especially effective at revealing local structure and clustering patterns.

1 Background

Dimensionality reduction is a fundamental task in data analysis, enabling the compression of high‑dimensional observations into a lower‑dimensional representation while preserving essential structure. The need arises from the curse of dimensionality and the desire to visualize complex datasets in two or three dimensions.

1.1 Dimensionality reduction overview

Dimensionality reduction methods can be broadly classified into linear techniques, such as Principal Component Analysis (PCA) and Multidimensional Scaling (MDS), and nonlinear techniques, such as Isomap, Locally Linear Embedding, autoencoders, and t‑SNE. The goal is to find a mapping from the original high‑dimensional space to a low‑dimensional space that retains meaningful properties of the data, often pairwise distances or neighborhood relationships.

1.2 Limitations of linear methods (e.g., PCA)

Linear methods project data onto a linear subspace, which is insufficient when the underlying data manifold is curved or contains complex cluster structures. PCA, for example, captures directions of maximum variance but cannot separate nonlinearly separable clusters. t‑SNE was designed specifically to overcome these limitations by preserving local neighborhood probabilities, allowing it to reveal clusters, subclusters, and intricate patterns that linear techniques miss.

2 Algorithm

The t‑SNE algorithm consists of two main stages: constructing probability distributions in the original high‑dimensional space and in the low‑dimensional embedding, then minimizing the Kullback–Leibler divergence between them.

2.1 High‑dimensional similarities

In the high‑dimensional space, pairwise similarities are modeled using a Gaussian kernel centered at each data point.

2.1.1 Gaussian kernel and perplexity

For each data point \(x_i\), the similarity to another point \(x_j\) is proportional to \(\exp(-\|x_i - x_j\|^2 / 2\sigma_i^2)\). The bandwidth \(\sigma_i\) is chosen such that the resulting conditional distribution has a fixed perplexity, a user‑defined parameter. Perplexity can be interpreted as a soft number of effective neighbors; common values range from 5 to 50.

2.1.2 Conditional probability computation

The conditional probability \(p_{j|i}\) is defined as \[ p_{j|i} = \frac{\exp(-\|x_i - x_j\|^2 / 2\sigma_i^2)}{\sum_{k \neq i} \exp(-\|x_i - x_k\|^2 / 2\sigma_i^2)}, \] with \(p_{i|i}=0\). The final symmetric joint probability is \(p_{ij} = (p_{j|i} + p_{i|j}) / (2n)\).

2.2 Low‑dimensional similarities

In the low‑dimensional map, points \(y_i\) are embedding coordinates. Their similarity is defined using a heavy‑tailed distribution to alleviate the crowding problem.

2.2.1 Student‑t distribution with one degree of freedom

The joint probability \(q_{ij}\) between low‑dimensional points \(y_i\) and \(y_j\) is \[ q_{ij} = \frac{(1 + \|y_i - y_j\|^2)^{-1}}{\sum_{k \neq l} (1 + \|y_k - y_l\|^2)^{-1}}, \] with \(q_{ii}=0\). The use of a Student‑t distribution with one degree of freedom (Cauchy distribution) allows moderate dissimilar points in the map to be placed further apart than would be possible with a Gaussian, thus better preserving global structure while focusing on local neighborhoods.

2.3 Cost function and gradient

t‑SNE minimizes the Kullback–Leibler divergence between the high‑dimensional and low‑dimensional joint distributions: \[ C = KL(P\|Q) = \sum_{i \neq j} p_{ij} \log \frac{p_{ij}}{q_{ij}}. \] The gradient with respect to the map point \(y_i\) is \[ \frac{\partial C}{\partial y_i} = 4 \sum_j (p_{ij} - q_{ij}) (y_i - y_j) (1 + \|y_i - y_j\|^2)^{-1}. \] This gradient is used to update the embedding.

2.4 Optimization details

The optimization is performed via iterative gradient descent with specific heuristics to avoid poor local minima.

2.4.1 Gradient descent with momentum

Updates follow \(y_i^{(t)} = y_i^{(t-1)} + \eta \frac{\partial C}{\partial y_i} + \alpha(t) (y_i^{(t-1)} - y_i^{(t-2)})\), where \(\eta\) is the learning rate and \(\alpha(t)\) is a momentum term (often 0.5 for the first 250 iterations and 0.8 thereafter).

2.4.1.1 Early exaggeration factor

During the first 250 iterations, all \(p_{ij}\) are multiplied by a factor (e.g., 4 to 12). This early exaggeration forces tightly clustered points to be pulled closer together, helping to form natural clusters early in the optimization.

2.5 Barnes‑Hut approximation

For large datasets, exact computation of all pairwise probabilities is O(n²). The Barnes‑Hut approximation reduces this to O(n log n) by treating far‑away groups of points collectively.

2.5.1 Space partitioning (quadtree/octree)

The low‑dimensional embedding is partitioned using a quadtree (2D) or octree (3D). Points in distant cells are approximated as a single node with a weighted average position, and their contributions to the gradient are computed using the cell’s center of mass. A user‑defined theta parameter controls the trade‑off between speed and accuracy.

3 Interpretation and visualization

Understanding what t‑SNE reveals (and does not reveal) is crucial for correct interpretation.

3.1 Output mapping properties

t‑SNE preserves local neighborhoods well: points that are close in the original space tend to stay close in the map. However, distances between widely separated clusters are not meaningful. The size, shape, and relative positions of clusters are influenced by local density and random initialization.

3.2 Choice of perplexity parameter

Perplexity acts as a smooth measure of the effective number of neighbors. A low perplexity (e.g., 5) emphasizes very local structure, often producing many small clusters. A high perplexity (e.g., 50) incorporates more global information and tends to form larger, more coherent clusters. There is no single correct value; multiple runs with different perplexities are recommended.

3.3 Random seed and reproducibility

Because t‑SNE uses stochastic initialization and gradient descent with momentum, different random seeds yield different maps. For reproducibility, a fixed random seed must be set. Analysts should run t‑SNE multiple times to confirm that consistent patterns emerge.

4 Applications

t‑SNE is a popular tool in many fields where high‑dimensional data require visual inspection.

4.1 Bioinformatics (e.g., single‑cell RNA‑seq)

In single‑cell RNA sequencing, thousands of genes are measured per cell. t‑SNE has been widely used to visualize cell subpopulations, revealing distinct clusters corresponding to different cell types or states. Combined with clustering algorithms, it helps identify biological structure.

4.2 Image and text embedding visualization

t‑SNE is often applied to the last hidden layer of deep neural networks to inspect learned representations. For example, image features from a convolutional network can be projected into 2D, showing semantic categories. Similarly, word embeddings (e.g., word2vec) are frequently visualized with t‑SNE to reveal relationships.

4.3 Exploratory data analysis

Beyond specific domains, t‑SNE is a standard exploratory tool for any tabular dataset. It allows analysts to quickly detect clusters, outliers, and patterns, guiding further modeling or hypothesis generation.

5 Limitations and pitfalls

Despite its popularity, t‑SNE has notable shortcomings that users must be aware of.

5.1 Interpretation of distances and cluster sizes

Since the low‑dimensional map distances are not proportional to original distances, one cannot deduce the relative size or density of clusters from their visual separation. A large empty region in the map does not imply a gap in the data; it may simply be due to the repulsive forces in the optimization.

5.2 Non‑convexity and sensitivity to initialization

The cost function is non‑convex, meaning the algorithm can converge to different local optima depending on initialization. Two runs with different random seeds may produce visually different layouts, even if the underlying clusters are stable. This requires careful validation.

5.3 Scalability and computational complexity

The exact t‑SNE algorithm has O(n²) time and memory complexity, making it impractical for datasets beyond tens of thousands of points. The Barnes‑Hut approximation improves scaling but still requires significant memory and runtime for very large datasets (e.g., hundreds of thousands of points).

6 Extensions and variants

Several modifications have been proposed to address t‑SNE’s limitations and extend its applicability.

6.1 Parametric t‑SNE

Parametric t‑SNE trains a neural network to learn a mapping from the high‑dimensional space to the low‑dimensional embedding. This allows the model to be applied to new, unseen data points without re‑running the optimization, and can also handle larger datasets via minibatch training.

6.2 Out‑of‑sample extension

Non‑parametric t‑SNE does not provide a function for new points. Out‑of‑sample methods (e.g., interpolation or training a separate regressor) can approximate the embedding of new data by fixing the existing map and only optimizing the new point’s position.

Uniform Manifold Approximation and Projection (UMAP) and LargeVis are newer techniques that share conceptual similarities with t‑SNE. UMAP uses a different mathematical foundation (Riemannian geometry) and often offers faster performance and better preservation of global structure. LargeVis employs a similar probability‑based framework but with a different cost function and graph construction, achieving better scalability for very large graphs. These methods have largely replaced t‑SNE in many large‑scale visualization tasks.