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

Unlocking Compositional Generalization in Pre-trained Models Using Intermediate Representations

Jonathan Herzig, Peter Shaw, Ming-Wei Chang, Kelvin Guu, Panupong Pasupat, Yuan ZhangarXiv 2021

Abstract

Sequence-to-sequence (seq2seq) models are prevalent in semantic parsing but struggle with out-of-distribution compositional generalization. While specialized architectures and pre-training have been proposed, they often sacrifice generality or show limited success. This paper investigates the impact of intermediate representations (IRs) on compositional generalization in pre-trained seq2seq models. By mapping natural language to reversible or lossy IRs that share stronger structural correspondence with the input, we "unlock" the latent knowledge in models like T5. This approach achieves new state-of-the-art results on CFQ (+14.8 accuracy points) and text-to-SQL datasets (+15.0 to +19.4 accuracy points) without changing the underlying model architecture.

Introduction

Semantic parsing—the translation of natural language into machine-executable code like SQL or SPARQL—is a cornerstone of modern AI interfaces. However, standard seq2seq models face a significant hurdle: compositional generalization. While these models excel when test data follows the same distribution as training data (i.i.d. splits), they often fail when asked to process novel combinations of known components.

The root cause is often a "structural mismatch." Formal languages contain syntactic boilerplate (e.g., table aliases, complex JOINs) that lacks direct correspondence in natural language. This noise hinders the model's ability to generalize linguistic patterns learned during pre-training to the rigid structure of formal code.

Methodology: Bridging the Structural Gap

The authors propose a two-stage decoding framework utilizing two distinct types of Intermediate Representations (IRs) to align formal outputs with natural language inputs.

Reversible Intermediate Representations (RIR)

RIRs are deterministic, rule-based transformations that reorganize formal code to mirror natural language structures. For instance, in SPARQL, RIRs might group related facts or use hierarchical bracketing to indicate scope. Since the transformation is reversible, the original executable code can be recovered perfectly without additional neural inference.

Lossy Intermediate Representations (LIR)

LIRs act as "sketches" that omit details not explicitly present in the natural language utterance, such as SQL FROM clauses. Because information is lost, a second seq2seq model is employed to take the original sentence and the LIR sketch to "fill in" the missing technical details, producing the final executable query.

The proposed workflows for Reversible (top) and Lossy (bottom) Intermediate Representations during training and testing.

By making the target output structurally similar to the input, the model can better leverage the linguistic patterns it acquired during its massive pre-training phase (e.g., T5).

Key Insights

  • Synergy with Pre-training: A critical finding is that IRs provide negligible benefits to models trained from scratch. However, when paired with pre-trained models, performance gains are massive. IRs serve as a "key" to unlock the model's pre-existing linguistic knowledge.
  • Structural Correspondence: The effectiveness of an IR is directly tied to how well it aligns with the natural language utterance. Removing elements that cannot be aligned to specific words reduces "structural noise" and improves generalization.

Experimental Results

The researchers evaluated their approach on benchmarks specifically designed for compositional generalization, including CFQ (SPARQL), Text-to-SQL (GEOQUERY, ATIS, SCHOLAR), and SCAN (action sequences).

Performance comparison between the baseline T5 model and the best IR configuration across i.i.d. and compositional splits.

The results demonstrate a dramatic "unlocking" effect:

  • CFQ: Achieved an improvement of +14.8 accuracy points over the previous state-of-the-art.
  • Text-to-SQL: Gains of +15.0 to +19.4 accuracy points on template-based splits.
  • SCAN: Reached 100% accuracy on several difficult splits by introducing hierarchical bracketing.
  • Robustness: These gains in compositional generalization did not degrade performance on standard i.i.d. tasks, maintaining high accuracy across the board.

Conclusion

This work highlights that intermediate representations are a powerful, yet often overlooked, degree of freedom for improving seq2seq models. By focusing on the structural alignment between natural and formal languages, we can significantly enhance the compositional reasoning of pre-trained models without the need for specialized architectures. Future work may involve automating the design of these representations or applying these principles to broader code generation tasks.

Summary updated

BibTeX
@misc{herzig2021unlocking,
  author = {Jonathan Herzig and Peter Shaw and Ming-Wei Chang and Kelvin Guu and Panupong Pasupat and Yuan Zhang},
  title = {{Unlocking Compositional Generalization in Pre-trained Models Using Intermediate Representations}},
  year = {2021},
  eprint = {2104.07478},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2104.07478},
}
Figure