Platonic JEPAs: finite world, positive-pair laws, JEPA objectives, spectral and alignment quantities
DefinitionPlatonicJEPA_BasicObjects of Section 2 and Appendix A.1 of Balestriero and LeCun (2026).
- World and positive pairs. A world is a finite set of states with probabilities , . A positive-pair law is a symmetric law on pairs of states whose marginals both equal .
- Embeddings and rotations. An embedding is , with . An orthogonal acts by . The law of the embeddings is .
- JEPA objective (eq. 1). For a prediction term and an anti-collapse term that depends on only through the law of its embeddings and may equal , . A modality that renders as trains an encoder on its observations with .
- Spectral JEPA (Proposition 1). is whitened if and . The prediction loss is , and a spectral minimiser minimises it among whitened embeddings.
- Spectrum. with and . Its eigenvalues are with multiplicity. The top space is the span of the eigenvectors of with eigenvalue at least . and are the spectral and Frobenius norms.
- Nuisance (Section 2.3). An observation of state carries a nuisance , drawn independently of . An encoder is written and is centred and whitened under . is the covariance of , and the scene-explained fraction is . A good-view JEPA's positive-pair law on observations is .
- Next-token prediction (eq. 6). For a context embedding and token vectors , and the loss is .
Formalization Note The eigenvalues are the roots of the characteristic polynomial of , sorted in decreasing order. The paper's convention is written in each statement as a hypothesis that applies only when . is the sum of the square roots of the eigenvalues of .
import Mathlib
/-!
Balestriero and LeCun, *Proving and Improving the Platonic Representation Hypothesis with JEPAs*,
arXiv:2610.39302v1 (2026): the finite world, positive-pair laws, JEPA objectives, spectral
quantities and alignment quantities of Section 2 and Appendix A.1.
-/
open MeasureTheory
noncomputable section
namespace PlatonicJEPA
variable {Z : Type*} [Fintype Z] [DecidableEq Z] {k : ℕ}
/-- Squared Euclidean norm of an embedding `v ∈ ℝ^k`. -/
def sqNorm (v : Fin k → ℝ) : ℝ := ∑ i, v i ^ 2
/-- Section 2.1: `p` is a probability on the finite world with `p(z) > 0`, and `π` is a symmetric
law on pairs of world states, both of whose marginals equal `p`. -/
def IsPairLaw (p : Z → ℝ) (π : Z → Z → ℝ) : Prop :=
(∀ z, 0 < p z) ∧ (∑ z, p z = 1) ∧ (∀ z z', 0 ≤ π z z') ∧ (∀ z z', π z z' = π z' z) ∧
(∀ z, ∑ z', π z z' = p z)
/-- The law of the embeddings `h(z)`, `z ∼ p`. -/
def embLaw (p : Z → ℝ) (h : Z → Fin k → ℝ) : Measure (Fin k → ℝ) :=
∑ z, ENNReal.ofReal (p z) • Measure.dirac (h z)
/-- Eq. (1) written on world states: `L_π(h) = E_{(z,z')∼π} ℓ(h z, h z') + Ω(h)`, where the
anti-collapse term `Ω` depends on `h` only through the law of its embeddings and may be `+∞`. -/
def worldLoss (p : Z → ℝ) (π : Z → Z → ℝ) (ℓ : (Fin k → ℝ) → (Fin k → ℝ) → ℝ)
(Ω : Measure (Fin k → ℝ) → EReal) (h : Z → Fin k → ℝ) : EReal :=
((∑ z, ∑ z', π z z' * ℓ (h z) (h z') : ℝ) : EReal) + Ω (embLaw p h)
/-- Eq. (1): the objective of a JEPA of a modality that renders state `z` as `g z`, for an
encoder `f` on that modality's observations. -/
def modalityLoss {X : Type*} (p : Z → ℝ) (π : Z → Z → ℝ) (ℓ : (Fin k → ℝ) → (Fin k → ℝ) → ℝ)
(Ω : Measure (Fin k → ℝ) → EReal) (g : Z → X) (f : X → Fin k → ℝ) : EReal :=
((∑ z, ∑ z', π z z' * ℓ (f (g z)) (f (g z')) : ℝ) : EReal) + Ω (embLaw p (f ∘ g))
/-- Rotation of an embedding by an orthogonal matrix. -/
def rot (Q : Matrix.orthogonalGroup (Fin k) ℝ) (v : Fin k → ℝ) : Fin k → ℝ :=
(Q : Matrix (Fin k) (Fin k) ℝ).mulVec v
/-- `h` is centred and whitened under `p`: `E_p h = 0`, `E_p h hᵀ = I_k`. -/
def IsWhitened (p : Z → ℝ) (h : Z → Fin k → ℝ) : Prop :=
(∀ i, ∑ z, p z * h z i = 0) ∧ (∀ i j, ∑ z, p z * h z i * h z j = if i = j then 1 else 0)
/-- The prediction term with `ℓ(a,b) = ‖a - b‖²`: `E_{(z,z')∼π} ‖h z - h z'‖²`. -/
def predLoss (π : Z → Z → ℝ) (h : Z → Fin k → ℝ) : ℝ :=
∑ z, ∑ z', π z z' * sqNorm (h z - h z')
/-- Proposition 1: `h` minimises `L_π` for `ℓ(a,b) = ‖a-b‖²` and `Ω` the whitening constraint. -/
def IsSpectralMin (p : Z → ℝ) (π : Z → Z → ℝ) (h : Z → Fin k → ℝ) : Prop :=
IsWhitened p h ∧ ∀ h' : Z → Fin k → ℝ, IsWhitened p h' → predLoss π h ≤ predLoss π h'
/-- The normalised adjacency `K_π = D^{-1/2} Π D^{-1/2}`. -/
def kerMat (p : Z → ℝ) (π : Z → Z → ℝ) : Matrix Z Z ℝ :=
fun z z' => π z z' / Real.sqrt (p z * p z')
/-- The eigenvalues `μ₀ ≥ μ₁ ≥ …` of `K_π`, with multiplicity, as the roots of its characteristic
polynomial sorted in decreasing order (`μ_i := 0` for `i ≥ |Z|`; statements never use those). -/
def eigs (p : Z → ℝ) (π : Z → Z → ℝ) (i : ℕ) : ℝ :=
((kerMat p π).charpoly.roots.sort (· ≥ ·)).getD i 0
/-- The span of the eigenvectors of `K_π` whose eigenvalue is at least `μ_k`. -/
def topSpace (p : Z → ℝ) (π : Z → Z → ℝ) (k : ℕ) : Submodule ℝ (Z → ℝ) :=
⨆ (μ : ℝ) (_ : eigs p π k ≤ μ), Module.End.eigenspace (Matrix.toLin' (kerMat p π)) μ
/-- Spectral (operator) norm of a real matrix. -/
def specNorm (A : Matrix Z Z ℝ) : ℝ :=
sSup ((fun v : Z → ℝ => Real.sqrt (∑ z, (A.mulVec v z) ^ 2)) '' {v | ∑ z, v z ^ 2 ≤ 1})
/-- Frobenius norm of a real matrix. -/
def frobNorm (A : Matrix Z Z ℝ) : ℝ := Real.sqrt (∑ z, ∑ z', A z z' ^ 2)
section Nuisance
variable {N : Type*} [Fintype N]
/-- Section 2.3: an encoder of observations `g(z, ν)`, written as `e z ν = f(g(z, ν))`, is centred and
whitened on its observations, whose law is `p(z) q(ν)`. -/
def IsWhitenedObs (p : Z → ℝ) (q : N → ℝ) (e : Z → N → Fin k → ℝ) : Prop :=
IsWhitened (fun x : Z × N => p x.1 * q x.2) (fun x => e x.1 x.2)
/-- `E[f(x) | z]` for an observation `x = g(z, ν)`, `ν ∼ q`. -/
def condMean (q : N → ℝ) (e : Z → N → Fin k → ℝ) (z : Z) : Fin k → ℝ :=
fun i => ∑ ν, q ν * e z ν i
/-- `C_f = Cov E[f(x) | z]` (the encoder is centred, so this is the second-moment matrix). -/
def stateCov (p : Z → ℝ) (q : N → ℝ) (e : Z → N → Fin k → ℝ) : Matrix (Fin k) (Fin k) ℝ :=
fun i j => ∑ z, p z * condMean q e z i * condMean q e z j
/-- The scene-explained fraction `ρ(f) = tr C_f^{1/2} / k`, computed from the eigenvalues of
`C_f` (the roots of its characteristic polynomial, with multiplicity). -/
def rho (p : Z → ℝ) (q : N → ℝ) (e : Z → N → Fin k → ℝ) : ℝ :=
(((stateCov p q e).charpoly.roots.map Real.sqrt).sum) / k
end Nuisance
/-- Proposition 3 (i): the positive-pair law of a good-view JEPA on observations `(z, ν)`:
`π(z, z') q(ν) q(ν')`. -/
def goodViewLaw {N : Type*} (π : Z → Z → ℝ) (q : N → ℝ) (x y : Z × N) : ℝ :=
π x.1 y.1 * q x.2 * q y.2
/-- Eq. (6): the anti-collapse term of next-token prediction, `A(h) = log ∑_v exp ⟨h, w_v⟩`. -/
def ntpAntiCollapse {V : Type*} [Fintype V] (w : V → Fin k → ℝ) (h : Fin k → ℝ) : ℝ :=
Real.log (∑ v, Real.exp (∑ i, h i * w v i))
/-- Eq. (6): the next-token loss `-⟨h, w_y⟩ + A(h)`. -/
def ntpLoss {V : Type*} [Fintype V] (w : V → Fin k → ℝ) (h : Fin k → ℝ) (y : V) : ℝ :=
-(∑ i, h i * w y i) + ntpAntiCollapse w h
end PlatonicJEPA
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Throughout, is an arbitrary finite type, possibly empty, with decidable equality. is a natural number, possibly . means real vectors indexed by . Functions and are arbitrary real-valued functions unless a declaration states otherwise. No positivity or normalisation is assumed implicitly.
sqNorm. For a vector ,
When the sum is empty and the value is .
IsPairLaw. For and , the predicate holds exactly when all five of the following hold:
- for every ;
- ;
- for all ;
- for all ;
- for every . This is the row-marginal condition; the column marginal then follows from symmetry.
Total mass is not stated separately but follows from conditions 2 and 5. If is empty, condition 2 fails, so the predicate can only hold when is nonempty.
embLaw. For and , is the measure on
where is the Dirac mass at .
- Negative values of are silently replaced by .
- Nothing requires to sum to , so this is a finite measure of total mass . It is a probability measure only when is a probability vector.
- If is empty it is the zero measure.
worldLoss. The inputs are:
- and , both arbitrary;
- an arbitrary real-valued function ;
- an arbitrary function from measures on to the extended reals ;
- .
The value is the extended real
The double sum is a finite real number. Adding it to gives when and when . No hypothesis is placed on , , or . In particular, may depend on the measure in any way, and need not be a pair law. sees only through the measure .
modalityLoss. The inputs are an arbitrary type , a map and a map , together with as in worldLoss. The value is
This is literally the same expression as worldLoss evaluated at . Again, no hypotheses are placed on any of the inputs.
rot. For a real orthogonal matrix (one with ) and , the value is the matrix–vector product .
IsWhitened. For and with coordinates , holds exactly when both of the following hold:
Points to note:
- is not required to be positive or to sum to ; the sums are taken with whatever weights provides.
- When both conditions are vacuous, so every is whitened.
- When everywhere, the conditions say that are orthonormal in the -weighted inner product and orthogonal to the constant function . This can only happen if ; for larger the predicate is unsatisfiable.
predLoss. For and ,
where is the sum of squared coordinates. It does not involve . Nothing is assumed about , so negative weights are allowed.
IsSpectralMin. For , and , holds exactly when both of the following hold:
- is whitened under in the sense of
IsWhitenedabove; - for every that is also whitened under ,
That is, attains the minimum of over the whitened maps. Points to note:
- No assumption is made that is a pair law.
- If no whitened map exists (for example and ), the predicate is false for every .
- If , every satisfies it.
kerMat. For and , this is the real matrix with entries
The conventions used are:
- the square root of a negative number is taken to be ;
- division by yields .
Consequently whenever . When this is , with and .
eigs. For , and an index (starting at ), is defined as follows:
- Take the characteristic polynomial of as a real polynomial.
- List its real roots with multiplicity.
- Sort them in non-increasing order.
- Return the -th entry, counting from . If is at least the length of this list, return .
Consequences of this definition:
- Only real roots are listed. If is not symmetric (for example if is not symmetric) and has non-real eigenvalues, those are omitted. The list is then shorter than , and from that shorter length onward.
- When is symmetric, the list has exactly entries: .
- The default value for out-of-range indices is indistinguishable from a genuine eigenvalue .
topSpace. For , and a natural number (this explicit argument is independent of the ambient ), is the subspace of obtained as follows:
- Let , acting on by matrix multiplication.
- For each real , let be the corresponding eigenspace, which is when is not an eigenvalue.
- Take the linear span of the union of these eigenspaces over all real with , where .
Points to note:
- With 0-based indexing, this is the span of eigenvectors for every real eigenvalue . That includes (i.e. listed values) and every further eigenvalue tied with .
- If is at least the length of the list of real eigenvalues, then . The space is then the span of all eigenvectors with nonnegative eigenvalue.
specNorm. For a real matrix ,
i.e. the operator norm of with respect to the Euclidean norm. The set is nonempty (it contains the value at ) and bounded, so this is an actual finite supremum. When is empty the value is .
frobNorm. For a real matrix ,
In the next five declarations, is an arbitrary finite type (a "nuisance" index set, possibly empty), is arbitrary, and has coordinates .
IsWhitenedObs. is IsWhitened applied on the product set , with weight and map . Explicitly, it holds exactly when both of the following hold:
Neither nor is required to be positive or normalised. When the predicate holds trivially.
condMean. For , and , this is the vector with coordinates
There is no division by . It is a conditional mean only when is a probability vector.
stateCov. For , and , this is the real matrix with entries
where is the condMean above. No mean is subtracted, so is the -weighted second-moment matrix of . is symmetric by construction, and it is positive semidefinite when .
rho. For , and ,
where the sum runs over the real roots of the characteristic polynomial of , counted with multiplicity. The conventions used are:
- for ;
- division by gives , so when .
Since is symmetric, it has real eigenvalues. When they are all nonnegative, and .
goodViewLaw. For an arbitrary type (not required to be finite here), , , and pairs , in , the value is
No properties of or are assumed.
ntpAntiCollapse. The inputs are an arbitrary finite type (possibly empty), vectors for , and . The value is
If is empty, the sum is and the value is , which is taken to be . Otherwise the sum is positive and this is the ordinary logarithm.
ntpLoss. For , and as in ntpAntiCollapse, and a token ,
The existence of forces to be nonempty, so the logarithm here is the ordinary one.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.