How Contextual are Contextualized Word Representations? Comparing the Geometry of BERT, ELMo, and GPT-2 Embeddings
Kawin Ethayarajh
Reveals the geometric behavior of BERT, ELMo, and GPT-2 embeddings across layers, proving that upper layers generate more context-specific representations while static word vectors account for less than five percent of their variance.
Contextualized language models have dramatically improved modern language processing by generating word meanings based on surrounding text rather than relying on a single static representation. Despite their success, the internal geometry of these models remains poorly understood, leaving unanswered questions about how contextual these representations actually are and whether simpler static vectors could adequately replace them.
The article evaluates the geometry of word representation spaces across all layers of three leading neural models—ELMo, BERT, and GPT-2—to determine the degree of contextuality and assess whether static embeddings can replace contextual representations.
The analysis uses sentences from standard Semantic Textual Similarity datasets (2012–2016) to track words appearing in multiple distinct contexts. The evaluation measures how representations vary across contexts (self-similarity), how words relate to the overall sentence (intra-sentence similarity), and how much variation a single static vector can capture (maximum explainable variance), while adjusting for directional non-uniformity across the vector space.
The findings reveal four key insights. First, representations across all three models are highly anisotropic, meaning word vectors occupy a narrow directional cone rather than spreading uniformly across the vector space, with upper layers showing the most extreme clustering. Second, representations become increasingly context-specific in higher network layers; common words like stopwords exhibit the highest context-specificity due to appearing in diverse contexts. Third, models handle sentence context differently: words in the same sentence become more similar in ELMo's upper layers, become more distinct in BERT, and show virtually no added similarity over random words in GPT-2. Fourth, even in the best-case scenario, a static embedding explains less than 5% of the variance in a word's contextualized representations, proving that models do not simply select from a finite set of dictionary word senses.
These results provide a clear mathematical justification for why contextualized models consistently outperform older static techniques across language tasks. Although large neural models demand substantial memory, computational time, and hosting costs, replacing them entirely with standard static vectors causes significant performance loss. However, extracting static vectors from the principal components of lower layers in models like BERT outperforms traditional GloVe and FastText embeddings on standard benchmarks, providing a viable low-cost deployment option.
Organizations seeking lighter computational footprints should consider extracting static vectors from lower layers of transformer models when production environments cannot host full neural networks. In addition, model developers should explore adding penalties during model training to reduce directional narrowing and potentially boost accuracy. Further research is required to determine why different model architectures process sentence-level context in fundamentally distinct ways.
While the analysis provides robust conclusions based on diverse benchmark tasks, findings are constrained by the sentence datasets examined and focus specifically on base-level models. Practitioners should test these representations against their specific domain data when applying static extractions in production.
- Paper: Deep contextualized word representations, Matthew E. Peters et al. (2018). This paper introduces ELMo and foundational bidirectional contextualized word representations, which the source directly analyzes and compares against Transformer architectures.
- Paper: BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding, Jacob Devlin et al. (2019). This foundational paper presents BERT, whose internal representational geometry and layerwise contextualization are a central subject of the source's empirical investigation.
- Paper: Efficient Estimation of Word Representations in Vector Space, Tomáš Mikolov et al. (2013). This foundational work introduces static word embeddings (Word2Vec), providing the essential non-contextual baseline against which the source measures contextual variance and anisotropy.
- Paper: GloVe: Global Vectors for Word Representation, Jeffrey Pennington et al. (2014). This paper establishes GloVe static vector representations, which form a key point of comparison for evaluating the contextual richness and variance of deep language representations in the source.
- Paper: A Structural Probe for Finding Syntax in Word Representations, John Hewitt et al. (2019). This study introduces structural geometric probing of ELMo and BERT representation spaces, establishing mathematical methodologies for interpreting the geometry of contextual embeddings.
- Paper: BERT Rediscovers the Classical NLP Pipeline, Ian Tenney et al. (2019). This work extends the source's layerwise geometric insights by showing how BERT's hierarchical representations sequentially execute the classical NLP pipeline across successive layers.
- Paper: A Primer in BERTology: What We Know About How BERT Works, Anna Rogers et al. (2020). This comprehensive survey synthesizes findings on BERT's internal mechanics, incorporating geometric and layer-specific representation properties identified in the source.
- Paper: Understanding Contrastive Representation Learning through Alignment and Uniformity on the Hypersphere, Tongzhou Wang et al. (2020). This paper builds on representational geometry analyses like the source's anisotropy findings by formalizing the concepts of alignment and uniformity on hyperspherical representation spaces.
- Paper: SimCSE: Simple Contrastive Learning of Sentence Embeddings, Tianyu Gao et al. (2021). This work develops contrastive sentence representations (SimCSE) specifically to resolve representation collapse and anisotropic geometry identified in pre-trained encoders like BERT.
- Paper: Pre-trained models for natural language processing: A survey, Xipeng Qiu et al. (2020). This survey provides a broader taxonomy and analysis of pre-trained NLP models, drawing upon empirical evaluations of contextualization across different neural architectures.
- Paper: Quantifying Attention Flow in Transformers, Samira Abnar et al. (2020). This study deepens the investigation of layerwise representation mixing in Transformers by formalizing attention rollout and attention flow across network layers.
- Paper: Intrinsic Dimensionality Explains the Effectiveness of Language Model Fine-Tuning, Armen Aghajanyan et al. (2021). This paper investigates the geometric properties of fine-tuning pre-trained language models by analyzing intrinsic task dimensionality across learned contextual spaces.
