Quality Assurance of A GPT-Based Sentiment Analysis System: Adversarial Review Data Generation and Detection

Tinghui Ouyang, Hoang-Quoc Nguyen-Son, Huy H. Nguyen, Isao Echizen, Yoshiki Seo

Abstract

As Large Language Models (LLMs) become central to commercial sentiment analysis, ensuring their reliability against adversarial inputs is critical. This paper presents a framework for generating realistic adversarial product reviews and a novel detection method using a refined Surprise Adequacy (SA) metric. By monitoring internal neuron activation patterns—specifically through a proposed "DSA3" local-neighborhood approach—the system can identify deceptive inputs that bypass traditional quality checks. Experimental results on Amazon review data demonstrate that while fine-tuned models achieve high accuracy, they remain vulnerable to simple perturbations, which the DSA3 metric detects with near-perfect reliability (AUC-ROC of 0.9994).

Introduction

Sentiment analysis serves as a cornerstone for businesses tracking customer satisfaction and market trends. The integration of Large Language Models (LLMs) like GPT-3 into these pipelines has significantly improved performance but introduced new challenges in Quality Assurance (QA). Unlike traditional numeric data, text is high-dimensional and non-linear, making it difficult to detect when a model is being "fooled" by subtle input changes.

A primary concern is the "black box" nature of LLMs. A model might provide a confident prediction that is fundamentally incorrect due to a minor perturbation, such as a typo or a contraction. Such errors can distort market data and lead to poor strategic decisions. This research addresses these vulnerabilities by developing a robust framework for both generating adversarial examples and detecting them through internal model monitoring.

Methodology

The researchers' approach is divided into three distinct phases: model optimization, adversarial attack generation, and anomaly detection.

1. Fine-tuning the Sentiment Classifier

The study first established a baseline by fine-tuning a GPT-3 model on a large corpus of Amazon product reviews. The researchers found that a specialized, fine-tuned model significantly outperformed general-purpose "zero-shot" APIs, providing a more accurate foundation for sentiment classification tasks.

2. Adversarial Generation (The Attack)

To test the model's limits, the authors employed a content-based adversarial generation strategy. Rather than using complex mathematical gradients—which often produce nonsensical text—they utilized the "CHECKLIST" library to introduce "natural" perturbations. These included:

  • Typos: Common character-level misspellings.
  • Contractions: Expanding or contracting words (e.g., changing "has not" to "hasn't").

An attack was considered successful if these minor, meaning-preserving changes caused the model to flip its sentiment prediction (e.g., from Positive to Negative).

3. Detection via Modified Surprise Adequacy (The Defense)

The core innovation of the paper lies in its detection mechanism: Surprise Adequacy (SA). SA measures how much a new input "surprises" the model relative to the data it saw during training. The authors focused on Distance-based SA (DSA), which analyzes the activation patterns of neurons within the model.

Standard DSA typically compares an input to its single nearest neighbor in the training set. However, the authors observed that this method is overly sensitive to outliers. They proposed DSA3, a refined metric that compares the input's activation pattern to the center of a local neighborhood of the ten nearest points in the neuron activation space. This "local descriptor" approach provides a more robust representation of expected model behavior.

Experimental Results

The framework was evaluated using the Amazon.com review dataset, a standard benchmark for NLP sentiment analysis.

Model Performance and Attack Success

The fine-tuned GPT model achieved an impressive 94.91% accuracy, compared to the 84.54% achieved by the standard ChatGPT API. Despite this high accuracy, the model remained susceptible to content-based attacks. The success rate for typo-based adversarial examples was approximately 10%, indicating that one in ten simple misspellings could successfully deceive the classifier.

Detection Efficacy

The proposed DSA3 metric proved exceptionally effective at identifying these adversarial samples. For attacks involving a single typo, DSA3 achieved an AUC-ROC of 0.9994. Even when multiple attack types were combined, the metric maintained a high detection accuracy with an AUC-ROC of 0.9707. This suggests that "surprise" is a highly reliable signal for identifying data quality issues in LLM-based systems.

Discussion and Insights

The research yielded several key insights into the behavior of LLMs:

  • Vulnerability in Short Text: Adversarial attacks were significantly more successful on shorter reviews. Longer texts provide more semantic context, allowing the model to maintain the correct sentiment despite local perturbations.
  • Neuron Behavior as a Fingerprint: The study reinforces the value of "white-box" monitoring. Even when a model's output is confident, its internal neuron activation patterns (its "behavioral fingerprint") change significantly when processing adversarial data.
  • Local vs. Global Context: The superiority of DSA3 over global metrics suggests that LLMs process different nuances of sentiment in distinct clusters within the latent space. Effective QA tools must respect these local boundaries to accurately identify anomalies.

Conclusion

This paper demonstrates that while fine-tuned LLMs are powerful tools for sentiment analysis, they require dedicated QA frameworks to ensure reliability. By combining realistic adversarial generation with internal neuron monitoring via the DSA3 metric, developers can create more resilient systems. Future work will look to expand these techniques to more complex tasks such as code generation and summarization, as well as optimizing the computational overhead of extracting high-dimensional neuron activations for real-time applications.

Summary updated

BibTeX
@inproceedings{ouyang2023quality,
  author = {Tinghui Ouyang and Hoang-Quoc Nguyen-Son and Huy H. Nguyen and Isao Echizen and Yoshiki Seo},
  title = {{Quality Assurance of A GPT-Based Sentiment Analysis System: Adversarial Review Data Generation and Detection}},
  booktitle = {APSEC},
  year = {2023},
  doi = {10.1109/apsec60848.2023.00056},
}
Figure