Two independent random unit vectors in have an expected dot product of and an expected squared dot product of . EmbeddingGemma's spread-out regularizer (the global orthogonal regularizer) penalizes a batch whose embeddings are more similar to each other than random vectors would be, so that the embedding space stays usable under truncation and quantization. Implement the moments and the loss. Rows are L2-normalized before anything else.
first_moment(E)
(B, d) batch, rounded to 4 decimals.second_moment(E)
spread_out_loss(E, second_only=True)
second_only is False (the original GOR). Rounded to 4 decimals.spread_out_pair_loss(Q, P)
spread_out_loss(Q) + spread_out_loss(P), the two groups regularized separately, rounded to 4 decimals.En @ En.T holds every pair; remove the diagonal before averaging over B * (B - 1) entries.0.0 for every moment.