From Balustrades to Pierre Vinken: Looking for Syntax in Transformer Self-Attentions

David Mareček, Rudolf Rosa

TL;DR

Researchers have discovered that Transformer encoders, trained solely for machine translation, naturally develop internal "balustrade" patterns in their self-attention heads that mirror syntactic phrases. By applying a simple, linguistically uninformed algorithm to these patterns, they successfully extracted constituency trees that significantly outperform random baselines, proving that these models learn fundamental syntax without being explicitly taught.

What Problem Does This Paper Address?

Modern deep learning models like the Transformer are often criticized as "black boxes." While they achieve state-of-the-art performance in tasks like Neural Machine Translation (NMT), it remains unclear whether they are learning human-like linguistic structures—such as syntax—or just exploiting complex statistical correlations.

Previous attempts to "peek inside" have often used "probes"—auxiliary classifiers trained to predict syntactic properties from a model's hidden states. However, this approach is controversial: does the probe reveal what the model knows, or is the probe itself learning syntax from the raw input features? This paper sidesteps that debate by looking for structures explicitly present in the attention weights themselves, without training any additional models.

Methods

The authors propose a transparent, deterministic method to quantify syntactic information in Transformer encoders:

  1. Visual Inspection: They first identified recurring patterns in attention heatmaps. The most striking was the "balustrade"—a series of vertical bars where a sequence of consecutive words (output states) all attend to the same single word (input state), often a punctuation mark or a head word.
  2. Tree Extraction Algorithm: To avoid confirmation bias, they developed a "linguistically uninformed" algorithm to build constituency trees:
  3. Hardening: They simplified the soft attention matrices by keeping only the maximum weight for each row.
  4. Phrase Identification: They identified "balusters" (sequences of states attending to one position) and treated them as candidate syntactic phrases.
  5. Weighting: Phrases were weighted based on their average attention intensity.
  6. CKY Parsing: They used the standard Cocke-Kasami-Younger (CKY) dynamic programming algorithm to find the highest-scoring binary constituency tree for a sentence based on these weights.
  7. Head Selection: Recognizing that not all attention heads are syntactic, they tested greedy "head addition" and "head ablation" strategies to identify the most syntactically informative heads.

Datasets

The study analyzed Transformer NMT encoders for three languages: English (en), French (fr), and German (de).

  • Training Data: The models were trained on the Europarl corpus, a large-scale multiparallel dataset of European Parliament proceedings.
  • Evaluation: 1,000 sentences from the evaluation set were used for tree extraction.
  • Gold Standard: The extracted trees were compared against "parse trees" generated by the Stanford Parser, which was trained on standard constituency treebanks (Penn Treebank for English, Negra for German, and the French Treebank).

Key Insights and Ideas

  • Balustrades as Constituents: The core "aha moment" is that the vertical bars in attention matrices (balustrades) frequently span sequences of words that humans recognize as syntactic phrases (e.g., a noun and its determiner).

    Example of a balustrade pattern in Layer 4, Head 2, where sequences of words attend to specific punctuation or head words.
  • Layer-wise Specialization: Syntax isn't evenly distributed. The first layer is dominated by simple diagonal patterns (passing information directly up), while the final layers (5 and 6) contain the most varied and complex balustrades, suggesting they handle higher-level syntactic grouping.

  • Implicit Learning: The model is never given a grammar book. It develops these syntactic representations purely as a byproduct of learning how to translate one language into another.

Key Results

The quantitative results confirm that the attention heads capture significant syntactic structure:

  • Outperforming Baselines: The extracted trees achieved F1 scores 6 to 13 percentage points higher than strong baselines like balanced binary trees. For example, the de → fr model reached an F1 of 43.6% compared to a 34.8% baseline.
  • Syntactic Head Subselection: By selecting only the most "syntactic" heads, F1 scores improved by an additional 3 to 10 percentage points.
  • Qualitative Success: Manual inspection of the generated trees (like the one in Figure 3 of the paper) showed that many subtrees make perfect syntactic sense, such as correctly grouping "have been damaged" or large noun phrases.

Limitations and Future Work

  • Formalism Bias: The evaluation is limited by how well the model's internal "syntax" matches the specific annotation style of the gold-standard treebanks. For instance, English scores were lower partly because the Penn Treebank is heavily right-branching, while the model's extracted trees were flatter and more balanced.
  • Translation-Specific Syntax: The model is optimized for translation, not parsing. It likely only captures syntactic structures that are useful for moving between specific language pairs.
  • Overlapping Structures: The authors noted that certain words (like punctuation) seem to belong to multiple neighboring phrases simultaneously. They suggest that future work should explore formalisms that allow for partially overlapping phrases rather than strict nested trees.

Summary updated

Abstract

We inspect the multi-head self-attention in Transformer NMT encoders for three source languages, looking for patterns that could have a syntactic interpretation. In many of the attention heads, we frequently find sequences of consecutive states attending to the same position, which resemble syntactic phrases. We propose a transparent deterministic method of quantifying the amount of syntactic information present in the self-attentions, based on automatically building and evaluating phrase-structure trees from the phrase-like sequences. We compare the resulting trees to existing constituency treebanks, both manually and by computing precision and recall.
BibTeX
@inproceedings{marecek2019from,
  author = {David Mareček and Rudolf Rosa},
  title = {{From Balustrades to Pierre Vinken: Looking for Syntax in Transformer Self-Attentions}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2019},
}
Figure