Norm of Mean Contextualized Embeddings Determines their Variance
Hiroaki Yamagiwa, Hidetoshi Shimodaira
TL;DR
This work investigates the distribution of contextualized embeddings in Transformer models by focusing on the three statistics $Q(X_t)$, $M(X_t)$, and $V(X_t)$ and proving the identity $Q(X_t) = M(X_t) + V(X_t)$. It introduces a sequential, memory-efficient method to compute these statistics for token-wise sets $X_t$, and demonstrates a strong trade-off between $M(X_t)$ and $V(X_t)$ across intermediate layers, likely shaped by Layer Normalization. The analysis is extended to the full embedding set $X$, with a variance decomposition $V(X) = V_W(X) + V_B(X)$ that reveals growing anisotropy as depth increases. Empirically, across BERT, RoBERTa, and GPT-2 on BookCorpus-derived data, the work shows that deeper layers push embeddings farther from the origin (larger $M(X)$) while reducing overall variance (smaller $V(X)$) and shifting within-/between-cluster variance, with LN placement explaining differences between Pre-LN and Post-LN architectures. Overall, the paper provides interpretable, scalable metrics for embedding distributions that illuminate how contextualized representations evolve with depth and architecture.
Abstract
Contextualized embeddings vary by context, even for the same token, and form a distribution in the embedding space. To analyze this distribution, we focus on the norm of the mean embedding and the variance of the embeddings. In this study, we first demonstrate that these values follow the well-known formula for variance in statistics and provide an efficient sequential computation method. Then, by observing embeddings from intermediate layers of several Transformer models, we found a strong trade-off relationship between the norm and the variance: as the mean embedding becomes closer to the origin, the variance increases. This trade-off is likely influenced by the layer normalization mechanism used in Transformer models. Furthermore, when the sets of token embeddings are treated as clusters, we show that the variance of the entire embedding set can theoretically be decomposed into the within-cluster variance and the between-cluster variance. We found experimentally that as the layers of Transformer models deepen, the embeddings move farther from the origin, the between-cluster variance relatively decreases, and the within-cluster variance relatively increases. These results are consistent with existing studies on the anisotropy of the embedding spaces across layers.
