arXiv:2611.02248cs.LGNov 2026

Manuscript Offprint

arXiv:2611.02248

Metamorphic Testing for Evaluating Robustness of Sentiment Analysis Models

Sowjanya Karanam, Jayanth Bhargav

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Sowjanya Karanam, Jayanth Bhargav

Abstract—Machine learning systems are challenging to test using traditional software testing methods because their behavior is learned from data rather than explicitly programmed. This challenge is particularly significant in natural language processing (NLP), where small input variations can lead to unexpected model behavior. Conventional evaluation metrics, such as accuracy and F1-score, often fail to capture such inconsistencies. Metamorphic testing addresses this limitation by evaluating expected relationships between original and transformed inputs. With the increasing prevalence of generative artificial intelligence (GenAI) and language-based AI systems, the need for systematic robustness testing has become even more pronounced. Motivated by this growing need, this paper presents a lightweight, batch-based metamorphic testing approach for evaluating the robustness of such systems. In particular, we consider sentiment analysis as a representative NLP task and evaluate a pretrained classifier under four transformations: synonym replacement, typo injection, word-order variation, and negation. Using consistency score, flip accuracy, and confidence change, we identify strengths in handling semantic variations and vulnerabilities to textual noise and logical transformations. These findings highlight the value of metamorphic testing in identifying behavioral inconsistencies beyond conventional performance metrics and demonstrate its potential as a systematic framework for evaluating the robustness of language-based AI systems and guiding performance improvements before deployment.

I. Introduction

Machine learning systems are increasingly deployed in real-world applications such as recommendation systems, fraud detection, autonomous systems, and natural language processing. Unlike traditional software systems, which follow explicitly defined rules, machine learning models learn their behavior from data. As a result, their decision-making process is often complex, non-linear, and difficult to interpret. This creates significant challenges for testing and validation, as correct outputs are not always known in advance and model behavior may vary across different input distributions.

Traditional software testing techniques rely on the presence of a test oracle, which defines the expected output for a given input. However, in machine learning systems, especially in natural language processing tasks, defining such an oracle is often infeasible [1]. For example, determining the exact sentiment of a sentence can be subjective, and small variations in wording may not have a clearly defined correct output. As a result, machine learning systems are typically evaluated using statistical metrics such as accuracy, precision, recall, and cross-validation.

While these metrics provide a high-level measure of model performance, they are limited in their ability to capture how models behave under input variations [2]. In real-world scenarios, input data is rarely clean or static. Text inputs may include paraphrasing, typographical errors, grammatical variations, or changes in word order. A model that performs well on a benchmark dataset may still produce inconsistent or unreliable predictions when exposed to such variations. This highlights the need for testing methods that evaluate not only predictive performance but also robustness and stability.

Metamorphic testing provides a practical approach to address the oracle problem in machine learning systems. Instead of requiring exact expected outputs, metamorphic testing defines relationships between inputs and outputs that should hold under specific transformations [3]. For example, if a sentence is modified by replacing a word with a synonym, the sentiment should typically remain unchanged. By verifying such relationships, metamorphic testing enables systematic evaluation of model behavior without requiring a complete oracle.

Recent work has demonstrated the effectiveness of metamorphic testing for validating machine learning and deep learning systems. Ding et al. [4] show how metamorphic testing can be used to validate deep learning frameworks, while the METTLE framework [5] extends this idea to assess machine learning systems under data transformations. However, much of the existing work focuses on structured data or theoretical validation, with limited emphasis on practical applications in natural language processing.

Natural language processing presents unique challenges for robustness testing due to the inherent variability of language. Sentiment analysis, in particular, is sensitive to linguistic nuances such as negation, emphasis, and context. A robust sentiment model should maintain consistent predictions under meaning-preserving transformations while correctly adapting to transformations that alter the underlying sentiment. Evaluating these properties requires testing approaches that go beyond traditional metrics and incorporate realistic input variations.

In this paper, we propose a lightweight, batch-based metamorphic testing framework for evaluating the robustness of sentiment analysis models. The approach applies a set of simple but effective linguistic transformations, including synonym replacement, typo injection, word-order variation, and negation. These transformations simulate common real-world variations in text data.

The proposed method evaluates model behavior using consistency score, flip accuracy, and confidence change, providing insights into both correctness and stability. By analyzing model performance under different transformation types, the framework identifies strengths and weaknesses in model robustness.

The contributions of this paper are as follows:

  • A practical batch-based metamorphic testing framework for sentiment analysis models
  • A systematic evaluation of model robustness under multiple linguistic transformations
  • An analysis of model behavior highlighting limitations in handling noise and logical constructs such as negation

Overall, this work demonstrates how metamorphic testing can be used as an effective and scalable approach for evaluating robustness in natural language processing systems.