Abstract
We propose an approach for semantic parsing that uses a recurrent neural network to map a natural language question into a logical form representation of a KB query. Building on recent work by (Wang et al., 2015), the interpretable logical forms, which are structured objects obeying certain constraints, are enumerated by an underlying grammar and are paired with their canonical realizations. In order to use sequence prediction, we need to sequentialize these logical forms. We compare three sequentializations: a direct linearization of the logical form, a linearization of the associated canonical realization, and a sequence consisting of derivation steps relative to the underlying grammar. We also show how grammatical constraints on the derivation sequence can easily be integrated inside the RNN-based sequential predictor. Our experiments show important improvements over previous results for the same dataset, and also demonstrate the advantage of incorporating the grammatical constraints.
Introduction
Semantic parsing is the task of converting a natural language utterance, such as "Which articles were published in 1950?", into a machine-readable logical form like a database query. While Recurrent Neural Networks (RNNs) have revolutionized sequence-to-sequence tasks like machine translation, semantic parsing presents a unique challenge: the output must be a structured object following strict grammatical rules. Standard RNNs often "hallucinate" logic that is syntactically invalid, containing errors like unbalanced parentheses or invalid variable types. This research explores bridging the gap between neural flexibility and logical rigidity by predicting derivation sequences within a grammar.
Methods: Sequentializing Logic
To apply sequence-to-sequence models to semantic parsing, the structured logical form (LF) must be converted into a sequence. The authors evaluate three distinct sequentialization strategies:
- Logical Form Prediction (LFP): Linearizing the logical form into a flat string of tokens.
- Canonical Form Prediction (CFP): Predicting a "canonical form"—a transparent, simplified English-like representation—which is then mapped back to logic via a grammar.
- Derivation Sequence Prediction (DSP): Instead of predicting the logic directly, the model predicts the sequence of grammar rules (derivation steps) used to construct that logic tree.
Grammatical Constraints (DSP-C)
The core innovation is the integration of grammatical constraints into the decoding process. In Constrained DSP (DSP-C), the model's choices at each step are masked based on the underlying grammar. If only specific rules are valid given the current derivation state, the model is restricted to those options. This ensures that the generated sequence always corresponds to a valid, executable logical form. The authors also explored DSP-CL (Constrained Loss), which incorporates these constraints during training by normalizing the probability distribution only over valid next steps.
Experimental Results
The models were evaluated on the Semantic Parser Overnight (SPO) benchmark, which includes seven distinct domains such as Basketball, Publication, and Housing. The sequence-based approach significantly outperformed the previous SPO baseline, with the DSP-C model reaching an average accuracy of 72.7% across all domains, compared to the original baseline of 57.1%.
As shown in the results, while unconstrained models (LFP, CFP, DSP) occasionally produced invalid logic with error rates as high as 11.8%, the constrained DSP-C model achieved a 0% grammatical error rate across all tested domains. Interestingly, the researchers found that applying constraints during inference (DSP-C) provided a larger performance boost than applying them during training (DSP-CL), suggesting that the model learns more effectively when exposed to the full difficulty of the task during training.
Conclusion and Future Work
Predicting derivation sequences rather than raw strings allows neural models to better capture the hierarchical nature of logic. By using a grammar as a hard constraint, the model is prevented from making structural errors. While this approach currently relies on a pre-defined grammar, future work could involve incorporating attention mechanisms to handle more complex inputs or exploring more sophisticated search strategies like beam search for larger logical forms.
Summary updated