Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Theorem 4.1 (as proved): upper bound using the unsupervised loss

Proved
ContrastiveUnsupervised.unsup_loss_upper_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,

Lsupμ(f^)≤11−τ(Lun(f)−τ)+11−τGenM,GenM=K(RRS(F)M+R2log⁡(1/δ)M).L^\mu_{sup}(\widehat f)\le\frac{1}{1-\tau}\big(L_{un}(f)-\tau\big)+\frac{1}{1-\tau}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).Lsupμ​(f​)≤1−τ1​(Lun​(f)−τ)+1−τ1​GenM​,GenM​=K(RMRS​(F)​+R2Mlog(1/δ)​​).

If F\mathcal FF contains a representation with small unsupervised loss, the learned representation has small average binary loss with the mean classifier.

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_loss_upper_bound :
    ∃ K : ℝ, ∀ {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,
            avgMeanSupLoss (stdLoss hinge) D ρ 1 (fhat S) ≤
              1 / (1 - collisionProb ρ) * (unsupLoss hinge D ρ 1 f - collisionProb ρ) +
                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.1, Theorem 4.1, p. 4
Read-back

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

There is a single real constant KKK such that the statement below holds for every choice of the following data:

  • a measurable space XXX and a countable set CCC of "latent classes";
  • a dimension d∈Nd \in \mathbb{N}d∈N, possibly d=0d = 0d=0, in which case every representation is the zero vector;
  • a family (Dc)c∈C(D_c)_{c \in C}(Dc​)c∈C​ of measures on XXX and a real-valued function ρ\rhoρ on CCC;
  • a choice of loss (hinge or logistic);
  • a radius RRR, a function class FFF, a sample size MMM, a learning rule f^\hat ff^​, and a confidence level δ\deltaδ.

KKK is chosen before all of these, so it may not depend on any of them.

Hypotheses on the class model.

  • Every 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. This forces C≠∅C \neq \emptysetC=∅ and X≠∅X \neq \emptysetX=∅. CCC may be infinite.
  • The collision probability satisfies τ:=∑c∈Cρ(c)2<1\tau := \sum_{c \in C} \rho(c)^2 < 1τ:=∑c∈C​ρ(c)2<1.

The loss. On one real number vvv, the loss ℓ\ellℓ is one of:

ℓ(v)=max⁡{0, 1−v}(hinge),ℓ(v)=log⁡2 ⁣(1+e−v)(logistic).\ell(v) = \max\{0,\, 1 - v\} \quad \text{(hinge)}, \qquad \ell(v) = \log_2\!\big(1 + e^{-v}\big) \quad \text{(logistic)}.ℓ(v)=max{0,1−v}(hinge),ℓ(v)=log2​(1+e−v)(logistic).

The same choice is used everywhere below.

Hypotheses on RRR and FFF.

  • R>0R > 0R>0.
  • FFF is a set of functions f:X→Rdf : X \to \mathbb{R}^df:X→Rd, with the Euclidean norm and inner product on Rd\mathbb{R}^dRd.
  • 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: some countable F0⊆FF_0 \subseteq FF0​⊆F has the property that every f∈Ff \in Ff∈F is a pointwise limit of a sequence in F0F_0F0​.

Samples. M≥1M \ge 1M≥1 is an integer. A sample is a tuple

S=((xj,xj+,xj−))j=1M∈(X×X×X)M.S = \big((x_j, x_j^+, x_j^-)\big)_{j=1}^M \in (X \times X \times X)^M.S=((xj​,xj+​,xj−​))j=1M​∈(X×X×X)M.

The empirical unsupervised loss of a function fff on SSS is

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

Hypothesis on f^\hat ff^​. f^\hat ff^​ assigns to every sample SSS a function f^S\hat f_Sf^​S​ such that:

  • f^S∈F\hat f_S \in Ff^​S​∈F;
  • L^un(f^S;S)≤L^un(f;S)\hat L_{\mathrm{un}}(\hat f_S; S) \le \hat L_{\mathrm{un}}(f; S)L^un​(f^​S​;S)≤L^un​(f;S) for every f∈Ff \in Ff∈F.

That is, f^\hat ff^​ is an exact empirical-risk minimizer over FFF for every sample. No measurability of S↦f^SS \mapsto \hat f_SS↦f^​S​ is assumed.

Hypothesis on δ\deltaδ. 0<δ≤120 < \delta \le \tfrac120<δ≤21​.

The quantities in the conclusion.

Distribution of samples. The sample SSS is drawn from the MMM-fold product of the law of one tuple (x,x+,x−)(x, x^+, x^-)(x,x+,x−). In that law, (x,x+)(x, x^+)(x,x+) and x−x^-x− are independent, with

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

Population unsupervised loss. For f∈Ff \in Ff∈F,

Lun(f)=E(x,x+,x−) ℓ(f(x)⊤(f(x+)−f(x−))),L_{\mathrm{un}}(f) = \mathbb{E}_{(x,x^+,x^-)}\, \ell\big(f(x)^\top(f(x^+) - f(x^-))\big),Lun​(f)=E(x,x+,x−)​ℓ(f(x)⊤(f(x+)−f(x−))),

with expectation over the tuple law just described.

Mean-classifier supervised loss. For a representation ggg, the class means are

μc=∫g dDc.\mu_c = \int g \, dD_c.μc​=∫gdDc​.

For a pair c≠c′c \neq c'c=c′, the two-class mean-classifier loss is

Lsupμ({c,c′},g)=12∫ℓ((μc−μc′)⊤g(x)) dDc(x)+12∫ℓ((μc′−μc)⊤g(x)) dDc′(x).L^\mu_{\mathrm{sup}}(\{c,c'\}, g) = \tfrac12 \int \ell\big((\mu_c - \mu_{c'})^\top g(x)\big)\, dD_c(x) + \tfrac12 \int \ell\big((\mu_{c'} - \mu_c)^\top g(x)\big)\, dD_{c'}(x).Lsupμ​({c,c′},g)=21​∫ℓ((μc​−μc′​)⊤g(x))dDc​(x)+21​∫ℓ((μc′​−μc​)⊤g(x))dDc′​(x).

This uses the uniform label distribution 12,12\tfrac12, \tfrac1221​,21​. The averaged loss is

Lsupμ(g)=∑(c0,c1): c0≠c1ρ(c0)ρ(c1) Lsupμ({c0,c1},g)∑(c0,c1): c0≠c1ρ(c0)ρ(c1).L^\mu_{\mathrm{sup}}(g) = \frac{\sum_{(c_0,c_1) :\, c_0 \neq c_1} \rho(c_0)\rho(c_1)\, L^\mu_{\mathrm{sup}}(\{c_0,c_1\}, g)}{\sum_{(c_0,c_1) :\, c_0 \neq c_1} \rho(c_0)\rho(c_1)}.Lsupμ​(g)=∑(c0​,c1​):c0​=c1​​ρ(c0​)ρ(c1​)∑(c0​,c1​):c0​=c1​​ρ(c0​)ρ(c1​)Lsupμ​({c0​,c1​},g)​.

Both sums run over ordered pairs. This is Lsupμ({c0,c1},g)L^\mu_{\mathrm{sup}}(\{c_0, c_1\}, g)Lsupμ​({c0​,c1​},g) averaged over independent c0,c1∼ρc_0, c_1 \sim \rhoc0​,c1​∼ρ, conditioned on c0≠c1c_0 \neq c_1c0​=c1​.

Empirical Rademacher average. Write zj,1=xjz_{j,1} = x_jzj,1​=xj​, zj,2=xj+z_{j,2} = x_j^+zj,2​=xj+​, zj,3=xj−z_{j,3} = x_j^-zj,3​=xj−​. Then

RS(F)=123dM∑σ∈{±1}M×3×d sup⁡f∈F∑j=1M∑p=13∑t=1dσj,p,t f(zj,p)t,\mathcal{R}_S(F) = \frac{1}{2^{3dM}} \sum_{\sigma \in \{\pm 1\}^{M \times 3 \times d}} \ \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)=23dM1​σ∈{±1}M×3×d∑​ f∈Fsup​j=1∑M​p=1∑3​t=1∑d​σj,p,t​f(zj,p​)t​,

where f(⋅)tf(\cdot)_tf(⋅)t​ is the ttt-th coordinate.

Generalization term. With natural logarithm,

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

This depends on SSS. It is the general expression evaluated at one negative sample, where the factor 1\sqrt{1}1​ and the term log⁡1\log 1log1 vanish.

Conclusion. Let BBB be the set of samples SSS for which some f∈Ff \in Ff∈F violates

Lsupμ(f^S)  ≤  11−τ(Lun(f)−τ)+11−τ Gen.L^\mu_{\mathrm{sup}}(\hat f_S) \;\le\; \frac{1}{1-\tau}\big(L_{\mathrm{un}}(f) - \tau\big) + \frac{1}{1-\tau}\,\mathrm{Gen}.Lsupμ​(f^​S​)≤1−τ1​(Lun​(f)−τ)+1−τ1​Gen.

The theorem asserts that BBB has probability at most δ\deltaδ under the product sample law. BBB need not be measurable; in that case the asserted bound is on its outer measure. Equivalently, outside a set of probability at most δ\deltaδ, the displayed inequality holds simultaneously for all f∈Ff \in Ff∈F.

Conventions. The integrals and infinite sums above are taken with the usual conventions:

  • an integral of a non-integrable function is 000;
  • a non-summable infinite sum is 000;
  • a supremum of a set that is not bounded above, or is empty, is 000.

Under the stated hypotheses the integrands are bounded and FFF is nonempty.

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