Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Theorem B.1: guarantee with k negative samples

Open
ContrastiveUnsupervised.k_negative_samples_guarantee

by Xeroth · Nov 23, 2026 · Mathlib 0df444a (Lean v4.33.1)

contrastive-learninggeneralization-boundslatent-classesrademacher-complexityrepresentation-learning

Let C\mathcal CC be a countable set of latent classes with distribution ρ\rhoρ and class distributions Dc\mathcal D_cDc​. Let k≥1k\ge1k≥1 be the number of negative samples, with τk=P[I+≠∅]<1\tau_k=P[I^+\ne\emptyset]<1τk​=P[I+=∅]<1. Let every task T\mathcal TT have a label distribution DT\mathcal D_{\mathcal T}DT​. Let ℓ\ellℓ be the hinge or logistic loss, and let F\mathcal FF be a pointwise separable class of measurable fff with ∥f(⋅)∥≤R\|f(\cdot)\|\le R∥f(⋅)∥≤R, R>0R>0R>0. Let f^(S)∈argmin⁡f∈FL^un(f)\widehat f(\mathcal S)\in\operatorname{argmin}_{f\in\mathcal F}\widehat L_{un}(f)f​(S)∈argminf∈F​Lun​(f) for training sets of M≥1M\ge1M≥1 tuples (x,x+,x1−,…,xk−)(x,x^+,x_1^-,\dots,x_k^-)(x,x+,x1−​,…,xk−​) drawn from (Dsim×Dnegk)M(\mathcal D_{sim}\times\mathcal D_{neg}^k)^M(Dsim​×Dnegk​)M. There are absolute constants KKK and c′>0c'>0c′>0 such that, for every 0<δ≤1/20<\delta\le1/20<δ≤1/2, with probability at least 1−δ1-\delta1−δ, for all f∈Ff\in\mathcal Ff∈F,

ET∼D[ρmin+(T)pmax(T)Lsupμ(T,f^)]≤1−τ′1−τkLun≠(f)+c′kτ11−τks(f)+11−τkGenM,\mathbb E_{\mathcal T\sim\mathcal D}\Big[\frac{\rho^+_{min}(\mathcal T)}{p_{max}(\mathcal T)}L^\mu_{sup}(\mathcal T,\widehat f)\Big]\le\frac{1-\tau'}{1-\tau_k}L^{\ne}_{un}(f)+c'k\frac{\tau_1}{1-\tau_k}s(f)+\frac{1}{1-\tau_k}Gen_M,ET∼D​[pmax​(T)ρmin+​(T)​Lsupμ​(T,f​)]≤1−τk​1−τ′​Lun=​(f)+c′k1−τk​τ1​​s(f)+1−τk​1​GenM​,

with GenM=K(Rk RS(F)/M+(R2+log⁡k)log⁡(1/δ)/M)Gen_M=K\big(R\sqrt k\,\mathcal R_{\mathcal S}(\mathcal F)/M+(R^2+\log k)\sqrt{\log(1/\delta)/M}\big)GenM​=K(Rk​RS​(F)/M+(R2+logk)log(1/δ)/M​), τ1=∑cρ(c)2\tau_1=\sum_c\rho(c)^2τ1​=∑c​ρ(c)2, τ′=P[ci−=c+ ∀i]\tau'=P[c_i^-=c^+\ \forall i]τ′=P[ci−​=c+ ∀i], and D\mathcal DD the law of the set of distinct classes of (c+,c1−,…,ck−)∼ρk+1(c^+,c_1^-,\dots,c_k^-)\sim\rho^{k+1}(c+,c1−​,…,ck−​)∼ρk+1 conditioned on c+∉{ci−}c^+\notin\{c_i^-\}c+∈/{ci−​}.

This is the formal version of Theorem 6.1. For k=1k=1k=1 and uniform DT\mathcal D_{\mathcal T}DT​ it gives the second inequality of Theorem 4.5 (then ρmin+/pmax=1\rho^+_{min}/p_{max}=1ρmin+​/pmax​=1 and τ′=τk=τ\tau'=\tau_k=\tauτ′=τk​=τ); it does not give the first inequality Lsup≤LsupμL_{sup}\le L^\mu_{sup}Lsup​≤Lsupμ​, and for non-uniform DT\mathcal D_{\mathcal T}DT​ it bounds a different, weighted quantity.

Formalization Note The paper's O(⋅)O(\cdot)O(⋅) is an absolute constant KKK, and "with probability at least 1−δ1-\delta1−δ" means that the outer measure of the failure set is at most δ\deltaδ. The statement is restricted to δ≤1/2\delta\le1/2δ≤1/2 because the proof (Mohri et al., Theorem 3.1, and Hoeffding) produces log⁡(4/δ)\log(4/\delta)log(4/δ) and log⁡(2/δ)\log(2/\delta)log(2/δ). These are O(log⁡(1/δ))O(\log(1/\delta))O(log(1/δ)) only for δ\deltaδ bounded away from 111; for δ≤1/2\delta\le1/2δ≤1/2 the two forms agree up to the constant. Pointwise separability of F\mathcal FF and measurability of each fff are standing conventions the paper does not state. The hypothesis τk<1\tau_k<1τk​<1 is implicit in the paper's division by 1−τk1-\tau_k1−τk​. Losses of an empty vector are 000, the convention the proof uses for Lun≠L^{\ne}_{un}Lun=​ when ∣I+∣=k|I^+|=k∣I+∣=k.

Preamble
import Mathlib
import Definitions.Def_ContrastiveUnsupervised_Basic

open MeasureTheory Filter Topology

universe u v
Formal statement
namespace ContrastiveUnsupervised

theorem k_negative_samples_guarantee :
    ∃ K c' : ℝ, 0 < c' ∧
      ∀ {X : Type u} [MeasurableSpace X] {C : Type v} [Countable C] {d : ℕ}
      (D : C → Measure X) (ρ : C → ℝ), IsLatentClassModel D ρ →
      ∀ (k : ℕ), 1 ≤ k → tauK ρ k < 1 →
      ∀ (pT : Finset C → C → ℝ), IsTaskDistFamily pT →
      ∀ (hinge : Bool) (R : ℝ), 0 < R →
      ∀ (F : Set (X → Rep d)), (∀ f ∈ F, IsBoundedRep f R) → IsPointwiseSeparable F →
      ∀ (M : ℕ), 1 ≤ M →
      ∀ (fhat : (Fin M → X × X × (Fin k → X)) → X → Rep d),
        (∀ S, fhat S ∈ F ∧ ∀ f ∈ F, empUnsupLoss hinge k (fhat S) S ≤ empUnsupLoss hinge k f S) →
      ∀ δ : ℝ, 0 < δ → δ ≤ 1 / 2 →
        sampleMeasure D ρ k M {S | ¬ ∀ f ∈ F,
            weightedTaskMeanSupLoss (stdLoss hinge) D ρ k pT (fhat S) ≤
              (1 - tauAll ρ k) / (1 - tauK ρ k) * unsupLossNeq hinge D ρ k f +
                c' * k * (collisionProb ρ / (1 - tauK ρ k)) * intraclassDeviation D ρ f +
                1 / (1 - tauK ρ k) * genError K R k M (rademacherAvg F S) δ} ≤
          ENNReal.ofReal δ := by sorry

end ContrastiveUnsupervised
Source
Arora, Khandeparkar, Khodak, Plevrakis and Saunshi, A Theoretical Analysis of Contrastive Unsupervised Representation Learning, arXiv:1902.09229v1 (2019), Appendix B.1, Theorem B.1, p. 14, proof pp. 14-16 (formal version of Section 6.1, Theorem 6.1)
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

There exist two real constants KKK and c′c'c′, with c′>0c' > 0c′>0 and no sign condition on KKK, such that the following holds. Both constants are fixed once, before any of the data below is chosen, so they cannot depend on any of it.

Setting. Let XXX be any measurable space and CCC any countable set of "classes". Let d≥0d \ge 0d≥0 be a natural number; d=0d = 0d=0 is allowed, in which case R0\mathbb{R}^0R0 is a single point. Representations take values in Rd\mathbb{R}^dRd with the Euclidean norm ∥⋅∥\|\cdot\|∥⋅∥ and inner product ⟨⋅,⋅⟩\langle\cdot,\cdot\rangle⟨⋅,⋅⟩.

Let (Dc)c∈C(D_c)_{c \in C}(Dc​)c∈C​ be probability measures on XXX. Let ρ:C→R\rho : C \to \mathbb{R}ρ:C→R satisfy ρ(c)≥0\rho(c) \ge 0ρ(c)≥0 for all ccc and ∑cρ(c)=1\sum_{c} \rho(c) = 1∑c​ρ(c)=1 (as an unconditionally convergent sum).

Let k≥1k \ge 1k≥1 be an integer. Draw classes c+,c1−,…,ck−c^+, c^-_1, \dots, c^-_kc+,c1−​,…,ck−​ i.i.d. from ρ\rhoρ, and define:

  • the collision set I+={i:ci−=c+}I^+ = \{ i : c^-_i = c^+ \}I+={i:ci−​=c+};
  • the set of distinct classes Q={c+,c1−,…,ck−}Q = \{c^+, c^-_1, \dots, c^-_k\}Q={c+,c1−​,…,ck−​};
  • τk=Pr⁡[I+≠∅]\tau_k = \Pr[I^+ \ne \emptyset]τk​=Pr[I+=∅], the probability that some negative class equals c+c^+c+;
  • τ′=Pr⁡[ci−=c+ for all i]\tau' = \Pr[c^-_i = c^+ \text{ for all } i]τ′=Pr[ci−​=c+ for all i];
  • τ=∑cρ(c)2\tau = \sum_c \rho(c)^2τ=∑c​ρ(c)2, the collision probability.

It is assumed that τk<1\tau_k < 1τk​<1.

Let (pT)(p_T)(pT​) assign to each finite set T⊆CT \subseteq CT⊆C a function pT:C→Rp_T : C \to \mathbb{R}pT​:C→R. For every nonempty TTT, it must satisfy pT(c)≥0p_T(c) \ge 0pT​(c)≥0 for all c∈Cc \in Cc∈C and ∑c∈TpT(c)=1\sum_{c \in T} p_T(c) = 1∑c∈T​pT​(c)=1. Nothing is required for T=∅T = \emptysetT=∅, and values of pTp_TpT​ outside TTT are otherwise unconstrained.

The loss. A Boolean flag selects the loss ℓ\ellℓ, applied to a finitely-indexed family (vi)i∈s(v_i)_{i \in s}(vi​)i∈s​:

  • either the hinge loss ℓ(v)=max⁡{0, 1+max⁡i∈s(−vi)}\ell(v) = \max\{0,\, 1 + \max_{i \in s}(-v_i)\}ℓ(v)=max{0,1+maxi∈s​(−vi​)}, set to 000 when s=∅s = \emptysets=∅;
  • or the logistic loss ℓ(v)=log⁡2 ⁣(1+∑i∈se−vi)\ell(v) = \log_2\!\big(1 + \sum_{i\in s} e^{-v_i}\big)ℓ(v)=log2​(1+∑i∈s​e−vi​), which also equals 000 when s=∅s = \emptysets=∅.

The same choice of ℓ\ellℓ is used in every quantity below.

Function class. Let R>0R > 0R>0. Let FFF be a set of maps f:X→Rdf : X \to \mathbb{R}^df:X→Rd such that:

  • each f∈Ff \in Ff∈F is measurable and satisfies ∥f(x)∥≤R\|f(x)\| \le R∥f(x)∥≤R for all xxx;
  • FFF is pointwise separable: there is a countable F0⊆FF_0 \subseteq FF0​⊆F such that every f∈Ff \in Ff∈F is the pointwise limit of some sequence in F0F_0F0​.

Samples. Let M≥1M \ge 1M≥1. A training sample is S=(zj)j=1MS = (z_j)_{j=1}^MS=(zj​)j=1M​ with zj=(xj,xj+,xj1−,…,xjk−)∈Xk+2z_j = (x_j, x_j^+, x^-_{j1}, \dots, x^-_{jk}) \in X^{k+2}zj​=(xj​,xj+​,xj1−​,…,xjk−​)∈Xk+2. Its law PS\mathbb{P}_SPS​ is the MMM-fold product of the following single-tuple law:

  • (x,x+)(x, x^+)(x,x+) is drawn from Dsim=∑cρ(c) Dc⊗DcD_{\mathrm{sim}} = \sum_c \rho(c)\, D_c \otimes D_cDsim​=∑c​ρ(c)Dc​⊗Dc​;
  • independently of that pair, x1−,…,xk−x^-_1, \dots, x^-_kx1−​,…,xk−​ are i.i.d. from Dneg=∑cρ(c) DcD_{\mathrm{neg}} = \sum_c \rho(c)\, D_cDneg​=∑c​ρ(c)Dc​.

The empirical contrastive loss of fff on SSS is

L^un(f;S)=1M∑j=1Mℓ({⟨f(xj), f(xj+)−f(xji−)⟩}i=1k).\widehat L_{\mathrm{un}}(f; S) = \frac1M \sum_{j=1}^M \ell\Big(\big\{\langle f(x_j),\, f(x_j^+) - f(x^-_{ji})\rangle\big\}_{i=1}^k\Big).Lun​(f;S)=M1​j=1∑M​ℓ({⟨f(xj​),f(xj+​)−f(xji−​)⟩}i=1k​).

The learner. Let f^\hat ff^​ be any map (no measurability is required) sending each sample SSS to f^S\hat f_Sf^​S​. For every sample SSS, it must satisfy f^S∈F\hat f_S \in Ff^​S​∈F and L^un(f^S;S)≤L^un(f;S)\widehat L_{\mathrm{un}}(\hat f_S; S) \le \widehat L_{\mathrm{un}}(f; S)Lun​(f^​S​;S)≤Lun​(f;S) for all f∈Ff \in Ff∈F. In other words, f^S\hat f_Sf^​S​ is an exact empirical minimizer over FFF at every sample. If no exact minimizer exists for some SSS, the hypothesis cannot be met and the statement is vacuous for that FFF.

Conclusion. For every δ\deltaδ with 0<δ≤120 < \delta \le \tfrac120<δ≤21​, consider the set of samples SSS for which it is not the case that, for all f∈Ff \in Ff∈F simultaneously,

LD(f^S)  ≤  1−τ′1−τk Lun≠(f)  +  c′ k τ1−τk s(f)  +  11−τk Gen(S).L_{\mathcal D}(\hat f_S) \;\le\; \frac{1-\tau'}{1-\tau_k}\, L^{\ne}_{\mathrm{un}}(f) \;+\; c'\,k\,\frac{\tau}{1-\tau_k}\, s(f) \;+\; \frac{1}{1-\tau_k}\, \mathrm{Gen}(S).LD​(f^​S​)≤1−τk​1−τ′​Lun=​(f)+c′k1−τk​τ​s(f)+1−τk​1​Gen(S).

This set has PS\mathbb{P}_SPS​-measure at most δ\deltaδ. The measure is applied to the set as written, so if the set is not measurable this means its outer measure.

The quantities in the inequality. Write μc=Ex∼Dc[f(x)]\mu_c = \mathbb{E}_{x\sim D_c}[f(x)]μc​=Ex∼Dc​​[f(x)] for the class mean of fff.

  • Left-hand side. It is a weighted average of mean-classifier losses over the tasks QQQ, conditioned on I+=∅I^+ = \emptysetI+=∅:
LD(g)=E[1I+=∅  ρmin⁡+(Q)pmax⁡(Q)  Lsupμ(Q,g)]Pr⁡[I+=∅].L_{\mathcal D}(g) = \frac{\mathbb{E}\Big[\mathbf 1_{I^+=\emptyset}\; \dfrac{\rho^+_{\min}(Q)}{p_{\max}(Q)}\; L^\mu_{\mathrm{sup}}(Q, g)\Big]}{\Pr[I^+=\emptyset]}.LD​(g)=Pr[I+=∅]E[1I+=∅​pmax​(Q)ρmin+​(Q)​Lsupμ​(Q,g)]​.

Its ingredients are:

  • ρmin⁡+(T)=min⁡c∈TPr⁡[c+=c, Q=T, I+=∅] / Pr⁡[Q=T, I+=∅]\rho^+_{\min}(T) = \min_{c \in T} \Pr[c^+ = c,\, Q = T,\, I^+ = \emptyset] \,/\, \Pr[Q = T,\, I^+ = \emptyset]ρmin+​(T)=minc∈T​Pr[c+=c,Q=T,I+=∅]/Pr[Q=T,I+=∅];
  • pmax⁡(T)=max⁡c∈TpT(c)p_{\max}(T) = \max_{c\in T} p_T(c)pmax​(T)=maxc∈T​pT​(c);
  • the mean-classifier supervised loss
Lsupμ(T,g)=∑c∈TpT(c) Ex∼Dc ℓ({⟨μc,g(x)⟩−⟨μc′′,g(x)⟩}c′′∈T∖{c}),L^\mu_{\mathrm{sup}}(T, g) = \sum_{c\in T} p_T(c)\, \mathbb{E}_{x \sim D_c}\, \ell\Big(\big\{\langle \mu_c, g(x)\rangle - \langle \mu_{c''}, g(x)\rangle\big\}_{c'' \in T\setminus\{c\}}\Big),Lsupμ​(T,g)=c∈T∑​pT​(c)Ex∼Dc​​ℓ({⟨μc​,g(x)⟩−⟨μc′′​,g(x)⟩}c′′∈T∖{c}​),

with the means μ\muμ computed from ggg.

  • First right-hand term. It uses
Lun≠(f)=E[1∣I+∣<k  Λf(c+,c−)]Pr⁡[∣I+∣<k].L^{\ne}_{\mathrm{un}}(f) = \frac{\mathbb{E}\big[\mathbf 1_{|I^+|<k}\; \Lambda_f(c^+, c^-)\big]}{\Pr[|I^+| < k]}.Lun=​(f)=Pr[∣I+∣<k]E[1∣I+∣<k​Λf​(c+,c−)]​.

Here Λf(c+,c−)\Lambda_f(c^+, c^-)Λf​(c+,c−) is the expectation of ℓ({⟨f(x),f(x+)−f(xi−)⟩}i∉I+)\ell\big(\{\langle f(x), f(x^+) - f(x^-_i)\rangle\}_{i \notin I^+}\big)ℓ({⟨f(x),f(x+)−f(xi−​)⟩}i∈/I+​), under x,x+∼Dc+x, x^+ \sim D_{c^+}x,x+∼Dc+​ and xi−∼Dci−x^-_i \sim D_{c^-_i}xi−​∼Dci−​​, all independent. Negatives that collide with c+c^+c+ are dropped.

  • Second right-hand term. It uses the intraclass deviation
s(f)=1τ∑cρ(c)2∥Σ(f,c)∥2  Ex∼Dc∥f(x)∥.s(f) = \frac{1}{\tau}\sum_c \rho(c)^2 \sqrt{\|\Sigma(f,c)\|_2}\; \mathbb{E}_{x\sim D_c}\|f(x)\|.s(f)=τ1​c∑​ρ(c)2∥Σ(f,c)∥2​​Ex∼Dc​​∥f(x)∥.

Here Σ(f,c)\Sigma(f,c)Σ(f,c) is the covariance matrix of f(x)f(x)f(x) for x∼Dcx \sim D_cx∼Dc​, and ∥⋅∥2\|\cdot\|_2∥⋅∥2​ is the spectral norm.

  • Third right-hand term. It is
Gen(S)=K(Rk RS(F)M+(R2+log⁡k)log⁡(1/δ)M),\mathrm{Gen}(S) = K\Big(\frac{R\sqrt{k}\, \mathcal R_S(F)}{M} + (R^2 + \log k)\sqrt{\frac{\log(1/\delta)}{M}}\Big),Gen(S)=K(MRk​RS​(F)​+(R2+logk)Mlog(1/δ)​​),

with natural logarithms. The quantity RS(F)\mathcal R_S(F)RS​(F) is the Rademacher average

RS(F)=2−M(k+2)d∑σ∈{±1}M×(k+2)×dsup⁡f∈F∑j=1M∑p=0k+1∑t=1dσj,p,t f(yj,p)t,\mathcal R_S(F) = 2^{-M(k+2)d} \sum_{\sigma \in \{\pm1\}^{M\times(k+2)\times d}} \sup_{f\in F} \sum_{j=1}^M \sum_{p=0}^{k+1} \sum_{t=1}^d \sigma_{j,p,t}\, f(y_{j,p})_t,RS​(F)=2−M(k+2)dσ∈{±1}M×(k+2)×d∑​f∈Fsup​j=1∑M​p=0∑k+1​t=1∑d​σj,p,t​f(yj,p​)t​,

where (yj,0,yj,1,yj,2,…,yj,k+1)=(xj,xj+,xj1−,…,xjk−)(y_{j,0}, y_{j,1}, y_{j,2}, \dots, y_{j,k+1}) = (x_j, x_j^+, x^-_{j1}, \dots, x^-_{jk})(yj,0​,yj,1​,yj,2​,…,yj,k+1​)=(xj​,xj+​,xj1−​,…,xjk−​).

Conventions. All expectations over classes are countable weighted sums.

  • A division by 000 evaluates to 000.
  • A non-summable sum, a non-integrable integral, or a supremum of an unbounded or empty family would also evaluate to 000.
  • Under the boundedness hypotheses these junk cases do not arise for the sums, integrals and suprema. The exception is the supremum over an empty FFF, which is possible only when XXX is empty.
  • The denominators Pr⁡[I+=∅]=1−τk\Pr[I^+ = \emptyset] = 1 - \tau_kPr[I+=∅]=1−τk​ and τ\tauτ are positive under the hypotheses.
  • Pr⁡[∣I+∣<k]=1−τ′\Pr[|I^+| < k] = 1 - \tau'Pr[∣I+∣<k]=1−τ′ may be 000.
Human review
  • Endorsed by Shuze Chen · Nov 24, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Xeroth · Nov 24, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me