Paper commentary
Embedding Dimension of Contrastive Learning and $k$-Nearest Neighbors
Arboricity of comparison graphs bounds the embedding dimension for contrastive and k-NN data
- Problem Before this work, no theory gave the embedding dimension needed for contrastive triplets or k-NN lists.
- Method The authors bound the needed dimension by the arboricity of each comparison's constraint graph, which counts how many forests cover its edges.
- Results The authors show an ℓ2 dimension of order √m suffices for m contrastive triplets and is necessary.
Why embedding dimension matters for distance comparisons
Embedding dimension is a key design choice when a deep learning architecture is picked. The question here is the smallest dimension d of an ℓp-space that can hold a given set of distance comparisons. Two kinds of comparison data are studied: contrastive triplets and k-NN lists.
Each contrastive triplet says the positive example must sit closer to the anchor than the negative one, and the embedding must respect every such inequality. Before this work there was no theoretical study of the embedding dimension for these settings.
For k-NN, each item comes with its ordered list of nearest neighbors, which is a dense set of comparisons. Read as triplets, the k-NN information amounts to n(n − 1) constraints, far more than a bound linear in n would suggest.
Turning comparisons into a constraint graph
Each contrastive sample adds edges from the anchor to its positive and negative examples, skipping edges that already exist. In the k-NN setting, each point gets an edge to each of its k nearest neighbors.
Arboricity is the least number of forests whose union covers all edges, so it stays small for sparse graphs and grows when a dense subgraph appears. Fact 7 bounds the arboricity of a graph with m edges by roughly the square root of m, so m samples give arboricity around √m at most.
An orientation of the edges gives an ordering in which each point has only a few earlier neighbors, and the later constructions rely on this ordering. For the k-NN graph the arboricity is at most k + 1.
An ℓ2 embedding driven by arboricity
Using the bound on arboricity for m samples gives the contrastive ℓ2 result, a dimension of order m^{1/2}.
The same theorem applied to the k-NN graph gives an ℓ2 dimension of order k that preserves the ordering of each list. This embedding preserves the order of each list but can move points so that a non-neighbor becomes a neighbor.
Extending the bounds to ℓp and ℓ∞
For integer p ≥ 1 the construction reduces to a partial semimetric and embeds it in dimension at most m + 1. Table 1 lists an upper bound of O(m) for integer p, with lower bounds that differ between even and odd p.
For ℓ∞ the points split into high-degree and low-degree sets, with the high-degree set of size O(m^{2/3}). Low-degree points are handled with graph colorings and high-degree points with a Fréchet-like embedding, which gives dimension O(m^{2/3}).
Preserving the order of k-NN lists
The k-NN constraint graph has arboricity at most k + 1, which makes the arboricity bound applicable. Theorem 6 gives an ℓ2 embedding of dimension O(k) that keeps the k-NN ordering.
For ℓp with p ≥ 1, Theorem 10 gives dimension O(r^2 log^3 n), so with r at most k + 1 the ordering needs roughly k^2 up to logarithmic factors.
Keeping the k-NN sets as nearest neighbors
The embedding of Theorem 10 keeps the order but can change which points are nearest, so an extension is needed. The extension gives each point a random choice among design vectors, so neighbors pick the same vector more often than non-neighbors.
Sharing a vector adds nothing to the distance between two points, while different vectors add at least (2 − α)R. Lemma 21 then shows that the gap between neighbor distances and non-neighbor distances exceeds the spread among neighbors.
The construction uses L = Θ(r^4 log^4 n) parts, and the final dimension is O(k^10 log^10 n) for constant p ≥ 1. A footnote notes that later versions improved the analysis to Õ(k^3).
Hardness and partial satisfaction
With d = 1, finding an ℓ2 embedding that satisfies given contrastive constraints is NP-hard, by reduction from betweenness. So no polynomial algorithm exists in the realizable case unless P = NP.
If only an α fraction of constraints must hold and α is at most 1/2, one random dimension already satisfies half of them in expectation. Above the threshold α* ≈ 0.77, satisfying the constraints needs dimension of order √m for even p.
CIFAR experiments on contrastive triplets
The authors build triplets from ground-truth distances of a pretrained ResNet-18 and train new ResNet-18 models from scratch with triplet loss for 50 epochs. The output dimension is set by the last fully-connected layer, and results on CIFAR-10 and CIFAR-100 are averaged over 5 runs with embedding dimension 128 in the sample sweep.
When d is at least √m, the learned embedding satisfies at least 99% of the triplets. The authors read this as consistent with Theorem 1.
Moving from 64 to 256 adds 2% accuracy, while moving from 256 to 1024 adds none.
Limitations
The experiments use only CIFAR-10 and CIFAR-100 with ResNet-18.
The partial-satisfaction result leaves a gap between α = 1/2 and α* ≈ 0.77, which the authors expect may be improvable. The authors note that the dependence on k and log n in the k-NN bound may be improvable, and that data-dependent bounds are not captured.
Paper info
- Authors
- Avdiukhin, Dmitrii, Chatziafratis, Vaggos, Fischer, Orr, Yaroslavtsev, Grigory
- Venue
- Advances in Neural Information Processing Systems · Published
- First published
- 2024-12-16
- Added
- 2026-11-25
- DOI
- 10.52202/079017-1309
- Original paper terms
- Check in the original ↗
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Avdiukhin, Dmitrii, Chatziafratis, Vaggos, Fischer, Orr, Yaroslavtsev, Grigory (2024). Embedding Dimension of Contrastive Learning and $k$-Nearest Neighbors. Advances in Neural Information Processing Systems. https://doi.org/10.52202/079017-1309
BibTeX
@article{dmitrii2024embedding,
title = {{Embedding Dimension of Contrastive Learning and $k$-Nearest Neighbors}},
author = {Avdiukhin, Dmitrii and Chatziafratis, Vaggos and Fischer, Orr and Yaroslavtsev, Grigory},
year = {2024},
journal = {Advances in Neural Information Processing Systems},
doi = {10.52202/079017-1309},
url = {https://papers.nips.cc/paper_files/paper/2024/hash/487c9d6ef55e73aa9dfd4b48fe3713a6-Abstract-Conference.html}
}