Introduction
Semantic parsing—the process of translating natural language (NL) queries into machine-executable code or logical forms—is a fundamental component of modern data interfaces. Traditionally, this task required specialized architectures trained on extensive human-annotated datasets. The advent of Large Language Models (LLMs) like Codex has introduced a paradigm shift toward "prompt-based" semantic parsing. In this setup, the model performs in-context learning, leveraging a few examples provided in the prompt to generate SQL or logical forms without requiring explicit weight updates.
Despite the impressive performance of LLMs, neural models are historically sensitive to minor input variations. This study investigates the adversarial robustness of Codex (specifically code-davinci-002) in the context of semantic parsing. The researchers explore whether these models are fragile when faced with text perturbations and evaluate strategies to mitigate such vulnerabilities without the need for expensive retraining.
Evaluation Framework
The authors developed a systematic framework to assess Codex's resilience across two benchmark datasets: GeoQuery (877 geography-related questions) and Scholar (816 academic publication queries). To ensure the model was not simply memorizing templates, the study utilized "query-split" versions of these datasets.
Adversarial Attacks
The study implemented seven distinct types of perturbations categorized into two levels:
- Word-level Attacks: These included character-level typos, random word deletions, random swaps, and context-aware substitutions or insertions.
- Sentence-level Attacks: These involved more sophisticated transformations, such as paraphrasing the entire query using tools like Quillbot or adding "distraction" phrases (e.g., "I want to know...") to the input.
Performance Metrics
To quantify robustness, the researchers employed three primary metrics:
- Standard Accuracy: Performance on the original, clean test set.
- Perturbation Accuracy: Performance on the modified (attacked) test set.
- Robust Accuracy: The percentage of instances where the model correctly parsed both the original and the perturbed version of a query.
Vulnerability Analysis
The empirical results reveal a significant disparity in how Codex handles different types of noise. While the model demonstrated relative resilience to word-level perturbations (like typos), it proved highly vulnerable to sentence-level changes.
In a zero-shot setting on the GeoQuery dataset, a rewriting attack led to a 25.27% drop in accuracy compared to the standard test set. This suggests that while Codex can overlook minor character noise, it struggles with the linguistic variance introduced by paraphrasing and the inclusion of irrelevant "distractor" phrases. This vulnerability indicates that the model's understanding of intent can be easily derailed by structural changes in natural language.
Defense Strategies and In-Context Learning
A core contribution of this research is the evaluation of defense mechanisms that do not require model fine-tuning.
Scaling In-Context Examples
One of the most effective defenses was simply increasing the number of examples (shots) provided in the prompt. On GeoQuery, increasing the prompt from 5-shot to 50-shot improved the Average Robust Accuracy from 75.67% to 83.22%. This suggests that providing more context helps the model build a more stable mapping between NL and logical forms, effectively "smoothing" its decision boundaries through increased data exposure.
Example Selection and Diversity
The method used to select these examples proved critical. The researchers compared several sampling strategies:
- Random Sampling: Picking examples at random.
- Perplexity-based Sampling: Selecting examples based on model confidence.
- Cluster-TF-IDF (Diversity-based): Selecting a diverse set of examples characterized by high lexical complexity and varied structures.
The Cluster-TF-IDF approach significantly outperformed others, achieving a Robust Accuracy of 85.10% on GeoQuery, compared to just 73.22% for random sampling and 50.82% for perplexity-based sampling. This highlights that exposure to a diverse and complex set of "demonstrations" is more beneficial for robustness than simply providing "easy" or high-confidence examples.
Adversarial Prompting
Interestingly, the study found that "adversarial prompting"—including perturbed examples directly in the prompt—was not as effective as it is in traditional supervised learning. This strategy provided only marginal gains and, in some instances, degraded standard accuracy, suggesting that LLMs may not generalize from adversarial examples in the prompt as effectively as they do from diverse, clean examples.
Conclusion
This study demonstrates that while Codex is a powerful semantic parser, its robustness is highly dependent on the quality and quantity of the examples provided in the prompt. Sentence-level paraphrasing remains a significant challenge, but it can be mitigated through strategic in-context learning. Specifically, scaling the number of examples and prioritizing diversity and complexity in example selection (via methods like Cluster-TF-IDF) are the most effective ways to build resilient prompt-based parsers.
Future research may look toward dynamic prompting—tailoring the examples to the specific linguistic style of the user's input—and expanding these robustness evaluations to a broader range of code-generation tasks and different LLM architectures.
Summary updated