Adversarial Math Word Problem Generation

Roy Xie, Chengxuan Huang, Junlin Wang, Bhuwan Dhingra

Introduction

As Large Language Models (LLMs) become increasingly integrated into educational environments, the challenge of accurately assessing student performance grows. Educators are currently locked in a "cat-and-mouse" game with AI-generated plagiarism. While detection tools exist, they often fail to distinguish between original student work and sophisticated AI outputs. This raises a critical question regarding the nature of LLM "intelligence": are these models truly reasoning through mathematical concepts, or are they simply identifying and replicating numeric patterns encountered during training?

This research addresses this fundamental concern by introducing a novel adversarial attack method. Unlike traditional attacks that rely on linguistic rephrasing—which often results in awkward or nonsensical phrasing—this approach focuses on strategically altering the numeric values within Math Word Problems (MWPs). By maintaining logical consistency while shifting the numeric distribution, the researchers demonstrate that even state-of-the-art models are surprisingly fragile when faced with unfamiliar numeric contexts.

Methodology: From Natural Language to Abstract Syntax Trees

The core of the proposed method is a structural pipeline designed to generate adversarial problems that remain trivial for humans but become insurmountable for AI. The process involves four distinct stages:

  1. Code Transformation: The pipeline begins by using GPT-4 to translate a natural language math problem into a functional Python script. This step is crucial as it distills the problem's underlying mathematical logic into a programmatic format.
  2. AST Representation: The resulting Python code is parsed into an Abstract Syntax Tree (AST). In this hierarchical structure, "variable nodes" represent the specific numbers from the original problem, while "operation nodes" represent the mathematical functions (e.g., addition, multiplication, division) required to reach the solution.
  3. Constrained Modification: To ensure the generated problems remain realistic and educationally sound, the system applies "Filtering Constraints." For instance, if a problem involves counting people, the constraints ensure that any new numeric inputs still result in an integer answer, avoiding nonsensical outputs like "2.5 students."
  4. Generation Tiers (M1-M3): The researchers established three levels of numeric substitution to test different degrees of adversarial pressure:
  5. M1 (Free): Utilizes a wide range of random numbers.
  6. M2 (Digit Count): Maintains the same number of digits as the original problem (e.g., replacing 100 with 942).
  7. M3 (Scientific): The most sophisticated tier, which uses Poisson distributions to keep the new numbers very close in magnitude and "feel" to the originals.
The pipeline for generating adversarial math word problems via AST transformation.

Experimental Setup

The effectiveness of this method was evaluated using two gold-standard benchmarks for mathematical reasoning: GSM8K, a collection of 8,500 high-quality grade school math problems, and MultiArith, sourced from elementary school worksheets. For comparison, the researchers also utilized RobustMath, a baseline dataset consisting of rephrased versions of the original problems.

Key Results and Discussion

The results of the study reveal a significant gap between the perceived and actual reasoning capabilities of modern LLMs.

Massive Performance Degradation

The most striking finding was the precipitous drop in accuracy across nearly all tested models. As shown in the experimental data, even under the most restrictive M3 constraints—where the problems look almost identical to the originals—performance plummeted. For example, WizardMath 13B saw its accuracy on MultiArith drop from an original 89% to just 20%.

Performance metrics across various LLMs on MultiArith and GSM8K benchmarks under different adversarial tiers.

The "Memorization" Trap

The fact that models fail so consistently on the M3 tier suggests a "memorization trap." LLMs appear to be over-relying on specific numeric distributions seen during pre-training rather than applying generalized mathematical rules. When the "distributional feel" of a problem is subtly shifted, the model's internal heuristics fail.

Superiority Over Rephrasing

The AST-based numeric modification method proved far more effective than traditional rephrasing attacks. On average, the researchers achieved a 62-point higher Attack Success Rate (ASR) compared to methods that only swap synonyms or alter sentence structure. This highlights that the numeric values themselves are a primary source of model brittleness.

Model-Specific Vulnerabilities and Transferability

Regression analysis indicated that different models have unique "comfort zones." Mistral 7B, for instance, performs better with smaller answer values, while MetaMath 7B is more robust in the mid-range. Interestingly, adversarial examples that break "weaker" models like Llama 2 13B are highly likely to also fool other models in that class. However, "stronger" models like GPT-4 exhibit more idiosyncratic failure patterns, making them harder to target with a one-size-fits-all approach.

Conclusion and Future Directions

This research underscores the fragility of current LLM reasoning. While these models can solve complex-looking word problems, their success is often tethered to the specific numeric patterns they have "memorized."

The authors acknowledge that while this method is highly effective for elementary arithmetic, further research is needed to determine if these vulnerabilities persist in higher-level mathematics, such as calculus or symbolic logic. Moving forward, these adversarial techniques could be repurposed for "adversarial training," helping to build the next generation of LLMs that possess truly robust, distribution-independent mathematical reasoning skills.

Summary updated

BibTeX
@inproceedings{xie2024adversarial,
  author = {Roy Xie and Chengxuan Huang and Junlin Wang and Bhuwan Dhingra},
  title = {{Adversarial Math Word Problem Generation}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.findings-emnlp.292},
}
Figure