Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Eqs. (4)–(5) (as corrected): InfoNCE embedding gradients and G=−WXG=-WXG=−WX

Proved
DimensionalCollapse.infonce_gradients_and_G_eq_neg_WX

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

contrastive-learninggradient-flowinfonceself-supervised-learningsingular-values

For embeddings zi,zi′∈Rdz_i,z_i'\in\mathbb{R}^dzi​,zi′​∈Rd (i=1,…,Ni=1,\dots,Ni=1,…,N), the gradients of the InfoNCE loss are

gzi=∑j≠iαij(zj−zi′)+∑j≠iαji(zj−zi),gzi′=∑j≠iαij(zi′−zi).g_{z_i}=\sum_{j\neq i}\alpha_{ij}(z_j-z_i')+\sum_{j\neq i}\alpha_{ji}(z_j-z_i),\qquad g_{z_i'}=\sum_{j\neq i}\alpha_{ij}(z_i'-z_i).gzi​​=j=i∑​αij​(zj​−zi′​)+j=i∑​αji​(zj​−zi​),gzi′​​=j=i∑​αij​(zi′​−zi​).

Consequently, for every linear model W∈Rd×nW\in\mathbb{R}^{d\times n}W∈Rd×n and inputs xi,xi′∈Rnx_i,x_i'\in\mathbb{R}^nxi​,xi′​∈Rn, with z=Wxz=Wxz=Wx,

G=∑i(gzixi⊤+gzi′xi′⊤)=−WX,G=\sum_i\big(g_{z_i}x_i^\top+g_{z_i'}x_i'^\top\big)=-WX,G=i∑​(gzi​​xi⊤​+gzi′​​xi′⊤​)=−WX,

where

X=∑i(∑j≠iαij(xi′−xj)+∑j≠iαji(xi−xj))xi⊤−∑i(1−αii)(xi′−xi)xi′⊤.X=\sum_i\Big(\sum_{j\neq i}\alpha_{ij}(x_i'-x_j)+\sum_{j\neq i}\alpha_{ji}(x_i-x_j)\Big)x_i^\top-\sum_i(1-\alpha_{ii})(x_i'-x_i)x_i'^\top .X=i∑​(j=i∑​αij​(xi′​−xj​)+j=i∑​αji​(xi​−xj​))xi⊤​−i∑​(1−αii​)(xi′​−xi​)xi′⊤​.

Combined with Lemma 1, the linear model evolves by W˙=WX\dot W=WXW˙=WX, which is the equation that Theorem 1 studies.

Formalization Note The matrix XXX is the one written at the start of the proof of Lemma 2 (Appendix B.2, p. 14). Eq. (6) on p. 4 prints a minus sign in front of the first sum; with that sign, G=−WXG=-WXG=−WX is false (a numerical check with N=4N=4N=4, n=d=3n=d=3n=d=3 gives an error of order 111).

Preamble
import Mathlib
import Definitions.Def_DimensionalCollapse_Basic

open Matrix Filter Topology
Formal statement
namespace DimensionalCollapse

theorem infonce_gradients_and_G_eq_neg_WX {N n d : ℕ} :
    (∀ (z z' : Fin N → Fin d → ℝ) (i : Fin N),
      gradZ z z' i = (∑ j ∈ Finset.univ.erase i, alpha z z' i j • (z j - z' i)) +
        ∑ j ∈ Finset.univ.erase i, alpha z z' j i • (z j - z i)) ∧
    (∀ (z z' : Fin N → Fin d → ℝ) (i : Fin N),
      gradZ' z z' i = ∑ j ∈ Finset.univ.erase i, alpha z z' i j • (z' i - z i)) ∧
    (∀ (x x' : Fin N → Fin n → ℝ) (W : Matrix (Fin d) (Fin n) ℝ),
      Gmat x x' W = -(W * Xmat x x' W)) := by sorry

end DimensionalCollapse
Source
Jing, Vincent, LeCun and Tian, Understanding Dimensional Collapse in Contrastive Self-supervised Learning, ICLR 2022, arXiv:2110.09348v3, Section 4.2, eqs. (4), (5), (6), p. 4; X in the form of Appendix B.2, p. 14
Read-back

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

Setting. Fix natural numbers NNN (number of samples), nnn (input dimension) and ddd (embedding dimension). All three may be 000, and there are no other hypotheses. For a vector v∈Rdv \in \mathbb{R}^dv∈Rd, write ∣v∣2=∑c=1dvc2|v|^2 = \sum_{c=1}^d v_c^2∣v∣2=∑c=1d​vc2​. Below, ece_cec​ denotes the ccc-th standard basis vector of Rd\mathbb{R}^dRd.

Definitions used. For two families of embeddings z=(z1,…,zN)z = (z_1,\dots,z_N)z=(z1​,…,zN​) and z′=(z1′,…,zN′)z' = (z_1',\dots,z_N')z′=(z1′​,…,zN′​) in Rd\mathbb{R}^dRd, define the partition function

Zi=∑j≠ie−∣zi−zj∣2/2+e−∣zi−zi′∣2/2.Z_i = \sum_{j \ne i} e^{-|z_i - z_j|^2/2} + e^{-|z_i - z_i'|^2/2}.Zi​=j=i∑​e−∣zi​−zj​∣2/2+e−∣zi​−zi′​∣2/2.

Define the loss

L(z,z′)=−∑i=1Nlog⁡e−∣zi−zi′∣2/2Zi.L(z,z') = -\sum_{i=1}^N \log\frac{e^{-|z_i - z_i'|^2/2}}{Z_i}.L(z,z′)=−i=1∑N​logZi​e−∣zi​−zi′​∣2/2​.

Define the weights

αij=e−∣zi−zj∣2/2Zi (j≠i),αii=e−∣zi−zi′∣2/2Zi.\alpha_{ij} = \frac{e^{-|z_i - z_j|^2/2}}{Z_i}\ (j \ne i), \qquad \alpha_{ii} = \frac{e^{-|z_i - z_i'|^2/2}}{Z_i}.αij​=Zi​e−∣zi​−zj​∣2/2​ (j=i),αii​=Zi​e−∣zi​−zi′​∣2/2​.

The vector gzi∈Rdg_{z_i} \in \mathbb{R}^dgzi​​∈Rd is defined componentwise. Its ccc-th entry is the derivative at s=0s = 0s=0 of

s↦L(z with zi replaced by zi+sec, z′).s \mapsto L(z \text{ with } z_i \text{ replaced by } z_i + s e_c,\ z').s↦L(z with zi​ replaced by zi​+sec​, z′).

The vector gzi′g_{z_i'}gzi′​​ is defined the same way, perturbing zi′z_i'zi′​ instead. Each is a vector of ordinary one-variable derivatives, with the convention that a non-existent derivative is recorded as 000.

Note that ziz_izi​ appears in ZiZ_iZi​ and also in every ZjZ_jZj​ with j≠ij \ne ij=i, through the term e−∣zj−zi∣2/2e^{-|z_j - z_i|^2/2}e−∣zj​−zi​∣2/2.

For inputs x=(x1,…,xN)x = (x_1,\dots,x_N)x=(x1​,…,xN​) and x′=(x1′,…,xN′)x' = (x_1',\dots,x_N')x′=(x1′​,…,xN′​) in Rn\mathbb{R}^nRn and a matrix W∈Rd×nW \in \mathbb{R}^{d\times n}W∈Rd×n:

  • Set zi=Wxiz_i = W x_izi​=Wxi​ and zi′=Wxi′z_i' = W x_i'zi′​=Wxi′​. Let α\alphaα, gzig_{z_i}gzi​​ and gzi′g_{z_i'}gzi′​​ be computed at these embeddings.
  • Define the d×nd\times nd×n matrix
G=∑i(gzixi⊤+gzi′xi′⊤).G = \sum_i \big(g_{z_i} x_i^{\top} + g_{z_i'} {x_i'}^{\top}\big).G=i∑​(gzi​​xi⊤​+gzi′​​xi′​⊤).
  • Define the n×nn\times nn×n matrix
X=∑i(∑j≠iαij(xi′−xj)+∑j≠iαji(xi−xj))xi⊤  −  ∑i(1−αii)(xi′−xi)xi′⊤.X = \sum_i \Big(\sum_{j\ne i}\alpha_{ij}(x_i' - x_j) + \sum_{j \ne i}\alpha_{ji}(x_i - x_j)\Big)x_i^{\top} \;-\; \sum_i (1-\alpha_{ii})(x_i' - x_i){x_i'}^{\top}.X=i∑​(j=i∑​αij​(xi′​−xj​)+j=i∑​αji​(xi​−xj​))xi⊤​−i∑​(1−αii​)(xi′​−xi​)xi′​⊤.

Assertion. The statement is the conjunction of three claims.

  1. For all families z,z′∈(Rd)Nz, z' \in (\mathbb{R}^d)^Nz,z′∈(Rd)N (not only those of the form WxWxWx) and every index iii:
gzi=∑j≠iαij (zj−zi′)+∑j≠iαji (zj−zi).g_{z_i} = \sum_{j \ne i}\alpha_{ij}\,(z_j - z_i') + \sum_{j\ne i}\alpha_{ji}\,(z_j - z_i).gzi​​=j=i∑​αij​(zj​−zi′​)+j=i∑​αji​(zj​−zi​).
  1. For all z,z′∈(Rd)Nz, z' \in (\mathbb{R}^d)^Nz,z′∈(Rd)N and every iii:
gzi′=∑j≠iαij (zi′−zi).g_{z_i'} = \sum_{j\ne i}\alpha_{ij}\,(z_i' - z_i).gzi′​​=j=i∑​αij​(zi′​−zi​).
  1. For all x,x′∈(Rn)Nx, x' \in (\mathbb{R}^n)^Nx,x′∈(Rn)N and all W∈Rd×nW \in \mathbb{R}^{d\times n}W∈Rd×n:
G=− WX.G = -\,W X.G=−WX.

Edge cases.

  • N=0N = 0N=0: there are no indices iii, so claims 1 and 2 hold vacuously. In claim 3, both GGG and XXX are empty sums, so both sides are the zero matrix.
  • N=1N = 1N=1: every sum over j≠ij \ne ij=i is empty. Claims 1 and 2 then assert that both gradients are the zero vector.
  • d=0d = 0d=0 or n=0n = 0n=0: the vectors or matrices involved have no entries.
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