On Robustness of Prompt-based Semantic Parsing with Large Pre-trained Language Model: An Empirical Study on Codex

Terry Yue Zhuo, Zhuang Li, Yujin Huang, Fatemeh Shiri, Weiqing Wang, Gholamreza Haffari, Yuan-Fang Li

Introduction

Semantic parsing—the process of translating natural language (NL) queries into machine-executable logical forms like SQL—has traditionally relied on supervised fine-tuning on large, domain-specific datasets. The emergence of Large Language Models (LLMs) like Codex has shifted this paradigm toward in-context learning, where models perform tasks based on a few-shot prompt without parameter updates.

However, the robustness of these prompt-based parsers remains a critical concern. While traditional neural networks are known to be brittle to minor input variations, the scale and frozen nature of LLMs present unique challenges for robustness evaluation and mitigation. This study investigates the resilience of Codex (code-davinci-002) against adversarial perturbations and explores strategies to enhance its robustness through prompt engineering.

Methodology

The researchers evaluated Codex's performance under seven distinct types of adversarial attacks, categorized into word-level and sentence-level perturbations. Word-level attacks included introducing typos, deleting random words, swapping word positions, and synonym substitution. Sentence-level attacks involved paraphrasing the entire query or appending distracting, irrelevant phrases.

Examples of word-level and sentence-level adversarial perturbations.

To mitigate these vulnerabilities, three primary strategies were explored:

  1. Scaling In-Context Learning: Increasing the number of few-shot examples (up to 50) to provide the model with more context.
  2. Adversarial In-Context Learning: Incorporating perturbed examples directly into the prompt to demonstrate how the model should handle noise.
  3. Strategic Sampling: Moving beyond random selection to use diversity-based (clustering) and perplexity-based sampling methods for selecting few-shot examples.

Experimental Setup

The study utilized two benchmark datasets: GeoQuery (877 US geography questions) and Scholar (academic publication queries). To ensure a rigorous evaluation of generalization, the authors employed "query splits," where SQL templates in the test set do not overlap with those in the training set. This prevents the model from succeeding through simple pattern memorization.

Results and Discussion

The Vulnerability of Sentence-Level Context

A primary finding of the study is that Codex is significantly more vulnerable to sentence-level changes than word-level ones. While the model shows relative resilience to typos and minor word swaps, its accuracy drops precipitously when the input is paraphrased.

Performance degradation of Codex under various perturbation strategies.

As shown in Figure 2, sentence-level perturbations (RB) caused a 25.27% drop in accuracy on GeoQuery and a 6.99% drop on Scholar. This suggests that the model's "understanding" is heavily tied to specific linguistic patterns rather than the underlying semantic intent.

Adversarial Prompting vs. Adversarial Training

In traditional machine learning, adversarial training—including "broken" examples in the training set—is a standard defense. However, the researchers found that "Adversarial In-Context Learning" (showing the model attacked examples in the prompt) yielded only marginal improvements. Unlike fine-tuning, simply presenting a few noisy examples does not appear to teach the model the robust logic required to overcome adversarial pressure.

Complexity as a Proxy for Robustness

One of the most significant insights is the correlation between the linguistic complexity of the few-shot examples and the model's eventual robustness. By selecting examples with high lexical diversity (measured by metrics like Type-Token Ratio), the researchers were able to significantly boost Codex's resilience. For instance, using Cluster-TF-IDF sampling—which prioritizes diverse and representative examples—resulted in a robust accuracy of 85.10% on GeoQuery, far exceeding the 73.22% achieved with random sampling.

Conclusion

This empirical study highlights that while LLMs like Codex are powerful semantic parsers, they remain fragile to sentence-level linguistic variations. Importantly, the research demonstrates that robustness can be improved without the need for computationally expensive retraining. By scaling the number of examples and, more crucially, selecting examples with high linguistic complexity and diversity, practitioners can build more resilient prompt-based systems. Future work remains to explore these effects in other logical forms and across a broader range of LLM architectures.

Summary updated

BibTeX
@inproceedings{zhuo2023robustness,
  author = {Terry Yue Zhuo and Zhuang Li and Yujin Huang and Fatemeh Shiri and Weiqing Wang and Gholamreza Haffari and Yuan-Fang Li},
  title = {{On Robustness of Prompt-based Semantic Parsing with Large Pre-trained Language Model: An Empirical Study on Codex}},
  booktitle = {EACL},
  year = {2023},
  doi = {10.18653/v1/2023.eacl-main.77},
}
Figure