NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Span-based Semantic Parsing for Compositional Generalization

Jonathan Herzig, Jonathan Berant

TL;DR

While sequence-to-sequence (seq2seq) models excel at standard semantic parsing, they struggle with compositional generalization—combining familiar words and concepts into novel, unseen program structures. This paper introduces SPANBASEDSP, a parser that enforces an explicit compositional inductive bias by predicting span-based parse trees over natural language utterances. Without needing gold trees during training, SPANBASEDSP dramatically closes the compositional generalization gap, improving average accuracy on compositional benchmarks from 61.0% to 88.9%.

What Problem Does This Paper Address?

Semantic parsing maps natural language utterances into executable formal programs (such as database queries or robot action commands). Modern approaches rely almost universally on seq2seq models, which generate programs token-by-token using soft attention to link the utterance to output symbols.

However, soft attention provides a weak inductive bias for compositionality. As a result, standard seq2seq models fail dramatically when evaluated on compositional splits—tests where all individual components (words, concepts, primitives) were seen during training, but appear in entirely new combinations or lengths at test time (e.g., training on "What states border China?" and "What is the largest state?" but testing on "What states border the largest state?").

Methods

Rather than relying on autoregressive token generation, the authors revive classical grammar-driven parsing using modern neural span representations. SPANBASEDSP works as follows:

  • Span Representation & Scoring: A BERT encoder derives contextual token embeddings. Every span $(i, j)$ is represented by concatenating its endpoint embeddings $[h_i; h_j]$ and passing them through a 1-hidden-layer MLP to score categories $c \in \mathcal{C}$ (domain constants $\Sigma$, a compositional join operation, or an empty category $\phi$).
  • Weak Supervision via Hard-EM: Unlike prior span-based parsers that require manual, gold-standard parse trees, SPANBASEDSP trains directly from utterance–program pairs $(x, z)$. During training, a constrained CKY search identifies the most probable latent tree that compiles to the gold program $z$, and the model parameters are updated using this tree as a target.
  • Constrained CKY Inference: At test time, an approximate $K$-best CKY parser finds the highest-scoring tree whose derived program satisfies domain-specific semantic type constraints (pruning semantically invalid programs).
  • Non-Projective Parsing: Natural language frequently separates predicates from their arguments (e.g., superlative expressions like "most" appearing between "State" and "people"). The authors extend standard binary CKY with a ternary rule (join := join join join), accommodating a major class of non-projective semantic structures while maintaining $O(n^4)$ complexity.
  • Lexicon Features: A small lexicon adds exact-match indicator features for entity names and basic domain predicates to ease weakly supervised latent-tree induction.

Datasets

The authors evaluate on both standard (I.I.D.) and compositional splits across three domains:

  1. GEOQUERY: 880 US geography queries in FunQL. Evaluated on the standard IID split, a TEMPLATE split (holding out unseen program templates), and a LENGTH split (testing on the longest queries).
  2. CLEVR & CLOSURE: CLEVR provides synthetic visual reasoning questions. CLOSURE tests compositional generalization by recombining referring expression types from CLEVR in seven new template combinations.
  3. SCAN-SP: Lake & Baroni's navigation command benchmark translated via a synchronous context-free grammar (SCFG) into executable semantic programs. Evaluated on the standard IID/SIMPLE split and the compositional RIGHT and AROUNDRIGHT splits.

Key Insights and Ideas

  • Explicit Structure vs. Soft Attention: Seq2seq models fail out-of-distribution because soft attention can spread probability mass arbitrarily across the input. Forcing the parser to bind sub-programs to discrete spans and assemble them bottom-up provides the structural inductive bias required for zero-shot compositional generalization.
  • Latent Trees Suffice: You do not need expensive, human-annotated span trees. Guided by execution-level program constraints, Hard-EM successfully recovers valid decomposition trees (matching semi-automatic gold trees with >90% $F_1$ on GEOQUERY and 100% on SCAN-SP).
  • Massive Sample Efficiency: On CLEVR/CLOSURE, SPANBASEDSP achieved near-perfect accuracy (98.8%) using only 10,000 training examples, compared to baseline models trained on 695,000 examples (70× more data) that still plateaued around 51–64%.

Key Results

Split / Benchmark Seq2Seq / Baseline Range SPANBASEDSP
CLOSURE (Test) 51.3% – 64.2% 98.8%
GEOQUERY: TEMPLATE (Test) 46.0% – 67.0% 82.2%
GEOQUERY: LENGTH (Test) 19.3% – 26.1% 63.6%
SCAN-SP: RIGHT / AROUNDRIGHT (Test) 0.0% – 95.3% 100% / 100%
All I.I.D. Splits Comparable Comparable

Across compositional splits, SPANBASEDSP jumped from a baseline average of 61.0% to 88.9% accuracy, while remaining fully competitive on standard in-distribution test sets.

Limitations and Future Work

  • Tight Alignment Requirement: The model assumes an explicit one-to-one correspondence between words/phrases and program constants. In domains like text-to-SQL where predicates are frequently implicit (e.g., inferring table joins or unstated columns), strict span-to-constant alignment breaks down.
  • Limited Non-Projectivity: While the ternary CKY extension covers common superlatives and split dependencies, it does not support arbitrary non-projective configurations. Fully general non-projective chart parsing would push time complexity up to $O(n^6)$, which is computationally intractable.
  • Future Directions: The authors suggest exploring methods to infuse this explicit compositional inductive bias directly into flexible autoregressive seq2seq models.

Summary updated

BibTeX
@inproceedings{herzig2021span,
  author = {Jonathan Herzig and Jonathan Berant},
  title = {{Span-based Semantic Parsing for Compositional Generalization}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2021},
  url = {https://openreview.net/forum?id=CBtS7FIPQvN},
}
Figure