Improving Grammar-based Sequence-to-Sequence Modeling with Decomposition and Constraints

Chao Lou, Kewei Tu

Introduction

While standard neural sequence-to-sequence (seq2seq) models like Transformers have revolutionized natural language processing, they often struggle with compositional generalization. This is the ability to generalize to novel combinations of known components—for instance, understanding "run twice" if the model already knows "run" and "jump twice." This limitation stems from a lack of strong inductive bias for the hierarchical, tree-like structure inherent in language.

Grammar-based models, such as Neural Quasi-Synchronous Context-Free Grammars (Neural QCFG), address this by explicitly modeling alignments between source and target parse trees. However, these models face a significant "computational tax." Inference time complexity is a staggering $O(|N|^3 S^3 T^3)$, where $N$ is the number of nonterminals and $S, T$ are sequence lengths. This extreme complexity limits the number of nonterminal symbols the model can utilize, restricting its expressiveness and scalability.

Low-Rank Grammar Architectures

To overcome these bottlenecks, this work introduces two low-rank variants of Neural QCFG using tensor rank decomposition. These models decompose binary grammar rules into independent components, significantly reducing computational overhead.

Comparison of the proposed (a) E model and (b) P model architectures.
  1. The E Model (Efficient): This variant decomposes binary rules into three independent parts, separating the symbols entirely. This allows for "rank-space dynamic programming," achieving a much lower $O(T^3)$ complexity. However, this independence means it cannot easily enforce constraints that require simultaneous consideration of all nodes in a rule.
  2. The P Model (Expressive): This model serves as a middle ground. It preserves the relationship between source tree nodes while decomposing the grammar symbols. While slower than the E model, it remains significantly faster than the vanilla version and allows for the implementation of complex structural constraints.

Soft Constraints for Structural Guidance

Beyond architectural changes, the paper proposes two soft constraints to improve modeling accuracy:

  • Soft Tree Hierarchy: Rather than using rigid "hard" rules for parent-child relationships in the source tree, this approach uses a reward function. It favors smaller distances between nodes in the tree hierarchy, providing flexibility while maintaining structural guidance.
  • Coverage Constraint: Implemented via posterior regularization, this constraint biases the model to ensure that most nodes in the source tree are translated. This prevents common seq2seq issues like ignoring input segments or over-translating specific words.

Efficiency and Scalability

The primary advantage of these low-rank models is their ability to scale. By reducing memory and time requirements, they can support a much larger number of nonterminal symbols. On a 24GB GPU, the vanilla model is limited to 18 nonterminals, whereas the P model can handle 64 and the E model can handle 128.

Inference time complexity comparison between vanilla Neural QCFG (vNQ2) and the proposed low-rank models.

As shown in the figure above, the empirical time complexity of the vanilla model (vNQ2) grows at $O(x^6)$, while the P model grows at $O(x^5)$ and the E model at $O(x^3)$. This drastic reduction enables the use of grammar-based models on longer sequences and with larger symbol sets.

Experimental Results

The models were evaluated on the SCAN benchmark for compositional generalization, StylePTB for text style transfer, and a small-scale English-to-French translation task.

  • Compositional Generalization: The P model achieved near-perfect accuracy (91%–97%) on SCAN splits, matching the vanilla model's performance with much higher efficiency. The E model struggled here, highlighting the importance of the structural relationships it sacrifices for speed.
  • Style Transfer: On the Active-to-Passive (ATP) task, the P model (with coverage constraints) achieved a BLEU-4 score of 75.44, significantly outperforming the vanilla model's 66.2.
  • Symbol Scaling: A key finding was that increasing the number of nonterminals directly correlates with improved performance. The low-rank models' ability to use 4x to 7x more symbols is a major driver of their success.

Conclusion and Future Work

This research demonstrates that tensor rank decomposition can effectively mitigate the computational challenges of grammar-based seq2seq models. While the P model offers a superior balance of efficiency and expressiveness, the E model provides a highly scalable alternative for tasks where strict structural constraints are less critical.

Future work may address the limitations of the context-free assumption and the requirement for Chomsky Normal Form. Integrating these low-rank grammar techniques with more powerful architectures, such as RNNGs or Transformer Grammars, could further enhance their ability to model complex linguistic dependencies.

Summary updated

BibTeX
@inproceedings{lou2023improving,
  author = {Chao Lou and Kewei Tu},
  title = {{Improving Grammar-based Sequence-to-Sequence Modeling with Decomposition and Constraints}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-short.163},
}
Figure