Two Heads Are Better Than One: A Multi-Task Learning Framework for Robustness Against Adversarial Text Perturbations
Abstract
Sentiment analysis models deployed in real-world applications face significant threats from adversarial attacks that perturb the text input at the character and word levels. While adversarial robustness has been extensively studied in NLP, most approaches focus solely on improving robustness against a single attack type. This paper introduces a unified multi-task learning framework that jointly trains a DeBERTa-v3 encoder with two classification heads: (1) sentiment classification (primary task), and (2) attack-type detection (auxiliary task). Our key finding is counter-intuitive: jointly training on attack-type detection, despite being an ostensibly unrelated auxiliary task, measurably improves sentiment robustness against both attack types. We conduct a rigorous six-stage experimental study — spanning a pilot comparison of five loss-weighting strategies, a hyperparameter sweep, full-scale confirmatory training, a controlled ablation ladder, and out-of-distribution (OOD) generalization testing. The primary model, trained with a fixed loss-weight ratio (λₐ = 0.3), achieves 83.28% overall sentiment accuracy on in-distribution test data, with 77.84% robustness on character-level attacks and 84.16% on word-level attacks. A single-task sentiment-only baseline trained under identical conditions reaches only 79.18%, demonstrating that auxiliary attack-type supervision acts as a robustness-improving regularizer. External evaluation on independently-generated TextAttack adversarial samples confirms generalization beyond the training pipeline, with 83.33% accuracy on character-attacked samples and 85.00% on word-attacked samples.