Spying on your neighbors: Fine-grained probing of contextual embeddings for information about surrounding words

Josef Klafka, Allyson Ettinger

Introduction

Contextual word embeddings, such as those produced by BERT, ELMo, and GPT, have revolutionized natural language processing by providing dynamic vector representations that change based on surrounding text. However, the specific nature of the information these embeddings capture about their neighbors remains an open question. For instance, in the sentence "The lawyer questioned the judge," does the embedding for "questioned" explicitly encode the gender of the "lawyer" or the animacy of the "judge"?

This paper introduces a suite of fine-grained probing tasks designed to map the precise distribution of syntactic and semantic features across sentence tokens. By examining how models distribute information like tense, animacy, and gender, the authors reveal fundamental differences in how transformer and recurrent architectures handle context.

Probing Methodology

The authors employ classification-based probing to investigate the internal representations of these models. A multi-layer perceptron (MLP) is trained on the contextual embedding of a "probed word" to predict a specific linguistic feature of a "target word."

To ensure clarity and isolate variables, the study utilizes a novel dataset of controlled 5-word transitive sentences following the structure: DET SUBJ-N VB DET OBJ-N. This fixed structure prevents models from relying on structural variance. The probing tasks target specific features for nouns (Number, Gender, and Animacy) and verbs (Tense, Causative-inchoative alternation, and Dynamic-stative properties).

Table 1: Examples of the probing tasks and their corresponding labels for subject features.

The researchers implemented strict baselines using GloVe (static embeddings) to confirm that the tasks require contextual information. Additionally, they controlled for surface-level morphological clues—for example, using past-tense verbs when probing for subject number to ensure the verb's spelling does not reveal the answer.

Results and Analysis

The findings highlight significant differences in how models distribute contextual information based on their architecture and training objectives.

Directionality and Selectivity

Directionality plays a crucial role in information distribution. GPT, a unidirectional (left-to-right) model, tends to "smear" subject information uniformly across all subsequent tokens. Interestingly, it captures very little about the object noun, even within the object noun's own embedding, suggesting a strong bias toward earlier context.

In contrast, bidirectional models like BERT and ELMo exhibit "nuanced selectivity." While BERT strongly encodes a subject's number and animacy across the entire sentence, it appears to actively drop subject gender information on surrounding tokens, recovering it at only ~75% accuracy compared to near 100% for other features.

Figure 1: Probing accuracy for subject features (Number, Gender, Animacy) across different words in the sentence. Note the drop in gender accuracy for BERT on non-subject tokens.

Features vs. Identity

A key insight is that models prioritize abstract linguistic features over exact word identity. On a 30-way classification task to identify a specific neighboring word, performance was significantly lower than on binary feature classification. This suggests that contextual embeddings learn useful abstractions rather than simple local vocabulary memorization.

Robustness to Distance

The study also tested the impact of linear distance by inserting relative clauses. Transformer-based models (BERT and GPT) proved remarkably robust, maintaining high accuracy for subject features even when the physical distance between the subject and the probed word increased. ELMo, however, showed a marked decrease in performance, indicating that transformers are better at leveraging syntactic awareness over long distances than traditional recurrent models.

Conclusion

This fine-grained analysis demonstrates that contextual embeddings are not just "bags of context" but structured representations that selectively distribute information. While all models richly encode neighbor features, their strategies differ: GPT prioritizes preceding context, while bidirectional transformers like BERT show sophisticated feature-specific selectivity and superior robustness to distance. Future work may extend these probes to more complex, naturalistic text and a wider variety of syntactic relationships.

Summary updated

BibTeX
@inproceedings{klafka2020spying,
  author = {Josef Klafka and Allyson Ettinger},
  title = {{Spying on your neighbors: Fine-grained probing of contextual embeddings for information about surrounding words}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2020},
  url = {https://openreview.net/forum?id=Oz8zIuoJsW5},
}
Figure