Skip to content

Constraint-Aware Counterfactual Editing for Aspect-Based Sentiment Analysis

Source: arXiv:2607.13977 · Published 2026-07-15 · By S M Rafiuddin, Vamsi Krishna Pavuluri, Atriya Sen

TL;DR

This paper addresses the challenge of generating valid counterfactual examples for Aspect-Based Sentiment Analysis (ABSA), where the goal is to flip the sentiment polarity of one specified aspect in a sentence while preserving the sentiment for all other aspects. Prior counterfactual generation methods mainly focus on sentence-level sentiment flipping and often produce edits that are contradictory, semantically drifting, or aspect-invalid. The authors propose CAVE-ABSA, a constraint-aware framework that separates candidate generation from rigorous multi-criteria validation. CAVE-ABSA first localizes the opinion span tied to the target aspect, then performs controlled rewriting limited to that span or clause, followed by repair for fluency and grammatical correctness. Candidate counterfactuals are then filtered using aspect-level sentiment verification, semantic similarity, Abstract Meaning Representation (AMR) guided structural preservation, argument minimality, fluency, and contradiction detection. Through experiments on standard ABSA benchmarks like SemEval-2014 Laptop, Restaurant, and MAMS, CAVE-ABSA demonstrates substantially improved target aspect flip rates (92.4%), non-target sentiment preservation (91.1%), semantic similarity (89.3%), and fluency (91.8%), while reducing contradiction rates to 4.6% versus much higher for prior methods. Augmenting ABSA model training with CAVE-ABSA counterfactuals leads to improved robustness, exposing brittle global polarity shortcuts in baseline models. Ablations confirm that each component—opinion-span localization, repair, AMR structural checking, and contradiction filtering—is necessary for high-quality aspect-level editing. This work provides a principled pipeline for generating aspect-level valid counterfactuals that can be used both for rigorous robustness evaluation and for training data augmentation to improve ABSA reliability.

Key findings

  • CAVE-ABSA achieves 92.4% target aspect flip accuracy, outperforming baselines such as Attribution+T5 at 85.7%.
  • It preserves non-target aspect sentiments at a 91.1% rate, significantly higher than baselines (top baseline at 81.3%).
  • Semantic similarity of generated counterfactuals to originals is 89.3%, improving over Attribution+T5’s 84.6%.
  • Fluency scores reach 91.8%, substantially better than Lexicon Replacement’s 51.2%.
  • Post-hoc contradiction rates for CAVE-ABSA are 4.6%, markedly lower than the 46.7% of simple lexicon substitution and 10.9% of Attribution+T5.
  • CAVE-ABSA retains 68.9% of generated candidates after filtering, showing efficient generation versus lower yields for other methods.
  • Augmenting ABSA model training with CAVE-ABSA counterfactuals boosts robustness metrics (target sensitivity and non-target stability) beyond augmenting with baseline-generated counterfactuals.
  • Ablation studies confirm all main pipeline components (opinion-span localization, repair, AMR-structure checking, contradiction filtering) are necessary for best generation validity and quality.

Threat model

The threat model considers an adversary attempting to generate counterfactual examples that flip the sentiment of a target aspect in a multi-aspect sentence, while preserving the sentiments of all other non-target aspects as well as sentence semantics, fluency, and factual consistency. The adversary cannot arbitrarily change non-target aspects or produce semantically contradictory or incoherent text. This models the scenario of generating valid counterfactual data for robustness evaluation and augmentation rather than a malicious attack.

Methodology — deep read

The paper formalizes aspect-level counterfactual editing as a constrained generation problem where only the target aspect's sentiment label is flipped, while all non-target aspects preserve their original labels. Furthermore, semantic similarity, minimal edits, fluency, and contradiction avoidance constraints are required to ensure valid counterfactuals.

The CAVE-ABSA pipeline includes the following steps:

  1. Threat Model & Assumptions: The adversary is a counterfactual example generator constrained by preservation of non-target aspects and sentence semantics, aiming to produce valid minimal edits for robustness evaluation or data augmentation. The adversary cannot alter non-target aspect polarity or meaning.

  2. Data: Experiments use standard ABSA benchmarks: SemEval-2014 Laptop and Restaurant reviews, plus MAMS dataset with multi-aspect sentences and varying polarity. Only positive and negative polarity cases are considered for counterfactual generation (neutrals excluded due to unclear flip direction). Train/test splits follow benchmarks; counterfactuals are generated for test and training sets in augmentation experiments.

  3. Architecture & Algorithm: Given sentence x and target aspect a* with polarity y*, CAVE-ABSA first localizes the contiguous opinion span s* tied to a* using a hybrid scoring of token proximity, syntactic dependency relations, and optional ABSA model attributions (e.g., integrated gradients). It then performs controlled rewriting constrained to s* or its enclosing clause, generating s_cf with desired flipped polarity y_cf. The edited sentence is reconstructed as c_left + s_cf + c_right, preserving target aspect substring and non-target aspects.

Next, a repair module refines the raw candidate for grammatical correctness and fluency without altering aspect terms, numbers, entities, or factual details. Then, AMR parses of original and candidate sentences are compared in their non-target subgraphs to quantify structural preservation and detect semantic drift.

A constraint-based verification step applies six key checks: target aspect flip confidence, non-target sentiment preservation, semantic similarity (Sentence-BERT embeddings), edit minimality (normalized token edit distance), fluency (LM perplexity), and contradiction detection (local polarity checks and rule-based mixed sentiment cues). Only candidates passing all hard thresholds remain.

A composite score combining these signals ranks candidates. The top-K form the final accepted counterfactual set.

Algorithm 1 formalizes this pipeline.

  1. Training Regime: Controlled rewriting is implemented via prompted or constrained sequence-to-sequence generation models; details on specific models, hyperparameters, or training epochs for repair or generation models are insufficiently detailed in the source text. Reproducibility partially depends on code release (not stated).

  2. Evaluation Protocol: Multiple automatic metrics are reported for counterfactual quality — target flip accuracy, non-target consistency, semantic similarity, fluency, post-hoc contradiction rate, and generation yield. Downstream ABSA evaluation uses macro-F1 and robustness metrics like target sensitivity and non-target stability, measured on the original vs augmented sets. Ablations remove individual components to quantify their impact.

  3. Reproducibility: The paper does not explicitly mention releasing code or frozen weights. Datasets are public ABSA benchmarks. Some procedures like attribution scores rely on pretrained ABSA classifiers. AMR parsing and NLI models are external tools used in verification.

End-to-end, given an original sentence with multiple aspects, CAVE-ABSA locates the opinion span related to the target aspect, generates candidate rewrites flipping only that span, repairs candidates, verifies all constraints including checking against AMR semantic shifts, scores and ranks candidates, and outputs validated aspect-level counterfactuals for evaluation or augmentation.

Technical innovations

  • Formulation of ABSA counterfactual generation as a constrained aspect-level editing problem enforcing target aspect flip and non-target preservation simultaneously.
  • Use of opinion-span localization combining syntactic, proximity, and attribution signals to identify minimal editable span specific to the target aspect.
  • Controlled rewriting of the localized opinion span or clause to produce fluent, minimally edited, target-polarity-flipped candidates that preserve target aspect strings and non-target facts.
  • A multi-stage validation pipeline including repair-based grammatical correction, AMR-guided structural preservation to detect semantic drift in non-target content, and a composite verification score combining target flip, non-target preservation, semantic similarity, fluency, edit minimality, and contradiction detection.
  • Explicit separation of counterfactual candidate generation from validation and ranking, improving both quality and yield of valid aspect-level counterfactuals.

Datasets

  • SemEval-2014 Laptop domain — thousands of annotated product review sentences — public
  • SemEval-2014 Restaurant domain — thousands of restaurant review sentences — public
  • MAMS (Multi-Aspect Multi-Sentiment) — multi-aspect sentences with varied sentiment labels — public

Baselines vs proposed

  • Lexicon Replacement: Target Flip = 76.4% vs CAVE-ABSA: 92.4%
  • MLM Replacement: Target Flip = 57.9% vs CAVE-ABSA: 92.4%
  • Prompt-only Rewrite: Target Flip = 84.8% vs CAVE-ABSA: 92.4%
  • Direct AMR Edit: Target Flip = 66.5% vs CAVE-ABSA: 92.4%
  • Attribution + T5: Target Flip = 85.7% vs CAVE-ABSA: 92.4%
  • Lexicon Replacement: Fluency = 51.2 vs CAVE-ABSA: 91.8
  • Attribution + T5: Non-target Keep = 81.3% vs CAVE-ABSA: 91.1%
  • Post-hoc Contradiction Rate: Lexicon Replacement = 46.7% vs CAVE-ABSA: 4.6%
  • Generation Yield (retained candidates): Attribution + T5 = 63.4% vs CAVE-ABSA: 68.9%

Limitations

  • The approach depends on accurate opinion-span localization, which may fail if syntactic or attribution signals are noisy or unavailable.
  • The repair module and rewriting process details (models, training) lack full disclosure, potentially limiting reproducibility.
  • Contradiction detection relies partly on heuristics and NLI models which may have false positives or negatives, leaving some residual contradictions.
  • Evaluation excludes neutral polarity edits due to unclear flip definitions; thus, method applicability to neutral cases is untested.
  • No adversarial or adaptive attacks were conducted to stress-test the verification pipeline under adversarial counterfactual generation.
  • AMR-based structural preservation requires robust AMR parse quality; errors in parsing may impact validation fidelity.

Open questions / follow-ons

  • Can CAVE-ABSA be extended to handle neutral aspect sentiments and multi-class polarity flips beyond binary?
  • How robust is the opinion-span localization and verification under adversarially crafted or noisy inputs?
  • Can the repair and controlled rewriting modules be trained end-to-end for improved fluency with stronger guarantees on minimal edits?
  • How well does AMR-guided structural checking perform across domains or languages with varying syntactic complexities?

Why it matters for bot defense

For bot-defense and CAPTCHA practitioners focused on evaluating the robustness of natural language understanding models, CAVE-ABSA provides a rigorous framework to generate aspect-level counterfactual examples that more precisely test whether models rely on true aspect-grounded reasoning rather than global shortcuts. This can help benchmark and harden ABSA-based content moderation or bot-detection pipelines against subtle manipulations. The methodology also highlights the importance of multi-faceted validation—including semantic, syntactic, contradiction, and minimality constraints—to produce meaningful adversarial or augmented training data. While the paper focuses on sentiment aspects, the constraint-aware generation and verification principles generalize to other fine-grained linguistic attribute editing tasks relevant to NLP-based bot or fraud detection systems.

Cite

bibtex
@article{arxiv2607_13977,
  title={ Constraint-Aware Counterfactual Editing for Aspect-Based Sentiment Analysis },
  author={ S M Rafiuddin and Vamsi Krishna Pavuluri and Atriya Sen },
  journal={arXiv preprint arXiv:2607.13977},
  year={ 2026 },
  url={https://arxiv.org/abs/2607.13977}
}

Read the full paper

Articles are CC BY 4.0 — feel free to quote with attribution