Transformer Grammars: Augmenting Transformer Language Models with Syntactic Inductive Biases at Scale

Laurent Sartran, Samuel Barrett, Adhiguna Kuncoro, Miloš Stanojević, Phil Blunsom, Chris Dyer · DOI

TL;DR

Transformer Grammars (TGs) introduce a recursive syntactic inductive bias into the Transformer architecture using a novel attention masking mechanism. While significantly smaller than industry giants like GPT-2 or Chinchilla, TGs achieve superior syntactic generalization and sentence-level modeling, though they reveal a surprising bottleneck when processing long-form documents.

What Problem Does This Paper Address?

For decades, linguistic research has argued that hierarchical syntactic structures are essential for human-like language generalization. However, modern Transformer-based Large Language Models (LLMs) have achieved massive success without any explicit modeling of these structures. This raises a fundamental question: Does explicit syntax still matter at scale?

Previous attempts to build "syntactic" models, like Recurrent Neural Network Grammars (RNNGs), were difficult to scale due to their reliance on LSTMs. The authors aim to bridge this gap by bringing the benefits of recursive syntactic composition—the process of building phrase representations from their parts—into the scalable and powerful Transformer-XL framework.

Methods

The core innovation is the Transformer Grammar (TG). It treats language modeling as a joint task of predicting both words ($x$) and their phrase-structure trees ($y$).

  1. Linearization: The model represents a tree as a sequence of actions: opening a non-terminal (e.g., a Noun Phrase), generating words, and closing the constituent.
  2. STACK and COMPOSE Attention: TGs implement recursive composition through a custom attention mask.
  3. STACK attention restricts the model to attend only to elements currently "active" in the syntactic stack.
  4. COMPOSE attention triggers when a constituent ends; the model attends to all children of that constituent to create a single, "composed" vector representation.
  5. The Bottleneck: Once a phrase is composed, subsequent words can only "see" the phrase through this single vector, not the individual words inside it. This forces the model to learn highly informative, compressed representations of syntactic subtrees.
Figure 1: An example that represents a pair of string x and its phrase-structure tree y, which are then represented as a sequence of actions that con- struct (x, y) in a top-down, left-to-right fashion (Dyer et al., 2016; Choe and Charniak, 2016).

To keep the model efficient, the authors duplicate closing non-terminals in the input sequence so that both COMPOSE and STACK operations can be performed in a single parallel pass during training.

Datasets

The models were trained and evaluated on:

  • Penn Treebank (PTB): A small-scale standard (approx. 1M words).
  • BLLIP-LG: A medium-scale dataset (approx. 40M words).
  • Hu et al. (2020) Syntactic Generalization (SG) Benchmark: A suite of 31 test cases designed to probe specific linguistic phenomena like subject-verb agreement and long-distance dependencies.

Key Insights and Ideas

  • Syntax vs. Scale: TGs demonstrate that inductive bias can be more powerful than raw scale for certain tasks. A TG model with 252M parameters outperformed models like Gopher (280B) and Chinchilla (70B) on syntactic generalization benchmarks, despite being roughly 1,000x smaller.
  • The Document-Level Bottleneck: While recursive composition helps with sentence structure, it actually hurts document-level perplexity. The "bottleneck" that forces a sentence into a single vector prevents the model from using simple "lexical copying" (remembering a specific word from three sentences ago), which is a key trick standard LLMs use to model long text.
  • Dissociation of Metrics: The paper finds a partial dissociation between perplexity (how well a model predicts the next word) and syntactic competence. A model can be slightly "worse" at predicting the next word overall while being much "better" at understanding underlying grammar.

Key Results

The authors compared TGs against standard Transformer-XL (TXL) baselines and prior syntactic models.

Model PTB Perplexity (↓) BLLIP SG Score (↑) PTB $F_1$ (↑)
TG 61.8 82.5 93.7
TXL (trees) 61.2 80.2 93.6
TXL (terminals) 62.6 69.5 n/a
Chinchilla (70B) n/a 79.7 n/a

Data from Table 1 (id: art_9312d9042a8d4bafaee9092473124710)

  • Syntactic Generalization: TGs achieved the highest SG scores, significantly outperforming terminal-only Transformers and even massive non-syntactic LLMs.
  • Parse Reranking: TGs set a new bar for accuracy in reranking candidate parses on the Penn Treebank.
  • Speed: By using the Transformer architecture, TGs are much faster to train than previous batched RNNG implementations.

Limitations and Future Work

  • Document Modeling: The current recursive composition mechanism is too restrictive for long-form text. Future work needs to find a way to balance syntactic structure with a more flexible memory that allows for word-level "priming" across sentence boundaries.
  • Inference Complexity: Calculating exact string probabilities $p(x)$ requires marginalizing over possible trees, which is computationally expensive. The authors currently use a "proposal model" to approximate this, but more efficient methods are needed.
  • Scaling to Billions: While TGs scale better than RNNGs, they haven't yet been tested at the multi-billion parameter scale where emergent properties of LLMs typically appear.

Summary updated

BibTeX
@article{sartran2022transformer,
  author = {Laurent Sartran and Samuel Barrett and Adhiguna Kuncoro and Miloš Stanojević and Phil Blunsom and Chris Dyer},
  title = {{Transformer Grammars: Augmenting Transformer Language Models with Syntactic Inductive Biases at Scale}},
  journal = {Trans. Assoc. Comput. Linguistics},
  year = {2022},
  doi = {10.1162/tacl\_a\_00526},
}
Figure