Defensive Dual Masking for Robust Adversarial Defense

Wangli Yang, Jie Yang, Yi Guo, Johan Barthelemy · 2024

Read Defensive Dual Masking for Robust Adversarial Defense by Wangli Yang, Jie Yang, Yi Guo, Johan Barthelemy (2024) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2412-07078.txt.

Introduction

Wangli Yang, Jie Yang, Yi Guo, and Johan Barthelemy present a defense for text classifiers in a paper from 2024. Attackers tweak input words slightly to fool language models while keeping meaning for humans. Their method, Defensive Dual Masking, inserts mask tokens into training examples so the model learns to cope with tampering. At run time, suspicious tokens are swapped for masks to neutralize the attack.

Tests across many data sets and attack styles beat leading defenses on accuracy and robustness. The method also strengthened large language models against attacks. Theory sections explain why selective masking helps the model spot manipulation. The authors offer it as a scalable shield for language applications.

Catalog record

CREATORWangli Yang, Jie Yang, Yi Guo, Johan Barthelemy
YEAR2024
COLLECTIONPAPERS
FORMATTXT
FILE SIZE50 KB
VERSION1.0
LICENSEhttp://creativecommons.org/licenses/by/4.0/
RIGHTSCC BY
SOURCEarXiv

Source: https://arxiv.org/abs/2412-07078

Browse the full library · About the Tower of Babel

Full text

The opening of the work, from the library's hosted text:

Defensive Dual Masking for Robust Adversarial Defense Wangli Yang, Jie Yang, Yi Guo, Johan Barthelemy Abstract The field of textual adversarial defenses has gained considerable attention in recent years due to the increasing vulnerability of natural language processing (NLP) models to adversarial attacks, which exploit subtle perturbations in input text to deceive models. This paper introduces the Defensive Dual Masking ( DDM ) algorithm, a novel approach designed to enhance model robustness against such attacks. DDM utilizes a unique adversarial training strategy where [MASK] tokens are strategically inserted into training samples to prepare the model to handle adversarial perturbations more effectively. During inference, potentially adversarial tokens are dynamically replaced with [MASK] tokens to neutralize potential threats while preserving the core semantics of the input. The theoretical foundation of our approach is explored, demonstrating how the selective masking mechanism strengthens the model’s ability to identify and mitigate adversarial manipulations. Our empirical evaluation across a diverse set of benchmark datasets and attack mechanisms consistently shows that DDM outperforms state-of-the-art defense techniques, improving model accuracy and robustness. Moreover, when applied to Large Language Models (LLMs), DDM also enhances their resilience to adversarial attacks, providing a scalable defense mechanism for large-scale NLP applications. 1 Introduction Language Models (LMs) have significantly advanced the performance of many Natural Language Processing (NLP) tasks, spanning text/document classification, semantic analysis, and topic clustering. However, extensive research has revealed that LMs are susceptible to adversarial attacks, where even subtle perturbations to input texts can adversely affect model performanc. That is, fine-tuned LMs may demonstrate a significant decrease in performance, up to 85%, due to the presence of even a single-character misspelling within input textse Gao et al. (2018) ; Li et al. (2019) ; Li et al. (2020) ; Jin et al. (2020) , highlighting their limited robustness in generalization. Consequently, there has been a considerable focus on developing adversarial defenses to ensure robust model performance on both original (clean) and adversarial (polluted) inputs. Research on adversarial defenses have spanned multiple approaches, including data augmentation, model adaptation, and randomized smoothing. Data augmentation techniques, commonly referred to as adversarial training , introduce controlled perturbations to clean data, generating noisy variants that are used alongside the clean data for model fine-tuning Yoo and Qi (2021) ; Dong et al. (2021) ; Zhou et al. (2021) ; Li et al. (2021) ; Meng et al. (2022) . Although effective, these methods often demand substantial computational resources due to the need for both generating and training on augmented samples. Model adaptation approaches concentrate on refining the vanilla model by modifying the training loss function or adjusting the network architecture Wang et al. (2021) ; Le, Park, and Lee (2022) ; Liu et al. (2022) . However, such modifications typically require extensive hyperparameter tuning and are prone to overfitting, thereby potentially undermining the model generalization capabilities. Another line of work involves ensemble-based randomized smoothing techniques Ye, Gong, and Liu (2020) ; Zeng et al. (2023) , but these methods incur overhead due to ensemble classification and tend to exhibit inconsistent performance against various attack types Zhang et al. (2022) ; Xu et al. (2022) . Further elaboration on existing adversarial attack and defense methods is provided in Section 2 . Thus, further investigations are necessary to improve the generalizability and robustness of models against adversarial attacks. To take one step towards this goal, this paper introduces a novel adversarial defense algorithm, termed D efensive D ual M asking ( DDM ). The core of DDM lies in strategically incorporating [MASK] tokens at both the training and inference stages to enhance model robustness. Specifically, during the training stage, random masking is applied to input sequences by directly adding [MASK] tokens rather than replacing existing ones. This simple yet effective technique generates masked variants of the input data, which are then used to fine-tune the vanilla model (eliminating the need for training on the original, unmodified data). During the inference stage, DDM identifies potential adversarial tokens from unseen testing samples and selectively masks them. Notably, our approach does not attempt to predict the content of masked tokens; instead, the masked samples are fed directly into the fine-tuned model for inference. The proposed DDM is characterized by its simplicity and effectiveness across several aspects: 1. Compared to existing data augmentation techniques, which require generating and training on additional samples, DDM merely inserts [MASK] tokens into the original input. Despite the increase in input length, this approach remains computationally cost-effective as it avoids the overhead of generating/training additional data. 2. In contrast to model adaptation techniques, DDM preserves the standard model architecture and loss functions. This ensures consistency and compatibility while also simplifying the integration of DDM into existing frameworks, making it highly adaptable in a plug-and-play fashion. 3. Finally, unlike randomized smoothing methods that rely on ensemble-based learning, DDM eliminates the need for complex ensembling. This reduction in complexity not only simplifies implementation but also improves the efficiency of DDM across a wide range of applications. We further observe that a few existing works also employ masking strategies for adversarial defense. However, our proposed method differs from these approaches in several key aspects, as summarized in Table 1 : (1) The [Mask] token is traditionally employed to hold out portions of input tokens for predicting missing tokens, with several studies extending this approach to generate augmented data Wang et al. (2023) ; Li, Song, and Qiu (2023) ; Zhao and Mao (2023) ; Raman et al. (2023) ; Rafiei Asl et al. (2024) . In contrast, DDM directly utilizes masked token samples during model fine-tuning; and (2) Existing methods often require multiple masked variants of the same input for inference. In DDM , however, no such multiple samples are needed. We employ a simple yet effective masking strategy to eliminate potentially adversarial tokens during inference. Empirically, our proposed method, DDM , consistently outperforms recent state-of-the-art baselines across a combination of standard benchmarks and adversarial attack methods. On average, DDM achieves an improvement of average 5.0 absolute points in accuracy. Table 1: A summary of various masking strategies employed in adversarial defense, where (M) denotes the process of masking a single input several times to generate multiple masked variants. Method Training Inference Replace-then-predict Replace only Insert Replace-then-predict Replace only Insert RanMASK Zeng et al. (2023) ✓(M) ✓(M) RSMI Moon et al. (2023) ✓(M) RMLM Wang et al. (2023) ✓ ✓ Adv-Purification Li, Song, and Qiu (2023) ✓ GenerAT Zhao and Mao (2023) ✓ MVP Raman et al. (2023) ✓ ✓ MI4D Hu et al. (2023) ✓ ✓ RobustSentEmbed Rafiei Asl et al. (2024) ✓ ✓ DDM ✓ ✓ The paper is structured as follows: Section 2 surveys existing work on adversarial attacks and defenses methods. Section 3 introduces the proposed method and offers theoretical analysis into the effects of masked varitions on model fine-tuning and inference. Section 4 evaluates the method across a combination of four highly-competetive benchmarks and four attacking mechanisms, followed by a comprehensive ablation study. Finally, Section 5 concludes and outlines future research directions. 2 Related work As Transformer-based Language Models (LMs) gain widespread use in tasks such as text classification, clustering, and information retrieval, their susceptibility to adversarial attack has become a growing area of

Read the complete text