Theorem 1: asymptotics of
ProvedAlignmentUniformity.contrastive_loss_asymptoticsLet and . Let be a probability distribution on , and let be a probability distribution on satisfying the Assumption of Section 3: it is symmetric and its marginal is . Encoders are measurable maps . For every encoder , the normalized contrastive loss converges as the number of negative samples tends to infinity:
Moreover:
- The first term is minimized over all encoders if and only if is perfectly aligned.
- If some perfectly uniform encoder exists, then an encoder minimizes the second term over all encoders if and only if it is perfectly uniform.
- The absolute deviation from the limit is : there is a constant such that, for all , .
The theorem shows that, with many negative samples, the contrastive loss optimizes alignment of positive pairs and uniformity of the feature distribution on the sphere.
Formalization Note The constant in item 3 may depend on , and the distributions, as the paper's does for fixed and . The distributions are probability measures rather than densities.
import Mathlib import Definitions.Def_AlignmentUniformity_Basic open MeasureTheory Filter Topology
namespace AlignmentUniformity
theorem contrastive_loss_asymptotics {n m : ℕ} (hm : 1 ≤ m) {τ : ℝ} (hτ : 0 < τ)
(pdata : Measure (Vec n)) [IsProbabilityMeasure pdata]
(ppos : Measure (Vec n × Vec n)) [IsProbabilityMeasure ppos] (hpos : IsPosPairLaw pdata ppos)
(f : Vec n → Vec m) (hf : IsEncoder f) :
Tendsto (fun M : ℕ => contrastiveLoss pdata ppos f τ M - Real.log M) atTop
(𝓝 (alignTerm ppos f τ + uniformTerm pdata f τ)) ∧
((∀ g : Vec n → Vec m, IsEncoder g → alignTerm ppos f τ ≤ alignTerm ppos g τ) ↔
PerfectlyAligned ppos f) ∧
((∃ g : Vec n → Vec m, IsEncoder g ∧ PerfectlyUniform pdata g) →
((∀ g : Vec n → Vec m, IsEncoder g → uniformTerm pdata f τ ≤ uniformTerm pdata g τ) ↔
PerfectlyUniform pdata f)) ∧
∃ C : ℝ, ∀ M : ℕ, 1 ≤ M →
|contrastiveLoss pdata ppos f τ M - Real.log M -
(alignTerm ppos f τ + uniformTerm pdata f τ)| ≤ C / Real.sqrt M := by sorry
end AlignmentUniformityRead-back
What the Lean code literally says, in plain math · claude-opus-5-5
Setting. Fix natural numbers and with , and a real temperature . Write for Euclidean space with the standard inner product and norm ; is allowed, in which case is a single point. The objects are:
- , a Borel probability measure on .
- , a Borel probability measure on with two properties:
- it is invariant under swapping coordinates, ;
- its first marginal equals .
- , an encoder: a Borel measurable map with for every .
In general, an encoder is any measurable map taking values in the unit sphere .
All integrals below are Bochner integrals, which are assigned the value when the integrand is not integrable. The logarithm is the real logarithm with the conventions and for .
Quantities. For , the contrastive loss integrates over together with an independent tuple drawn from the -fold product :
Note that the negatives are paired with , not with . For the sum is empty, the ratio equals , and .
The alignment term and the uniformity term of an encoder are
An encoder is perfectly aligned if for -almost every .
An encoder is perfectly uniform if the pushforward equals . Here is the normalized surface measure on the unit sphere , viewed as a measure on . It is obtained from Lebesgue measure via and then divided by its total mass. For this is the measure giving mass to each of .
Assertion. Under the hypotheses above, all four of the following hold simultaneously.
- Limit. As through the natural numbers,
-
Characterization of alignment minimizers. The following are equivalent:
- for every encoder (with the same );
- is perfectly aligned.
-
Characterization of uniformity minimizers, under an existence hypothesis. Suppose there exists some encoder that is perfectly uniform. Then the following are equivalent:
- for every encoder ;
- .
If no perfectly uniform encoder exists, this part asserts nothing. That happens, for example, when is a single Dirac mass, since its pushforward under any map is again a Dirac mass.
-
Rate. There exists a real constant such that, for every integer ,
The constant is chosen after all the data are fixed, so it may depend on , , , , and . It is not required to be uniform in any of them.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.