Introduction
The rise of pre-trained Masked Language Models (MLMs) has fundamentally shifted the landscape of Natural Language Processing. However, the mechanisms by which these models—specifically Transformers like BERT and recurrent architectures like BiLSTMs—utilize context remain poorly understood. Traditional analysis often relies on architecture-specific probes, such as self-attention maps, which lack generalizability. This study introduces a model-agnostic "context perturbation" framework to quantify the quantity, distance, and quality of context utilized by MLMs.
Methodology
The researchers employ two primary methods to evaluate contextual impact:
- Context Perturbation: An architecture-agnostic "black-box" approach that iteratively masks context words causing the minimal change in a target word's probability. The process continues until the Negative Log Likelihood (NLL) exceeds a threshold (0.2), identifying the "used" context.
- Gradient-based IMPACT Score: A "glass-box" approach measuring the sensitivity of the output to subword embeddings via gradient norms.
To ensure comparability, both a BERT-base model and a 3-layer BiLSTM were trained from scratch on the same Wikipedia-book corpus using identical hyperparameters.
Contextual Quantity and Distance
A defining finding of this research is the stark contrast in how models perceive their surroundings. BERT acts as a "context glutton," leveraging approximately 75% of a sentence's available context. In contrast, BiLSTMs are "localists," utilizing only about 30%.
As shown in the figure above, BERT maintains high contextual relevance even for words located more than 20 positions away from the target. BiLSTM’s focus, however, decays rapidly beyond a narrow local window. This disparity suggests that BERT's architecture is significantly more effective at capturing long-range dependencies.
Robustness and Sentence Length
The models' efficiency also varies with sentence length. While BERT consistently utilizes ~75% of context regardless of length, BiLSTMs struggle as sentences grow longer, with their context usage dropping from 35% in short sentences to a mere 10% in long ones.
The NLL analysis reveals that BERT identifies roughly 35% of context as "essential"—meaning its removal causes a catastrophic drop in prediction accuracy. BiLSTM identifies only 20% as essential, suggesting that BERT builds more redundant and robust internal representations.
Linguistic Insights and Practical Applications
The study further reveals that both models align with linguistic intuition regarding word types: "content words" (nouns, verbs, adjectives) require significantly more context for accurate prediction than "function words" (determiners, adpositions). Interestingly, for determiners, both models exhibit a right-leaning bias, reflecting the head-initial structure of English noun phrases.
Beyond theoretical insights, these findings have practical implications for model efficiency. By implementing "attention pruning"—restricting BERT’s attention to its effective 78% window—the researchers achieved a ~39% reduction in self-attention computation. Crucially, this optimization resulted in negligible performance loss on downstream tasks like Named Entity Recognition (NER), maintaining an F1 score of 90.6 compared to the baseline 90.8.
Conclusion
This work provides a robust framework for understanding the "effective context window" of MLMs. By demonstrating that BERT's global perspective allows for significant pruning without performance loss, the study opens new avenues for developing more efficient, context-aware architectures. Future research will explore these dynamics in morphologically rich languages and more complex reasoning tasks.
Summary updated