Optimal VC Dimension of Contrastive Learning with Margin
Abstract
Contrastive learning is a successful paradigm for learning -dimensional geometric representations from a collection of “anchor–positive–negative” triplets , indicating that “item is closer to than to .” Despite its success, understanding why contrastive learning leads to representations of high generalization quality—beyond the often pessimistic predictions from PAC-learning—remains a central question. Recently, Alon, Avdiukhin, Elboim, Fischer and Yaroslavtsev (2024) proved that, for PAC-learning -dimensional Euclidean representations of -point datasets, triplets are necessary and sufficient, while they posed as an open question whether their VC dimension bounds for the more realistic setting of contrastive learning with a margin can be improved. For a margin parameter , a triplet is satisfied by the embedding , if . In this work, we resolve their question by proving that the VC dimension of contrastive learning under any margin is in fact , improving on the previous bound of . We also establish that the bounds are optimal up to constant factors, by providing a matching lower bound of (the previously known lower bound was ), for .
Contents
1 Introduction
Contrastive learning is a powerful paradigm in representation learning, where the goal is to find meaningful representations, encoded as features in -dimensional Euclidean space, allowing us to replace data point by its feature vector in various downstream tasks. At the heart of contrastive learning lies the notion of a triplet comparison indicating that “item is closer to than to ,” also known as “anchor–positive–negative” (Schroff et al., 2015). For example, modern pipelines are trained with a contrastive loss, e.g., Triplet or InfoNCE (with one or more negatives), mapping data into -dimensional vectors by pulling anchor-positive pairs closer, while pushing anchor-negative pairs further apart, enabling a unified approach for diverse types of data, including text, audio, graph-based tasks, and images (Schroff et al., 2015; Grover and Leskovec, 2016; Oord et al., 2018; Saunshi et al., 2019; Chen et al., 2020).
Unfortunately, despite its empirical success, many theoretical aspects of contrastive learning are not well-understood. In this work, we focus on sample complexity and generalization bounds—a central question in PAC-learning—making progress towards understanding when a representation learned from anchor–positive–negative samples generalizes well to unseen (test) samples.
1.1 Sample Complexity of Contrastive Learning
Following the framework by Alon, Avdiukhin, Elboim, Fischer and Yaroslavtsev (2024), let be an -point dataset and let be an embedding that maps points into -dimensional Euclidean space (we do not make any assumptions on ). Motivated by the anchor–positive–negative paradigm, typically we assume access to a collection of triplets; these are usually generated from data, such as nearby words in a document, or neighboring video frames, that serve as the anchor-positive pair, and then a random other data point plays the role of the negative example. For more on how to pick negative samples, and their role in downstream performance, please refer to Saunshi et al. (2019); Robinson et al. (2020); Awasthi et al. (2022).
Definition 1.1.
We say that the embedding satisfies or is consistent with input triplet if:
More generally, it is common to enforce a small margin in the above distance comparison (Vankadara et al., 2023), i.e., for a margin parameter , the embedding satisfies the triplet if:
The basic question motivating our work concerns the sample complexity of contrastive learning: for a set of items, what is the smallest number of anchor–positive–negative samples required to PAC-learn an underlying ground-truth embedding ?
In particular, we focus on the following problem in PAC-learning studied by Alon, Avdiukhin, Elboim, Fischer and Yaroslavtsev (2024):
Problem 1.2 (PAC-Learning an embedding from triplets Alon et al. (2024)).
Fix error parameters . Given i.i.d. samples drawn from a distribution over , and labeled according to embedding as either or , based on whether , the goal is to find an embedding 11 1 In the contrastive learning with margin setting studied below, learning might require an improper predictor. that generalizes well to unseen triplets, i.e., with probability , for a subsequent sample sampled from :
In other words, for a test triplet query , the learned embedding must classify whether the anchor is closer to or to according to the (unknown) , i.e., whether the triplet is or . Similarly, Problem 1.2 can be studied in the agnostic case (where samples are not necessarily consistent with some embedding), or with quadruplet samples indicating whether from the literature of ordinal embeddings (Bilu and Linial, 2005; Alon et al., 2008; Terada and Luxburg, 2014; Vankadara et al., 2023).
Dimensionality-vs-Generalization.
Recently, Alon, Avdiukhin, Elboim, Fischer and Yaroslavtsev (Alon et al., 2024) showed that the VC-dimension of the learning task in Problem 1.2 is , i.e., they proved that labeled triplets are sufficient22 2 The bound is , since without affecting pairwise distance comparisons (Bilu and Linial, 2005). for PAC-learning the embedding . Typically, stems from the output layer of a neural network, so they focused on the representation dimensionality , a key parameter of interest often ranging in the thousands Radford et al. (2018); Kusupati et al. (2022); Comanici et al. (2025).
1.2 Our Contribution: Generalization from samples, under any margin
For the special case when the margin between distances , Alon et al. (2024) managed to show a matching lower bound of for Problem 1.2. However, it is unclear what happens for the well-motivated case of contrastive learning with margin . Observe that provides some gap between distances, so the dimension can be directly replaced by using standard tools, e.g., Johnson-Lindenstrauss (JL) lemma: as noted in (Alon et al., 2024), JL yields , where is the distortion (Dasgupta and Gupta, 2003), so triplets suffice for generalization (set distortion ). Improving this bound was raised as an open question by Alon et al. (2024):
For contrastive learning with large enough values of margin ,
can the VC-dimension bound be improved beyond ?
Our Main Result.
We go beyond the above approach based on JL, and we obtain optimal bounds in the VC dimension, thus resolving the above question for all values of margin (not necessarily large values as originally stated in Alon et al. (2024)).
Our main result is a stronger, linear in VC-bound of for contrastive learning. This is coupled with a matching lower bound of (for ), so when put together the two results give a tight characterization of the VC dimension in this setting. To make things formal, we need the following definition related to the notion of partial concept classes from Alon et al. (2022):
Definition 1.3 (Concept class for embeddings with margin).
Fix , and let be an embedding. Associated with embedding is its triplet classifier , labeling33 3 Symbol is arbitrary, meaning classifiers may not answer certain queries (e.g., if distances are not separated). an input triplet as follows:
The concept class containing all possible triplet classifiers is denoted44 4 For the case of no margin, we simply write . Note that for embeddings , as in the definition, is a total concept class. as . We only consider embeddings such that for every with , .
Theorem 1.4 (Linear VC-dimension for any margin).
The VC-dimension of is for and for . Specifically, there exists absolute constant such that:
Furthermore, assuming that , the VC dimension is , for and for . In particular there exists an absolute constant such that:
We prove the upper bound of Theorem 1.4 in Section 3, the proof of the lower bound follows the construction for linear classification with margin and is proven in Section 4.
A few remarks are in order. First, our result characterizes the VC-dimension of concept class in the regime where as . Second, it is surprising that under a margin , dimensionality does not play a role: the larger the margin, the easier the learning task becomes, since the sought-after embedding is less refined, and a priori, one might expect that dimension plays a role on the samples required to avoid misclassification of test samples (perhaps this is why Alon et al. (2024) originally asked the question for large margins as a simplification).
Learning Bounds via Geometric Approximation.
An interesting aspect in our analysis that allows us to obtain the VC-bound, is the use of geometric approximation algorithms aiming to satisfy as many of the input triplets as possible. In contrast to the approach taken in Alon et al. (2024), where they used combinatorial bounds on the number of sign-patterns of a system of polynomials, here we essentially reduce the -dimensional learning problem to a -dimensional setting, whose sample complexity we can bound. On the one hand, we exploit the margin to show that a simple one-dimensional projection satisfies fraction of triplets, independently of dimension , where -approximation is a trivial baseline achieved by a random embedding. On the other hand, we use the probabilistic method to show that no set of size can be shattered on the line , and more precisely, there exists a labeling of the triplet samples such that no embedding satisfies more than of the triplets; since can be taken to be sufficiently smaller than this leads to a contradiction, giving us the upper bound of Theorem 1.4. Our approach is similar in spirit to the algorithm of Blum (2005) (see also Balcan and Blum (2005)) for linear classification with margin which combines a random projection coupled with boosting. For formal definitions and a detailed technical overview see Section 2 below.
1.3 Further Related Work
There are intense efforts to understand various aspects of contrastive learning, both from a theoretical and a practical perspective. For example, many well-known works study relations between transfer learning, inductive biases and contrastive learning (Saunshi et al., 2019; Saunshi et al., 2022), posing specific assumptions on latent classes or how contrastive triplets are generated, in order to try to explain the observed success of such methods (Schroff et al., 2015; Oord et al., 2018; Chen et al., 2020). Other works focus more on optimization loss functions such as spectral contrastive loss with good downstream performance (HaoChen et al., 2021), understanding the role of negative samples (Robinson et al., 2020; Awasthi et al., 2022; Lei et al., 2023), adversarial training (Zou and Liu, 2023) and more. Here, the work closest to ours is Alon et al. (2024), which served as the main inspiration towards our sample complexity results.
Moreover, the literature of non-metric embeddings, often called ordinal embeddings or monotone maps (Bilu and Linial, 2005; Alon et al., 2008; Terada and Luxburg, 2014; Emamjomeh-Zadeh and Kempe, 2018; Ghosh et al., 2019; Ghoshdastidar et al., 2019; Fan et al., 2020; Avdiukhin et al., 2023; Chatziafratis and Indyk, 2024; Avdiukhin et al., 2024), is also closely related to our setting, as their main algorithmic task is, given a collection of comparisons between pairwise distances, to find an embedding into a suitable geometric space, e.g., tree metric, ultrametric, or Euclidean space, so that as many of the given pairwise comparisons are satisfied. We note that, because humans are much faster at comparisons between objects, in contrast to providing numerical scores, such triplet comparisons are also widely-deployed in metric learning and crowdsourcing (Schultz and Joachims, 2003; Tamuz et al., 2011; Kulis, 2013). Other types of comparisons include the quadruplet setting mentioned earlier, where comparisons are of the form “item is closer to , than item is to ,” see survey Vankadara et al. (2023).
Finally, there are several results on the computational complexity and approximation algorithms literature associated with the empirical risk minimizer on a given sample. Given (non-contradictory) triplet constraints on items, Bilu and Linial (2005) show that dimensions always suffice to satisfy them, while are necessary. In Avdiukhin et al. (2024), they present an algorithm that achieves dimension and further improve it via the notion of graph arboricity. For the case of non-realizable instances, recent work by Arvanitakis et al. (2026) showed that it is computational intractable to obtain a better than -approximation (assuming the Unique Games Conjecture (Khot, 2002)), showing that the problem of maximizing satisfied triplets is approximation resistant (Hstad, 2001; Hast, 2005; Guruswami et al., 2008).
Regarding more practical approaches based on local search, including gradient-based methods, it is known that in worst-case, finding even a locally optimum solution is intractable, as captured by PLS-completeness55 5 Both PLS and CLS are complexity classes related to finding local optima via local search methods, see Johnson, Papadimitriou and Yannakakis (1988); Daskalakis and Papadimitriou (2011). for discrete settings, and CLS-completeness for continuous embedding settings (Yan et al., 2026). However, it is reported in Vankadara et al. (2023), that popular methods usually obtain near-zero training error for a variety of triplet loss objectives (see also (Bower et al., 2018) on spurious local optima vs global optima).
2 Technical Overview
We present the main proof strategy and technical ideas behind our improved bound on the VC-dimension for the concept class of triplet classifiers with margin.
2.1 Our approach for : Algorithmic Advantage over Random
To give some intuition and set notation, we first describe the approach taken in Alon et al. (2024) for the case of zero margin, and why it fails in our case when margin .
Sign-Patterns of Polynomials vs. margin .
Given that each triplet imposes a geometric constraint on how the representation embeds the data points, a first attempt would be to analyze how partitions -dimensional Euclidean space, and count the regions wherein triplet classifiers do not switch their label. Indeed, Alon et al. (2024) observed that each triplet is satisfied, if and only if the following polynomial on number of variables, and of degree is positive:
In total, this leads to such polynomials (as there are input triplets), with the total number of variables being . Then, Alon et al. (2024) used known results from algebraic combinatorics to upper bound the different sign-patterns of the resulting system of polynomials on variables (Warren, 1968; Alon et al., 1985). This limits the size of a set that can be shattered giving an upper bound on the VC-dimension (see definitions below).
While the above approach worked for the case of no margin , and yielded the bound , a similar approach for would still yield the same (dimension-dependent) bound : notice that if instead we defined the polynomial
the number of sign-patterns does not change, as those depend solely on , the degree of the polynomials and the number of variables.
We take a different approach to exploit the margin through geometric approximation algorithms that estimate triplet labels induced by . On the one hand, the margin allows a -dimensional random projection algorithm to get slightly better-than-random approximations, specifically satisfying fraction of the triplets. This is crucially independent of what the dimension is, and is the reason why our final bound in Theorem 1.4 does not have a dependence on . On the other hand, if the VC-dimension was substantially larger than , and the labels of the training set were chosen at random to be either or , then no embedding could fit the labels of the input triplets, better than random chance, which leads to a contradiction.
2.2 Rounding-vs-Noisy Labels in 1D
To make the above precise, we remind the reader of the standard definitions of VC-dimension and Shattering of a set (Shalev-Shwartz and Ben-David, 2014), adapted to our setting. The appropriate framework for our results is that of Alon et al. (2022), where hypothesis functions can be undefined on certain inputs (this corresponds to the asterisk case in Definition 1.3).
Definition 2.1 (Shattering).
We say that a set is shattered by if for every there exists a concept function such that for every , .
Notice that in the definition, the concept is not allowed to output the special symbol on any of the points. We can now give the definition of the VC dimension of the hypothesis class .
Definition 2.2 (VC-dimension).
The VC-dimension of hypothesis class is the largest number such that there exists a set of size that is shattered. We will use to denote the VC dimension of hypothesis class .
We directly apply the definition of the VC dimension and shattering to prove our main theorem. What we need to show is that for , no set of unlabeled triplets is shattered. Equivalently, starting with arbitrary triplets (one can think of them as being selected by an adversary) we need to show that there is a labeling of the triplets such that no embedding can satisfy all of them. We let be a sufficiently small constant fraction of and let : we show that for a set of unlabeled triplets there exists a labeling (i.e., every unlabeled triplet is labeled as either or ) such that no embedding is consistent with all the labeled triplets.
Rounding to 1D.
Our proof, perhaps surprisingly, begins by an observation drawing ideas from rounding semidefinite programs in the approximation algorithms literature. Suppose that we have a set of triplet constraints with margin , and an embedding that satisfies all the constraints. Then, as we show, one can round the embedding to a one-dimensional embedding so that a fraction of at least of the triplet constraints without margin are satisfied by . A priori this result seems weak: not only the constraints that satisfies are without margin, but also only a fraction of of them are satisfied.66 6 For comparison, a trivial one-dimensional embedding that maps every item to a uniform number in satisfies half of the constraints in expectation. The fact, however, that there always exists such an embedding in one dimension that is strictly better than the random solution ends up being strong enough to give us the result. Our rounding algorithm projects all the embedded vectors along a random direction in a way similar to the MAX-CUT rounding algorithm of Goemans and Williamson (1995), see Lemma 3.2 for the formal statement and proof.
No 1D embedding can fit noise on triplets.
We now go back to our setting where we are given a set of unlabeled triplets, adversarially selected, and we want to show that there is a labeling of the triplets such that no embedding, even in dimensions, can satisfy all of them. The key idea is that our rounding algorithm allows us to focus on the real line and forget about the margin parameter. Recall that Alon et al. (2024) show that the VC-dimension of embeddings in dimension is , and so for , we get that the VC dimension is . What this means in particular, is that no embedding on the real line is able to fit triplets labeled by random noise: if we select the labels of a set of triplets randomly then with constant probability, no embedding will be able to satisfy more than of them. This is formalized by the notion of Rademacher complexity and its bound in terms of the VC-dimension of a hypothesis class (Shalev-Shwartz and Ben-David, 2014; Bousquet et al., 2003). Using the probabilistic method, we get that for every set of unlabeled triplets, there exists a labeling such that no embedding on the real line satisfies more than of them. The formal statement and proof can be found in Lemma 3.4.
2.3 Putting things together
We now discuss how to combine the ideas from the above paragraphs to get the result. Let be the set of adversarially selected triplets and suppose, for the sake of contradiction, that the set is shattered by the hypothesis class . On the one hand, we get that since is large enough and linear in , there exists a labeling of the triplets, such that no embedding on the real line (no ) satisfies more than a fraction of of them. Consider that labeling for the triplets. By our assumption that the set is shattered there exists an embedding (potentially in dimensions) such that all the triplets (with margin) are satisfied. Applying our rounding algorithm on that embedding we get that there exists an embedding on the real line satisfying a fraction of of them (without margin). This leads to a contradiction that:
yet we can choose to be sufficiently small compared to . The above are made formal in our proof of Theorem 3.1 in Section 3.
3 Improved VC-dimension: Upper bound of Theorem 1.4
In this section, we prove the following theorem.
Theorem 3.1 (Upper bound for ).
The VC-dimension of is linear in and independent of the dimensionality . In particular, there exists an absolute constant such that:
Note that the VC dimension is monotonically decreasing in , thus it suffices to show that for it is bounded by . From now on we assume that . Our proof uses the following lemma which, roughly speaking, states that if a set of contrastive learning constraints with margin , are satisfiable (potentially in dimensions) then there exists an embedding on the real line satisfying a fraction of the contrastive constraints . Note here that the constraints that satisfies are without margin.
Lemma 3.2 (Rounding to 1D).
Let be such that the constraints are satisfied by . Then there exists a such that at least constraints of are satisfied by .
Proof.
Let be a standard Gaussian vector. We will consider the random embedding given by and show that on expectation, the embedding satisfies a fraction of of constraints in . Note that by virtue of the fact that for every with , we get that, the with probability one, . The above combined imply that there exists a such that the embedding given by satisfies a fraction of at least of constraints and furthermore .
For let . Observe that the embedding satisfies a constraint if:
By linearity of expectation, the expected number of constraints that satisfies is
where the probability is over the randomness in . It therefore suffices to show that for every :
where for vectors and it holds that To that end, we prove the following claim.
Claim 3.3.
Let and let be a standard Gaussian vector. If for some , then
In particular, for :
Claim 3.3, which we prove in Appendix A, gives us the result.77 7 Observe this claim is for two vectors as long as they have a gap , so it also allows us to capture the case of quadruplet comparisons (Bilu and Linial, 2005; Vankadara et al., 2023), where we compare the distance between to the distance between . ∎
In the next lemma we use the upper bound on the VC dimension of contrastive learning on the real line, proven in Alon et al. (2024), to prove that for every set of unlabeled triplets , there exists a labeling of them such that no embedding is consistent with more than a fraction of of them.
Lemma 3.4.
There exists an absolute constant such that for every , the following holds. For every and set there exists a labeling such that no embedding satisfies more than a fraction of of the geometric triplet constraints induced by the labeling. In particular, for every it holds that:
Proof.
We will use the probabilistic method. In particular, we will pick the label randomly and show that
| (1) |
using bounds for the worst case empirical Rademacher complexity of a hypothesis class in terms of the VC-dimension, and then the result directly follows. In particular, we let with probability and with the remaining probability, independently of everything else. We can equivalently write Equation 1 as:
| (2) |
and observe that the left hand side exactly corresponds to the empirical Rademacher complexity of hypothesis class on points . We now use (see e.g. Bousquet et al. (2003)) that there exists an absolute constant such that the empirical Rademacher complexity of a hypothesis class on points can be upper bounded in terms of the VC dimension of the class. In particular, if is the worst-case88 8 Supremum over sets of size . empirical Rademacher complexity on points then
| (3) |
We apply this bound to the left hand side of Equation 2 and use that to get that for being a sufficiently large constant:
which gives us the result. ∎
We can now prove our main Theorem 3.1.
Proof of Theorem 3.1.
Let and let be a large enough constant. We will show that no set of size can be shattered, which gives the result. Consider a set of triplets and assume, for the sake of contradiction, that the set is shattered by , meaning that for every labeling of the triplets, there is an embedding that is consistent with all the corresponding triplet constraints.
Formally, by Lemma 3.4, taking bigger than the constant in the lemma we get that there exists a labeling such that for every :
| (4) |
On the other hand, by our assumption that the set is shattered, we get that there exists an embedding satisfying all the corresponding constraints: if then , and if then . Without loss of generality and for notational convenience, we can assume that the labeled triplets are ; by Lemma 3.2, there exists a one dimensional embedding such that a fraction of at least constraints in are satisfied.99 9 These are constraints without margin. For the function this implies that:
| (5) |
Combining Equations 4 and 5 we get that:
which is a contradiction since we have taken ∎
4 A Matching Lower Bound
In this section we prove a matching lower bound for the VC dimension of contrastive learning with margin parameter . In particular we show that as long as then .
Theorem 4.1.
Suppose that . Then, there exists an absolute constant such that:
Proof.
We divide into two cases. We first consider the case where , in which case we show that the VC dimension is . We make a distinction between the elements in . We use to denote the first two elements and for the rest. We consider the set of triplets given by and show that they are shattered. For a labeling of the triplets, let be the such that is labeled as and . We define the embedding to be , , furthermore for we let where and for , where . Consider and the triplet , we have that , and the triplet is satisfied. On the other hand for , we have that and the triplet is satisfied. In the above construction there exist with such that . A small perturbation of all points resolves this issue while maintaining the conclusion.
In the remaining case, we consider . We proceed to describe an instance of triplets that is shattered. Let for convenience . We first make a distinction between the elements in . We will use to denote the first elements of and with for the remaining elements. The set of triplets that we propose is inspired by the construction of Alon et al. (2022) for the lower bound on the VC dimension of linear classifiers with margin.
We consider the set of triplets and show that the set is shattered. Note that the number of triplets is (here, we have used that ), thus showing that they can be shattered gives us the result. For every labeling of the triplets, the embedding for points will be the same. In particular, we will always map to the -th standard basis vector (here we have used that ). Now consider a labeling of the triplets and observe that we can decompose the triplets as , where having fixed the mappings of , the instances are decoupled for different . It therefore suffices to show that for every labeling of triplets there is an embedding of points and that satisfies all the triplets.
Consider a labeling of the triplets and let be the subset of in such that the triplet is labeled as and . Let , is exactly the vector that defines the hyperplane separating the points from the points with margin , see Proposition 17 in Alon et al. (2022). We let . We also select to be a point at distance from . We now consider , we have that
This in turn means that:
where we have used that the function is convex and . We therefore get that is satisfied by the embedding.
On the other hand, for , we have that
meaning that the triplet is satisfied. In the above construction there exist with such that . A small perturbation of all points resolves this issue while maintaining the conclusion.
∎
5 Experiments
To complement our theoretical bounds, we empirically explore how the generalization error is affected as we vary the dimension , the number of points , the margin and the number of given triplet samples. We test both on synthetic data generated from a Gaussian distribution and on real datasets (CIFAR-100). Our goal is to test the dimension-independence of our bound.
Experimental Setting.
For each configuration , we sample training triplets from uniformly at random, reject any that fail the -margin condition under a ground-truth metric , and fit an embedding by minimizing the multiplicative-margin triplet loss
which is the natural surrogate for the -separation defining (see Schroff et al. (2015) and survey Vankadara et al. (2023)). We optimize with Adam, with learning rate and steps, and report the empirical generalization error on held-out -separated test triplets.
We perform experiments for two types of ground-truth embeddings. In the synthetic setting, is the undelying embedding of points drawn i.i.d. from and the learner directly parameterizes the embedding rows in . In the real-data setting, is the L2-normalized penultimate feature (this provides a vector in ) of an ImageNet-pretrained ResNet18 (He et al., 2016) on CIFAR-100 test images (Krizhevsky, 2009), frozen during training, and the learner is a linear head on top of these features.
Dimension-independence.
As Theorem 3.1 does not depend on the embedding dimension , for fixed , the empirical error should not change as we increase . To test this we fix and vary . On the synthetic side we keep the ground-truth ambient dimension at so that the data distribution itself is unchanged, and only the learner’s capacity changes. We sweep and on the synthetic setup, and and on the real-data setup, over 5 random seeds. Figure 1 agrees with the theoretical predictions on both setups, as it shows the three curves corresponding to different dimensions (encoded by different colors) lie on top of each other within each -trajectory. Interestingly, the plots show that on real-data (Fig. 1 (b)), dimension-independence is quite prominent, since as varies, the error changes only slightly (notice the small values of on the -axis). Appendix B provides further experiments.
Conclusion
We resolved an open question from Alon et al. (2024) related to provable generalization guarantees and the VC-dimension of contrastive learning, in the presence of a margin parameter separating the distance between an anchor-positive pair from an anchor-negative pair. Enforcing a margin is not only a practically well-motivated approach in the literature of contrastive learning and ordinal embeddings, but as we show it also leads to interesting theoretical insights. Our main result improves upon the direct application of standard low-distortion metric embedding techniques, such as the Johnson-Lindenstrauss lemma, and provides an optimal bound for the VC-dimension for learning a ground-truth embedding on data points of interest (with the lower bound holding under the assumption that ). Surprisingly, this is independent of the underlying dimensionality of the ground-truth embedding, which is often large. Given that our bound is optimal in , our work makes steps towards understanding the empirical success of contrastive learning. Technically, our approach uses ideas from approximation algorithms and geometric projections, coupled with learning theory bounds for learning triplet comparisons.
AI Disclosure
Generative AI tools were used for polishing and for feedback on exposition as well as literature search. In particular, the free version of ChatGPT helped the authors find a reference for the stronger bound on Rademacher complexity in terms of VC-dimension. The main result of the paper was obtained by the authors in April 2026. All the proofs and technical ideas come from the authors. Generative AI tools were used to assist with the experiments.
References
- OPTIMAL sample complexity of contrastive learning. In 12th International Conference on Learning Representations, ICLR 2024, Cited by: §1.1, §1.1, §1.1, §1.2, §1.2, §1.2, §1.2, §1.3, Problem 1.2, §2.1, §2.1, §2.1, §2.2, §3, Conclusion, Abstract.
- Ordinal embeddings of minimum relaxation: general properties, trees, and ultrametrics. ACM Transactions on Algorithms (TALG) 4 (4), pp. 1–21. Cited by: §1.1, §1.3.
- Geometrical realization of set systems and probabilistic communication complexity. In 26th Annual Symposium on Foundations of Computer Science (sfcs 1985), pp. 277–280. Cited by: §2.1.
- A theory of pac learnability of partial concept classes. In 2021 IEEE 62nd Annual Symposium on Foundations of Computer Science (FOCS), pp. 658–671. Cited by: §1.2, §2.2, §4, §4.
- Provable accuracy collapse in embedding-based representations under dimensionality mismatch. 43rd International Conference on Machine Learning (ICML). Cited by: §1.3.
- Embedding dimension of contrastive learning and -nearest neighbors. Advances in Neural Information Processing Systems 37, pp. 41359–41393. Cited by: §1.3, §1.3.
- Tree learning: optimal sample complexity and algorithms. In Proceedings of the AAAI Conference on Artificial Intelligence, Vol. 37, pp. 6701–6708. Cited by: §1.3.
- Do more negative samples necessarily hurt in contrastive learning?. In International conference on machine learning, pp. 1101–1116. Cited by: §1.1, §1.3.
- A pac-style model for learning from labeled and unlabeled data. In International Conference on Computational Learning Theory, pp. 111–126. Cited by: §1.2.
- Monotone maps, sphericity and bounded second eigenvalue. Journal of Combinatorial Theory, Series B 95 (2), pp. 283–299. Cited by: §1.1, §1.3, §1.3, footnote 2, footnote 7.
- Random projection, margins, kernels, and feature-selection. In International Statistical and Optimization Perspectives Workshop” Subspace, Latent Structure and Feature Selection”, pp. 52–68. Cited by: §1.2.
- Introduction to statistical learning theory. In Summer school on machine learning, pp. 169–207. Cited by: §2.2, §3.
- The landscape of non-convex quadratic feasibility. In 2018 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP), pp. 3974–3978. Cited by: §1.3.
- Dimension-accuracy tradeoffs in contrastive embeddings for triplets, terminals & top-k nearest neighbors. In 2024 Symposium on Simplicity in Algorithms (SOSA), pp. 230–243. Cited by: §1.3.
- A simple framework for contrastive learning of visual representations. In International conference on machine learning, pp. 1597–1607. Cited by: §1.3, §1.
- Gemini 2.5: pushing the frontier with advanced reasoning, multimodality, long context, and next generation agentic capabilities. arXiv preprint arXiv:2507.06261. Cited by: §1.1.
- An elementary proof of a theorem of johnson and lindenstrauss. Random Structures & Algorithms 22 (1), pp. 60–65. Cited by: §1.2.
- Continuous local search. In Proceedings of the twenty-second annual ACM-SIAM symposium on Discrete Algorithms, pp. 790–804. Cited by: footnote 5.
- Adaptive hierarchical clustering using ordinal queries. In Proceedings of the Twenty-Ninth Annual ACM-SIAM Symposium on Discrete Algorithms, pp. 415–429. Cited by: §1.3.
- Learning lines with ordinal constraints. arXiv preprint arXiv:2004.13202. Cited by: §1.3.
- Landmark ordinal embedding. Advances in neural information processing systems 32. Cited by: §1.3.
- Foundations of comparison-based hierarchical clustering. Advances in neural information processing systems 32. Cited by: §1.3.
- Improved approximation algorithms for maximum cut and satisfiability problems using semidefinite programming. Journal of the ACM (JACM) 42 (6), pp. 1115–1145. Cited by: §2.2.
- Node2vec: scalable feature learning for networks. In Proceedings of the 22nd ACM SIGKDD international conference on Knowledge discovery and data mining, pp. 855–864. Cited by: §1.
- Beating the random ordering is hard: inapproximability of maximum acyclic subgraph. In 2008 49th Annual IEEE Symposium on Foundations of Computer Science, pp. 573–582. Cited by: §1.3.
- Provable guarantees for self-supervised deep learning with spectral contrastive loss. Advances in neural information processing systems 34, pp. 5000–5011. Cited by: §1.3.
- Beating a random assignment. In Approximation, Randomization and Combinatorial Optimization. Algorithms and Techniques, pp. 134–145. Cited by: §1.3.
- Deep residual learning for image recognition. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 770–778. Cited by: §5.
- Some optimal inapproximability results. Journal of the ACM (JACM) 48 (4), pp. 798–859. Cited by: §1.3.
- How easy is local search?. Journal of computer and system sciences 37 (1), pp. 79–100. Cited by: footnote 5.
- On the power of unique 2-prover 1-round games. In Proceedings of the thiry-fourth annual ACM symposium on Theory of computing, pp. 767–775. Cited by: §1.3.
- Learning multiple layers of features from tiny images. Technical report University of Toronto. Cited by: §5.
- Metric learning: a survey. Foundations and Trends® in Machine Learning 5 (4), pp. 287–364. Cited by: §1.3.
- Matryoshka representation learning. Advances in Neural Information Processing Systems 35, pp. 30233–30249. Cited by: §1.1.
- Generalization analysis for contrastive representation learning. In International Conference on Machine Learning, pp. 19200–19227. Cited by: §1.3.
- Representation learning with contrastive predictive coding. arXiv preprint arXiv:1807.03748. Cited by: §1.3, §1.
- Improving language understanding by generative pre-training. Technical report OpenAI. Cited by: §1.1.
- Contrastive learning with hard negative samples. arXiv preprint arXiv:2010.04592. Cited by: §1.1, §1.3.
- Understanding contrastive learning requires incorporating inductive biases. In International Conference on Machine Learning, pp. 19250–19286. Cited by: §1.3.
- A theoretical analysis of contrastive unsupervised representation learning. In International conference on machine learning, pp. 5628–5637. Cited by: §1.1, §1.3, §1.
- Facenet: a unified embedding for face recognition and clustering. In Proceedings of the IEEE conference on computer vision and pattern recognition, pp. 815–823. Cited by: §1.3, §1, §5.
- Learning a distance metric from relative comparisons. Advances in neural information processing systems 16. Cited by: §1.3.
- Understanding machine learning: from theory to algorithms. Cambridge university press. Cited by: §2.2, §2.2.
- Adaptively learning the crowd kernel. 28th International Conference on Machine Learning (ICML). Cited by: §1.3.
- Local ordinal embedding. In International Conference on Machine Learning, pp. 847–855. Cited by: §1.1, §1.3.
- Insights into ordinal embedding algorithms: a systematic evaluation. Journal of Machine Learning Research 24 (191), pp. 1–83. Cited by: §1.1, §1.3, §1.3, Definition 1.1, §5, footnote 7.
- Lower bounds for approximation by nonlinear manifolds. Transactions of the American Mathematical Society 133 (1), pp. 167–178. Cited by: §2.1.
- The complexity of finding local optima in contrastive learning. Advances in Neural Information Processing Systems 38, pp. 52758–52785. Cited by: §1.3.
- Generalization bounds for adversarial contrastive learning. Journal of Machine Learning Research 24 (114), pp. 1–54. Cited by: §1.3.
Appendix A Reduction to 1D
In this section we prove Claim 3.3.
Proof of Claim 3.3.
If , the claim is immediate. Assume , which also implies . Let and . Define . Then the inequality holds if and only if
Since , it suffices to show
If , then the event holds with probability , so we may assume that and are not collinear. Let be the two-dimensional subspace spanned by and . We decompose as
where is the orthogonal projection of onto . Since both and lie in , we have
Let be the angle between and , measured counterclockwise, and let be the angle from to , also measured counterclockwise. To visualize the configuration, align the first basis vector of with . Then has coordinates , has coordinates , and has coordinates . See Figure 2. We exclude the events and , which occur with probability . Then is uniformly distributed on
We have
Therefore,
Define
Since , this is equivalent to
Using , we get
Since , we have , and hence
Therefore, consists of two intervals and , where
The probability of equals
Denote the expression in the square brackets on the right hand side by (see Figure 2):
Then the probability above is . The derivative of equals
Write it as
Function is increasing for because
and . Observe that and . Hence when and when . Therefore, is minimized at . Consequently,
Thus
This proves the first part of the claim. We now use that the function is concave for meaning that in any interval, it can be lower bounded by the secant line between the endpoints of the interval. In particular, we get that for :
where . ∎
Appendix B Additional Experiments
In this section we provide the additional experiments referenced from Section 5. All experiments run on a standard CPU and can be completed within an hour.
B.1 Synthetic -sweep
In Section 5, we fixed and varied . Here we do the opposite: on the synthetic setup, we fix to match the ground-truth ambient dimension, and sweep , , over 5 seeds. In Figure 3, we plot the empirical error against the effective sample size predicted by Theorem 3.1. All nine curves collapse onto a single trajectory and drop from random-guess error to near zero once . If we plot against instead, the curves separate by margin, so the factor in our obtained bound is quite precise.
B.2 Real data -sweep
On the real-data setup, we fix , and sweep , , over 5 seeds. Figure 4 reproduces both diagnostics: plotting against orders the curves and they decay together to zero error, while removing separates them by . Compared to the synthetic data, two things look different: the empirical errors are well below their synthetic counterparts at the same , and at fixed larger gives lower rather than higher error. Both behaviors are what we would expect when the linear head explores a more structured subspace of , rather than randomly generated data (it has only parameters, independent of ). A smaller class generalizes better than our worst-case bound predicts, and at fixed , a larger value of means more triplets constraining the same fixed-size parameter matrix.
B.3 Dimension-independence across
The dimension-independence experiment in Section 5 uses a single representative margin . We repeat this experiment at on the synthetic and real-data setups (Figure 5). The three -curves overlap within each -trajectory across the full range in both cases. The one exception is mild underfitting at when is small and is large: 16 dimensions cannot faithfully embed the ground truth ( synthetic, up to 512 on CIFAR-100), and tight margins are more sensitive to the resulting distortion.
B.4 Margin sanity check
The hypothesis class is defined by embeddings whose output itself satisfies the -separation; the multiplicative-margin loss is a continuous surrogate for this constraint. As a post-hoc check that the learned actually lives in the hypothesis class, we measure the fraction of held-out triplets on which the learned embedding satisfies (Figure 6). The fraction climbs from around at the smallest to above once . So whenever the empirical error is small, the learned embedding really is -separated on most test triplets.