Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Theorem 4.5 (as proved): guaranteed average binary classification

Proved
ContrastiveUnsupervised.binary_contrastive_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​, and let τ=∑cρ(c)2<1\tau=\sum_c\rho(c)^2<1τ=∑c​ρ(c)2<1. Let ℓ\ellℓ be the hinge or the logistic loss. Let F\mathcal FF be a pointwise separable class of measurable f:X→Rdf:\mathcal X\to\mathbb R^df:X→Rd with ∥f(⋅)∥≤R\|f(\cdot)\|\le R∥f(⋅)∥≤R, R>0R>0R>0. Let f^\widehat ff​ be an empirical minimizer, 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 every training set S\mathcal SS of M≥1M\ge1M≥1 tuples (x,x+,x−)(x,x^+,x^-)(x,x+,x−) (one negative sample). 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−δ over the training set S\mathcal SS of M≥1M\ge1M≥1 tuples drawn from (Dsim×Dneg)M(\mathcal D_{sim}\times\mathcal D_{neg})^M(Dsim​×Dneg​)M, for all f∈Ff\in\mathcal Ff∈F,

Lsup(f^)≤Lsupμ(f^)≤Lun≠(f)+β s(f)+η GenM,L_{sup}(\widehat f)\le L^\mu_{sup}(\widehat f)\le L^{\ne}_{un}(f)+\beta\,s(f)+\eta\,Gen_M,Lsup​(f​)≤Lsupμ​(f​)≤Lun=​(f)+βs(f)+ηGenM​,

where β=c′τ1−τ\beta=c'\frac{\tau}{1-\tau}β=c′1−ττ​, η=11−τ\eta=\frac{1}{1-\tau}η=1−τ1​, GenM=K(R RS(F)/M+R2log⁡(1/δ)/M)Gen_M=K\big(R\,\mathcal R_{\mathcal S}(\mathcal F)/M+R^2\sqrt{\log(1/\delta)/M}\big)GenM​=K(RRS​(F)/M+R2log(1/δ)/M​), Lun≠(f)L^{\ne}_{un}(f)Lun=​(f) is the unsupervised loss conditioned on c+≠c−c^+\ne c^-c+=c−, and s(f)s(f)s(f) is the intraclass deviation.

This is the paper's main guarantee: if some f∈Ff\in\mathcal Ff∈F contrasts different classes well and is concentrated within classes, the empirical minimizer of the contrastive loss does well on average binary classification.

Formalization Note LsupL_{sup}Lsup​ and LsupμL^\mu_{sup}Lsupμ​ are averages over pairs of distinct classes with uniform label distribution, and LsupL_{sup}Lsup​ uses the best linear classifier. 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 τ<1\tau<1τ<1 is implicit in the paper's division by 1−τ1-\tau1−τ.

Preamble
import Mathlib
import Definitions.Def_ContrastiveUnsupervised_Basic

open MeasureTheory Filter Topology

universe u v
Formal statement
namespace ContrastiveUnsupervised

theorem binary_contrastive_guarantee :
    ∃ K c' : ℝ, 0 < c' ∧
      ∀ {X : Type u} [MeasurableSpace X] {C : Type v} [Countable C] {d : ℕ}
      (D : C → Measure X) (ρ : C → ℝ), IsLatentClassModel D ρ → collisionProb ρ < 1 →
      ∀ (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 1 → X)) → X → Rep d),
        (∀ S, fhat S ∈ F ∧ ∀ f ∈ F, empUnsupLoss hinge 1 (fhat S) S ≤ empUnsupLoss hinge 1 f S) →
      ∀ δ : ℝ, 0 < δ → δ ≤ 1 / 2 →
        sampleMeasure D ρ 1 M {S | ¬ ∀ f ∈ F,
            avgSupLoss (stdLoss hinge) D ρ 1 (fhat S) ≤
                avgMeanSupLoss (stdLoss hinge) D ρ 1 (fhat S) ∧
              avgMeanSupLoss (stdLoss hinge) D ρ 1 (fhat S) ≤
                unsupLossNeq hinge D ρ 1 f +
                  c' * (collisionProb ρ / (1 - collisionProb ρ)) * intraclassDeviation D ρ f +
                  1 / (1 - collisionProb ρ) * genError K R 1 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), Section 4.2, Theorem 4.5, p. 5
Read-back

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

Claim. There exist real constants KKK and c′c'c′, with c′>0c' > 0c′>0 and no sign condition on KKK, such that the following holds for every configuration described below. The constants do not depend on any of the data.

Setting and hypotheses.

  • XXX is any measurable space, CCC is any countable type of "classes", and d≥0d \ge 0d≥0 is a natural number. Representations take values in Rd\mathbb{R}^dRd with the Euclidean norm and inner product.

  • D=(Dc)c∈CD = (D_c)_{c \in C}D=(Dc​)c∈C​ assigns a measure DcD_cDc​ on XXX to each class, and ρ:C→R\rho : C \to \mathbb{R}ρ:C→R. The pair is assumed to be a latent class model: each DcD_cDc​ is a probability measure, ρ(c)≥0\rho(c) \ge 0ρ(c)≥0 for all ccc, and ∑cρ(c)=1\sum_c \rho(c) = 1∑c​ρ(c)=1.

  • The collision probability τ:=∑cρ(c)2\tau := \sum_{c} \rho(c)^2τ:=∑c​ρ(c)2 satisfies τ<1\tau < 1τ<1.

  • A Boolean flag selects the loss ℓ\ellℓ used throughout. For a finite index set sss and vector vvv:

    • hinge: ℓ(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​)}, with ℓ=0\ell = 0ℓ=0 when s=∅s = \emptysets=∅;
    • logistic: ℓ(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​).

    On a single coordinate these become max⁡{0,1−v}\max\{0, 1-v\}max{0,1−v} and log⁡2(1+e−v)\log_2(1+e^{-v})log2​(1+e−v) respectively.

  • R>0R > 0R>0 is a real number.

  • FFF is a set of functions f:X→Rdf : X \to \mathbb{R}^df:X→Rd with two properties:

    • every 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 a pointwise limit, at every xxx, of some sequence in F0F_0F0​.
  • M≥1M \ge 1M≥1 is a natural number, the sample size.

  • A training sample is S=(xj,xj+,xj−)j=1M∈(X×X×X)MS = (x_j, x_j^+, x_j^-)_{j=1}^M \in (X\times X\times X)^MS=(xj​,xj+​,xj−​)j=1M​∈(X×X×X)M, with exactly one negative sample per tuple.

  • f^\hat ff^​ maps each sample SSS to a function f^S\hat f_Sf^​S​. It is assumed that for every sample SSS (not merely almost every), f^S∈F\hat f_S \in Ff^​S​∈F and f^S\hat f_Sf^​S​ is an exact minimizer of the empirical loss over FFF:

L^un(f^S;S)≤L^un(f;S)for all f∈F.\hat L_{un}(\hat f_S; S) \le \hat L_{un}(f; S) \quad \text{for all } f \in F.L^un​(f^​S​;S)≤L^un​(f;S)for all f∈F.

Here the empirical loss is

L^un(f;S)=1M∑j=1Mℓ(f(xj)⊤(f(xj+)−f(xj−))).\hat L_{un}(f;S) = \frac1M \sum_{j=1}^M \ell\big(f(x_j)^\top(f(x_j^+) - f(x_j^-))\big).L^un​(f;S)=M1​j=1∑M​ℓ(f(xj​)⊤(f(xj+​)−f(xj−​))).

No measurability of S↦f^SS \mapsto \hat f_SS↦f^​S​ is assumed.

  • δ\deltaδ is a real number with 0<δ≤120 < \delta \le \tfrac120<δ≤21​.

Distribution of the sample. Define

Dsim=∑cρ(c) Dc⊗Dc  on pairs (x,x+),Dneg=∑cρ(c) Dc  on x−.D_{sim} = \sum_c \rho(c)\, D_c \otimes D_c \ \text{ on pairs } (x, x^+), \qquad D_{neg} = \sum_c \rho(c)\, D_c \ \text{ on } x^-.Dsim​=c∑​ρ(c)Dc​⊗Dc​  on pairs (x,x+),Dneg​=c∑​ρ(c)Dc​  on x−.

One tuple (x,x+,x−)(x, x^+, x^-)(x,x+,x−) has law Dsim⊗DnegD_{sim} \otimes D_{neg}Dsim​⊗Dneg​. The sample SSS has law P=(Dsim⊗Dneg)⊗MP = (D_{sim}\otimes D_{neg})^{\otimes M}P=(Dsim​⊗Dneg​)⊗M.

Conclusion. Let EEE be the set of samples SSS for which the following statement fails:

For every f∈Ff \in Ff∈F, both

Lsup(f^S)≤Lsupμ(f^S)L_{sup}(\hat f_S) \le L^\mu_{sup}(\hat f_S)Lsup​(f^​S​)≤Lsupμ​(f^​S​)

and

Lsupμ(f^S)≤Lun≠(f)+c′ τ1−τ s(f)+11−τ K(R RS(F)M+R2log⁡(1/δ)M).L^\mu_{sup}(\hat f_S) \le L^{\neq}_{un}(f) + c'\,\frac{\tau}{1-\tau}\, s(f) + \frac{1}{1-\tau}\, K\Big(\frac{R\,\mathcal{R}_S(F)}{M} + R^2\sqrt{\tfrac{\log(1/\delta)}{M}}\Big).Lsupμ​(f^​S​)≤Lun=​(f)+c′1−ττ​s(f)+1−τ1​K(MRRS​(F)​+R2Mlog(1/δ)​​).

Then P(E)≤δP(E) \le \deltaP(E)≤δ. If EEE is not measurable, P(E)P(E)P(E) is its outer measure.

The left-hand sides involve only the data-dependent f^S\hat f_Sf^​S​. The right-hand side is evaluated at an arbitrary comparator f∈Ff \in Ff∈F. The first inequality is also part of the event, sitting inside the quantifier over fff.

The quantities, unfolded (one negative sample, so 222-way tasks):

  • Class mean: μc=∫f dDc∈Rd\mu_c = \int f\,dD_c \in \mathbb{R}^dμc​=∫fdDc​∈Rd.
  • Supervised loss of a task. Take a task T={c1,c2}T = \{c_1, c_2\}T={c1​,c2​} with uniform label weights 12\tfrac1221​ and a classifier given by rows Wc∈RdW_c \in \mathbb{R}^dWc​∈Rd. Its loss is
∑c∈T12∫ℓ((Wc−Wc′)⊤f(x)) dDc(x),\sum_{c\in T}\tfrac12\int \ell\big((W_c - W_{c'})^\top f(x)\big)\,dD_c(x),c∈T∑​21​∫ℓ((Wc​−Wc′​)⊤f(x))dDc​(x),

where c′c'c′ is the other class of TTT.

  • Lsup(T,f)L_{sup}(T,f)Lsup​(T,f) is the infimum of this over all row assignments W:C→RdW : C\to\mathbb{R}^dW:C→Rd.
  • Lsupμ(T,f)L^\mu_{sup}(T,f)Lsupμ​(T,f) is its value at the mean classifier Wc=μcW_c = \mu_cWc​=μc​.
  • Averaged supervised losses. Average over ordered pairs (c1,c2)(c_1,c_2)(c1​,c2​) with c1≠c2c_1 \ne c_2c1​=c2​, weighted by ρ(c1)ρ(c2)\rho(c_1)\rho(c_2)ρ(c1​)ρ(c2​), normalized by the total such weight:
Lsup(f)=∑c1≠c2ρ(c1)ρ(c2) Lsup({c1,c2},f)∑c1≠c2ρ(c1)ρ(c2),L_{sup}(f) = \frac{\sum_{c_1\ne c_2}\rho(c_1)\rho(c_2)\,L_{sup}(\{c_1,c_2\},f)}{\sum_{c_1\ne c_2}\rho(c_1)\rho(c_2)},Lsup​(f)=∑c1​=c2​​ρ(c1​)ρ(c2​)∑c1​=c2​​ρ(c1​)ρ(c2​)Lsup​({c1​,c2​},f)​,

and Lsupμ(f)L^\mu_{sup}(f)Lsupμ​(f) is defined the same way with Lsupμ(T,f)L^\mu_{sup}(T,f)Lsupμ​(T,f).

  • Unsupervised loss on distinct classes. With x,x+∼Dc+x, x^+ \sim D_{c^+}x,x+∼Dc+​ and x−∼Dc−x^- \sim D_{c^-}x−∼Dc−​ independent:
Lun≠(f)=∑c+≠c−ρ(c+)ρ(c−) E ℓ(f(x)⊤(f(x+)−f(x−)))∑c+≠c−ρ(c+)ρ(c−).L^{\neq}_{un}(f) = \frac{\sum_{c^+\ne c^-}\rho(c^+)\rho(c^-)\,\mathbb{E}\,\ell\big(f(x)^\top(f(x^+)-f(x^-))\big)}{\sum_{c^+\ne c^-}\rho(c^+)\rho(c^-)}.Lun=​(f)=∑c+=c−​ρ(c+)ρ(c−)∑c+=c−​ρ(c+)ρ(c−)Eℓ(f(x)⊤(f(x+)−f(x−)))​.
  • 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) under DcD_cDc​, and ∥⋅∥2\|\cdot\|_2∥⋅∥2​ is the spectral (operator) norm.

  • Rademacher average. Let σ\sigmaσ range uniformly over all sign patterns {±1}M×3×d\{\pm1\}^{M\times 3\times d}{±1}M×3×d. Then
RS(F)=2−3dM∑σ sup⁡f∈F ∑j=1M∑p=13∑t=1dσj,p,t f(zj,p)t,\mathcal{R}_S(F) = 2^{-3dM}\sum_{\sigma}\ \sup_{f\in F}\ \sum_{j=1}^M\sum_{p=1}^{3}\sum_{t=1}^d \sigma_{j,p,t}\, f(z_{j,p})_t,RS​(F)=2−3dMσ∑​ f∈Fsup​ j=1∑M​p=1∑3​t=1∑d​σj,p,t​f(zj,p​)t​,

where (zj,1,zj,2,zj,3)=(xj,xj+,xj−)(z_{j,1}, z_{j,2}, z_{j,3}) = (x_j, x_j^+, x_j^-)(zj,1​,zj,2​,zj,3​)=(xj​,xj+​,xj−​).

  • Generalization term. It arises from the general expression
K(Rk RS(F)M+(R2+log⁡k)log⁡(1/δ)M)K\Big(\frac{R\sqrt{k}\,\mathcal{R}_S(F)}{M} + (R^2+\log k)\sqrt{\tfrac{\log(1/\delta)}{M}}\Big)K(MRk​RS​(F)​+(R2+logk)Mlog(1/δ)​​)

at k=1k = 1k=1, which reduces to the term displayed in the conclusion. Its sign follows the sign of KKK.

Degenerate and edge cases.

  • Junk-value conventions. These are the formalization's defaults:
    • a divergent infinite sum is treated as 000;
    • a non-integrable function has integral 000;
    • an infimum or supremum of a set unbounded in that direction, or of an empty set, is 000.
  • Positivity of τ\tauτ. The hypotheses force τ>0\tau > 0τ>0. The normalizing sums over distinct pairs equal 1−τ>01-\tau > 01−τ>0 when the series converge.
  • d=0d = 0d=0. All representations are 000 and RS(F)=0\mathcal{R}_S(F) = 0RS​(F)=0.
  • Unattainable minimum. The exact-minimizer hypothesis on f^\hat ff^​ must hold at every sample. If for some SSS no minimizer of L^un(⋅ ;S)\hat L_{un}(\cdot\,;S)L^un​(⋅;S) exists in FFF, no such f^\hat ff^​ exists and the statement is vacuous for that FFF.
  • Range of log⁡(1/δ)\log(1/\delta)log(1/δ). Since δ≤12\delta \le \tfrac12δ≤21​, we have log⁡(1/δ)≥log⁡2\log(1/\delta) \ge \log 2log(1/δ)≥log2.
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