Attention Understands Semantic Relations

Anastasia Chizhikova, Sanzhar Murzakhmetov, Oleg Serikov, Tatiana Shavrina, Mikhail BurtsevLREC 2022

Introduction

Large Language Models (LLMs) are frequently characterized as "black boxes" that might rely on pattern memorization rather than a deep understanding of underlying concepts. While previous "probing" studies have demonstrated that these models capture grammatical structures effectively, their grasp of semantic and factual knowledge has remained less clear. This research addresses this gap by investigating whether internal self-attention weights—the scores determining word focus during processing—actually encode the relationships between entities, such as identifying that "Paris" is the "capital" of "France."

Methodology

The researchers developed an intentionally simple and interpretable Relation Extraction (RE) pipeline to probe a pre-trained BERT model. The process involves three main stages:

  1. Candidate Selection: Basic linguistic rules (Part-of-Speech tagging) are used to identify potential triplets consisting of a head entity, a tail entity, and a relation word (e.g., "Moscow" [head], "Russia" [tail], "capital" [rel]).
  2. Attention Vectorization: For every candidate triplet, attention weights are extracted between all three components across all 12 layers and 12 heads of BERT. This creates a feature vector representing the model's internal relational mapping of these words.
  3. Classification: Two simple Logistic Regression classifiers are trained on these attention vectors: a Binary Classifier to detect the existence of a semantic relation, and a Multiclass Classifier to identify the specific type of relation based on WikiData properties.
Overview of the proposed relation classification pipeline based on attention weights.

By utilizing simple classifiers on top of raw attention scores, any success in extracting relations can be directly attributed to the information already present within BERT's attention maps.

Datasets

The study leverages three primary resources:

  • WikiData: A massive knowledge base used to define semantic relations.
  • T-REx: A dataset of 11 million WikiData triplets aligned with Wikipedia abstracts, used for training and balanced evaluation.
  • DocREd: A document-level relation extraction dataset used to test performance on complex, human-annotated text.

Discussion and Insights

  • Semantic Awareness in Attention: Attention scores alone provide sufficient information to identify semantic relations with high accuracy. This supports the hypothesis that transformers construct internal "knowledge graphs" during pre-training.
  • The Role of the "Relation" Token: The study found that attention involving the explicit relation word (the "rel" token) is critical for disambiguation. For instance, without the word "mother" or "father," a model might struggle to distinguish between different family relations based solely on entity names.
  • Layer-wise Distribution: Knowledge is not localized in a single layer. Probing revealed that middle layers (specifically layers 4 and 10) are significantly more informative for semantic tasks than the initial or final layers.
  • Semantic Clustering: Analysis of attention heads revealed that BERT naturally groups similar concepts. Relations like "place of birth" and "place of death" exhibit similar attention patterns, forming clusters that align with human interpretation.

Experimental Results

The probing experiments provided strong quantitative evidence of BERT's semantic awareness:

  • Selectivity: The pre-trained BERT model achieved a binary classification accuracy of 0.902, significantly outperforming a randomly initialized version (0.498). This confirms that the knowledge is acquired during pre-training.
  • Relation Identification: The multiclass classifier reached an F1-score of 0.863 using BERT's attention, vastly exceeding the random baseline of 0.018.
  • Comparative Performance: On the T-REx dataset, this "naive" attention-based method outperformed REBEL, a more complex state-of-the-art model, primarily due to its superior handling of pronouns.
F1-score for multiclass relation prediction across varying numbers of classes.

Conclusion and Future Work

While the results are promising, the authors identify several challenges:

  • Over-generation: The pipeline's exhaustive candidate generation leads to many false positives on uncurated text as the number of potential triplets grows exponentially with sentence length.
  • Dataset Noise: Existing RE datasets often contain "precision and recall flaws," meaning ground truth labels are not always perfect.
  • Syntactic Nuance: The specific role of syntax in these semantic relations requires further study. Future research aims to integrate unsupervised methods to reduce reliance on manual candidate filtering.

Summary updated

BibTeX
@inproceedings{chizhikova2022attention,
  author = {Anastasia Chizhikova and Sanzhar Murzakhmetov and Oleg Serikov and Tatiana Shavrina and Mikhail Burtsev},
  title = {{Attention Understands Semantic Relations}},
  booktitle = {LREC},
  year = {2022},
}
Figure