Towards Crafting Text Adversarial Samples

Suranjana Samanta, Sameep MehtaarXiv 2017

Abstract

Adversarial attacks, well-documented in the computer vision domain, involve making subtle perturbations to input data to deceive machine learning models. Extending these attacks to natural language processing (NLP) is challenging due to the discrete and structured nature of text. This paper introduces a novel framework for generating adversarial text samples—strategically modified sentences designed to flip model predictions while remaining indistinguishable to human readers. By leveraging word importance ranking and "genre-specific" keywords, the proposed method successfully compromises sentiment and gender classifiers with minimal, grammatically sound changes.

Introduction: The Challenge of Textual Adversaries

In computer vision, adversarial attacks are a known vulnerability. For instance, by altering a few pixels in an image, an attacker can cause a model to misclassify a digit—such as seeing a '7' as a '3'—even if the change is imperceptible to humans.

Adversarial example in computer vision: a digit '7' perturbed to be misclassified as a '3'.
A digit '0' perturbed to be misclassified as a '6'.

Crafting similar attacks for text is significantly more difficult. Unlike images, where pixel values can be adjusted continuously, text is discrete. Swapping words randomly often results in ungrammatical or nonsensical sentences, making the attack obvious. This research addresses the challenge of creating "stealthy" adversarial text that is both effective at fooling models and natural enough to pass human inspection.

Methodology

The authors propose a greedy algorithm that iteratively modifies text until the target classifier's prediction flips. The framework rests on three pillars:

1. Calculating Word Importance

Inspired by the Fast Gradient Sign Method (FGSM) used in image processing, the authors rank words based on their contribution to the model's final decision. By identifying these "heavy hitters," the algorithm can target the most influential words first, minimizing the total number of changes required.

2. Modification Strategies

The framework employs three primary tactics to perturb the text:

  • Removal: Deleting high-contribution adverbs (e.g., "extremely"), which often alters sentiment intensity without violating grammatical rules.
  • Addition: Inserting adverbs before adjectives to subtly shift the model's perception.
  • Replacement: Swapping words with synonyms, common typos, or "genre-specific" keywords. Parts-of-Speech (POS) tagging ensures that replacements maintain the original sentence structure.

3. Genre-Specific Keywords

A key innovation is the use of keywords tailored to specific sub-categories. For example, the word "hilarious" is a strong positive indicator for a comedy but might be interpreted differently in a horror context. Exploiting these nuances allows the attacker to find "weak spots" in how a model generalizes across different domains.

Experimental Evaluation

The method was evaluated on two benchmarks: the IMDB Movie Review Dataset (sentiment analysis) and a Twitter Gender Detection Dataset. To test the genre-specific theory, the IMDB dataset was sub-categorized into genres like Action, Comedy, and Drama.

Key Results

The proposed method significantly outperformed existing baselines such as TextFool:

  • Success Rate: On the IMDB dataset, the method achieved a 90.64% success rate using genre-specific keywords, compared to just 0.64% for the baseline.
  • Model Degradation: The accuracy of a Convolutional Neural Network (CNN) classifier on IMDB plummeted from 74.53% to 32.55% when exposed to adversarial samples.
  • Human-Like Quality: Semantic similarity scores (measured via Spacy) remained high (0.91 to 0.97), indicating that the adversarial text preserved the original meaning.
  • Defense through Retraining: Incorporating adversarial samples into the training set (adversarial training) restored model accuracy to approximately 78%, enhancing robustness.

Discussion and Future Work

The study highlights that adverbs are the "soft underbelly" of NLP models, as they can be easily manipulated with minimal grammatical impact. Furthermore, it demonstrates that models often rely on "global" features that can be exploited by targeting sub-category-specific nuances.

While effective, the current approach relies on heuristic-based rules for modifications. Future research aims to move beyond word-level changes toward sentence-level modifications and to automate the heuristic process, making adversarial generation more efficient and harder to detect by automated defenses.

Summary updated

BibTeX
@misc{samanta2017towards,
  author = {Suranjana Samanta and Sameep Mehta},
  title = {{Towards Crafting Text Adversarial Samples}},
  year = {2017},
  eprint = {1707.02812},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1707.02812},
}
Figure