Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Lemma 4.2 (as proved): generalization bound for the unsupervised loss

Proved
ContrastiveUnsupervised.unsup_generalization_bound

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 is an absolute constant KKK 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,

Lun(f^)≤Lun(f)+GenM,GenM=K(RRS(F)M+R2log⁡(1/δ)M),L_{un}(\widehat f)\le L_{un}(f)+Gen_M,\qquad Gen_M=K\Big(R\frac{\mathcal R_{\mathcal S}(\mathcal F)}{M}+R^2\sqrt{\frac{\log(1/\delta)}{M}}\Big),Lun​(f​)≤Lun​(f)+GenM​,GenM​=K(RMRS​(F)​+R2Mlog(1/δ)​​),

where RS(F)=Eσ∼{±1}3dMsup⁡f∈F⟨σ,f∣S⟩\mathcal R_{\mathcal S}(\mathcal F)=\mathbb E_{\sigma\sim\{\pm1\}^{3dM}}\sup_{f\in\mathcal F}\langle\sigma,f_{|\mathcal S}\rangleRS​(F)=Eσ∼{±1}3dM​supf∈F​⟨σ,f∣S​⟩.

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 τ<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 unsup_generalization_bound :
    ∃ K : ℝ, ∀ {X : Type u} [MeasurableSpace X] {C : Type v} [Countable C] {d : ℕ}
      (D : C → Measure X) (ρ : C → ℝ), IsLatentClassModel D ρ →
      ∀ (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,
            unsupLoss hinge D ρ 1 (fhat S) ≤
              unsupLoss hinge D ρ 1 f + 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.1, Lemma 4.2, p. 4; proof in Appendix A.3 (Lemma A.2 with k = 1), pp. 11-12
Read-back

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

There is a single real constant KKK (no sign or size condition is imposed on it) such that the following holds uniformly for all choices of the data below. KKK is chosen before all of them and may not depend on any of them.

Data and hypotheses.

  • XXX is any type with a σ-algebra (the data space).

  • CCC is any countable type (the latent classes).

  • d∈Nd \in \mathbb{N}d∈N is a dimension, possibly d=0d = 0d=0. Representations take values in Rd\mathbb{R}^dRd with the Euclidean norm and inner product.

  • (Dc)c∈C(D_c)_{c \in C}(Dc​)c∈C​ is a family of measures on XXX, and ρ:C→R\rho : C \to \mathbb{R}ρ:C→R. They form a latent class model:

    • every DcD_cDc​ is a probability measure;
    • ρ(c)≥0\rho(c) \ge 0ρ(c)≥0 for all ccc;
    • ∑cρ(c)=1\sum_{c} \rho(c) = 1∑c​ρ(c)=1 (unconditional summability to 111).

    This forces CCC and XXX to be nonempty.

  • A boolean choice selects the loss ℓ\ellℓ on a single real score vvv:

    • hinge: ℓ(v)=max⁡{0, 1−v}\ell(v) = \max\{0,\, 1 - v\}ℓ(v)=max{0,1−v};
    • logistic: ℓ(v)=log⁡2(1+e−v)\ell(v) = \log_2(1 + e^{-v})ℓ(v)=log2​(1+e−v).
  • R>0R > 0R>0 is a real number.

  • F\mathcal{F}F is a set of functions f:X→Rdf : X \to \mathbb{R}^df:X→Rd. Every f∈Ff \in \mathcal{F}f∈F is measurable and satisfies ∥f(x)∥≤R\|f(x)\| \le R∥f(x)∥≤R for all xxx.

  • F\mathcal{F}F is pointwise separable: there is a countable F0⊆F\mathcal{F}_0 \subseteq \mathcal{F}F0​⊆F such that every f∈Ff \in \mathcal{F}f∈F is the pointwise limit of some sequence in F0\mathcal{F}_0F0​.

  • M≥1M \ge 1M≥1 is a natural number (the sample size).

  • f^\hat ff^​ is any map from samples to representations, where a 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. For every sample SSS (not just almost every), f^S∈F\hat f_S \in \mathcal{F}f^​S​∈F and f^S\hat f_Sf^​S​ is an exact empirical-risk minimizer over F\mathcal{F}F:

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

No measurability of S↦f^SS \mapsto \hat f_SS↦f^​S​ is assumed. If F\mathcal{F}F is empty, this hypothesis cannot be satisfied.

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

The losses.

The empirical loss is

L^un(f;S)=1M∑j=1Mℓ(f(xj)⊤(f(xj+)−f(xj−))).\hat L_{\mathrm{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−​))).

The population loss Lun(f)L_{\mathrm{un}}(f)Lun​(f) is the integral of ℓ(f(x)⊤(f(x+)−f(x−)))\ell\big(f(x)^\top(f(x^+) - f(x^-))\big)ℓ(f(x)⊤(f(x+)−f(x−))) against Dsim⊗Dneg\mathcal{D}_{\mathrm{sim}} \otimes \mathcal{D}_{\mathrm{neg}}Dsim​⊗Dneg​, where:

  • Dsim=∑cρ(c) Dc⊗Dc\mathcal{D}_{\mathrm{sim}} = \sum_c \rho(c)\, D_c \otimes D_cDsim​=∑c​ρ(c)Dc​⊗Dc​ is the law of (x,x+)(x, x^+)(x,x+);
  • Dneg=∑cρ(c) Dc\mathcal{D}_{\mathrm{neg}} = \sum_c \rho(c)\, D_cDneg​=∑c​ρ(c)Dc​ is the law of x−x^-x−.

This integral is taken to be 000 by convention if the integrand is not integrable.

The Rademacher term.

Label the three points of the jjj-th tuple as zj,0=xjz_{j,0} = x_jzj,0​=xj​, zj,1=xj+z_{j,1} = x_j^+zj,1​=xj+​, zj,2=xj−z_{j,2} = x_j^-zj,2​=xj−​. The term is

RS(F)=123dM∑σ∈{±1}M×3×dsup⁡f∈F∑j=1M∑p=02∑t=1dσj,p,t f(zj,p)t.\mathcal{R}_S(\mathcal{F}) = \frac{1}{2^{3dM}} \sum_{\sigma \in \{\pm1\}^{M \times 3 \times d}} \sup_{f \in \mathcal{F}} \sum_{j=1}^M \sum_{p=0}^{2} \sum_{t=1}^d \sigma_{j,p,t}\, f(z_{j,p})_t .RS​(F)=23dM1​σ∈{±1}M×3×d∑​f∈Fsup​j=1∑M​p=0∑2​t=1∑d​σj,p,t​f(zj,p​)t​.

Here the supremum is a real supremum, with the convention that it equals 000 when the set is empty or unbounded above. When d=0d = 0d=0 the term is 000.

The error term.

With natural logarithm, the error term is

Gen=K(R RS(F)M+R2log⁡(1/δ)M).\mathrm{Gen} = K\left(\frac{R\, \mathcal{R}_S(\mathcal{F})}{M} + R^2 \sqrt{\frac{\log(1/\delta)}{M}}\right).Gen=K(MRRS​(F)​+R2Mlog(1/δ)​​).

This is the general formula with k=1k = 1k=1, where k=1\sqrt{k} = 1k​=1 and log⁡k=0\log k = 0logk=0.

Conclusion.

Let the sample SSS be drawn from (Dsim⊗Dneg)⊗M(\mathcal{D}_{\mathrm{sim}} \otimes \mathcal{D}_{\mathrm{neg}})^{\otimes M}(Dsim​⊗Dneg​)⊗M, i.e., MMM independent tuples. Consider the set of samples SSS for which there exists some f∈Ff \in \mathcal{F}f∈F with

Lun(f^S)>Lun(f)+Gen.L_{\mathrm{un}}(\hat f_S) > L_{\mathrm{un}}(f) + \mathrm{Gen}.Lun​(f^​S​)>Lun​(f)+Gen.

The statement is that this set has measure at most δ\deltaδ. The set is not required to be measurable; for a non-measurable set, the measure means the outer measure.

Equivalently, outside a set of outer measure at most δ\deltaδ,

Lun(f^S)≤Lun(f)+Genfor every f∈F.L_{\mathrm{un}}(\hat f_S) \le L_{\mathrm{un}}(f) + \mathrm{Gen} \quad \text{for every } f \in \mathcal{F}.Lun​(f^​S​)≤Lun​(f)+Genfor every f∈F.
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