Small Transformers Compute Universal Metric Embeddings

Anastasis Kratsios, Valentin Debarnot, Ivan Dokmanic

TL;DR

This paper proves that a specialized neural network architecture called a probabilistic transformer can embed data from any arbitrary metric space into a space of Gaussian mixtures without suffering from the curse of dimensionality. By leveraging optimal transport metrics, a relatively small transformer (with depth proportional to $n\log(n)$ and width around $n^2$) can faithfully preserve the geometric distances of an $n$-point dataset. This provides a unified, computationally tractable framework for representing complex data geometries like trees, graphs, and manifolds.

What Problem Does This Paper Address?

In machine learning, representing data in a way that faithfully preserves its intrinsic relationships (distances or similarities) is crucial. Traditionally, researchers have mapped data into Euclidean spaces. However, Euclidean spaces are often "too small" or "too flat" to capture complex structures like hierarchical trees, social networks, or curved manifolds without massive distortion.

While alternative spaces like hyperbolic geometry excel at representing trees, they fail when applied to more heterogeneous or unstructured datasets. This paper tackles the challenge of finding a "universal" representation space—and a computationally efficient neural network to map data into it—that can accommodate any arbitrary geometry without requiring custom-tuned tools for every new dataset.

Methods

The authors propose using the space of univariate Gaussian mixtures ($\mathcal{GM}_2(\mathbb{R})$) equipped with a specialized optimal transport metric called the mixed-Gaussian Wasserstein distance ($MW_2$). This space is infinite-dimensional and highly flexible, yet its elements can be exactly parameterized and efficiently computed on a computer.

To map data into this space, they introduce an extension of the probabilistic transformer (PT). The pipeline operates in three distinct phases:

  1. Metric Encoding (Landmarks): An input point from an arbitrary metric space $\mathcal{X}$ is converted into a vector of distances to a fixed set of reference points or "landmarks." This acts as a non-linear coordinate system.
  2. Parameter Generation: This distance vector is fed into parallel, independent ReLU feedforward networks (MLPs) that output the parameters (means, covariances, and mixing weights) of a Gaussian mixture.
  3. Probabilistic Attention: A specialized attention mechanism mixes these components into a final univariate or multivariate Gaussian mixture distribution.
Schematic view of a probabilistic transformer representing a metric space while embedding distinguished data points.

Datasets

The theoretical guarantees are validated using stylized computer experiments on synthetic datasets designed to test different geometric properties:

  • Combinatorial Trees: Regular binary trees of depth six (127 vertices) equipped with the shortest-path metric.
  • Manifolds (Spheres): High-dimensional spheres ($S^2$ up to $S^{45}$) equipped with geodesic (arc-length) distances.
  • Graphs: Random graphs and neighborhood graphs constructed over points sampled from Riemannian manifolds.

Key Insights and Ideas

  • Beating the Curse of Dimensionality: Standard universal approximation theorems require an exponential number of parameters relative to the input dimension. In contrast, the probabilistic transformer's size scales polynomially with the number of data points ($n$), completely independent of the underlying space's dimension.
  • The Embedding Landscape: The complexity of the required transformer depends heavily on the "regularity" of the data's latent geometry. Structured spaces like trees or smooth manifolds are "easiest" to embed, requiring fewer mixture components, whereas unstructured expander graphs require more complex networks.
Embedding landscape of probabilistic transformers showing that structured spaces are easier to embed than unstructured ones.
  • Deterministic vs. Probabilistic Guarantees: For completely unstructured data, the paper provides a trade-off: you can achieve low distortion deterministically if you accept a fractional (bi-Hölder) scaling, or you can achieve strict distance preservation (bi-Lipschitz) for a randomly sampled subset of point pairs (a PAC-type guarantee).

Key Results

  • Manifold Embedding Stability: In experiments embedding $N$-dimensional spheres, standard Euclidean and Hyperbolic feedforward networks saw their embedding quality rapidly deteriorate as the manifold dimension increased. The probabilistic transformer, however, maintained a stable, low relative absolute error across all dimensions.
  • Tree Embedding Performance: When embedding a regular binary tree, the proposed mixture-Wasserstein approach achieved a lower mean error (0.03) and maximum error (0.25) on training points compared to a 2D hyperbolic baseline (mean error 0.15, max error 0.44), performing on par with a much higher-dimensional 15D hyperbolic space.
  • Stronger Regular Guarantees: The authors proved that if the data originates from a compact Riemannian manifold with bounded Ricci curvature, the probabilistic transformer can compute a bi-Lipschitz embedding with an effective dimension of just $3d + 6$, where $d$ is the manifold's dimension.

Limitations and Future Work

While the paper provides robust "memorization" guarantees (proving the network can perfectly fit a finite training dataset $X_n$), it leaves the question of out-of-sample generalization largely open from a theoretical standpoint, even though their empirical tests demonstrated good generalization in practice.

Additionally, the current mathematical proofs rely on a step that passes through a high-dimensional Euclidean space, which the authors note is theoretically suboptimal and likely overestimates the network size actually needed in practice. Future work aims to leverage the true non-linear properties of Gaussian mixtures directly in the proofs to lower these complexity bounds.

Summary updated

BibTeX
@article{kratsios2023small,
  author = {Anastasis Kratsios and Valentin Debarnot and Ivan Dokmanic},
  title = {{Small Transformers Compute Universal Metric Embeddings}},
  journal = {J. Mach. Learn. Res.},
  year = {2023},
  url = {https://openreview.net/forum?id=V_pH_0tIlP5},
}
Figure