Language Models (LMs) have become ubiquitous, powering everything from customer service chatbots to code generation tools. However, despite their impressive capabilities, they possess a significant fragility: adversarial attacks. By making subtle changes to an input sentence—changes often imperceptible to humans—an attacker can trick a model into making a completely wrong prediction.
While researchers have developed highly successful attack methods, defenders have caught up. They have realized that while adversarial examples might fool the model’s prediction logic, they often look statistically “weird.” They break the data distribution patterns that the model is used to seeing. This allows defenders to build simple detectors that flag these inputs before they can do damage.
In this post, we will dive deep into DA³ (Distribution-Aware Adversarial Attack), a novel method proposed by Wang et al. that changes the game. Instead of just trying to fool the model, DA³ explicitly learns to mimic the statistical distribution of the original training data. The result? “Stealthy” attacks that bypass detection systems while maintaining high success rates.
The Problem: Successful Attacks are Too “Loud”
To understand why DA³ is necessary, we first need to look at the flaw in previous attack methods (like TextFooler or BERT-Attack). These methods work by greedily swapping words to flip a label. For example, changing “The students are sanguine” to “The students are jubilant” might confuse a sentiment classifier.
However, these perturbations leave a digital fingerprint. When a standard language model processes these adversarial inputs, it often reacts with hesitation or confusion, even if it eventually outputs the wrong label.

As shown in Figure 1, a standard adversarial example (top) might successfully trick the model into a “Negative” prediction, but a separate “Detector” module flags it immediately. The goal of DA³ is to generate the bottom example: an attack that flips the prediction and passes the detector.
The Two “Tells” of an Adversarial Attack
The researchers identified two specific statistical signals—or “distribution shifts”—that give away standard adversarial attacks:
- Reduced Confidence (MSP): When a model processes normal data, it is usually very confident (e.g., “I am 99% sure this is Positive”). When processing adversarial data, the Maximum Softmax Probability (MSP)—the confidence score of the predicted class—tends to drop.
- Distance from Training Data (MD): The Mahalanobis Distance (MD) measures how far a data point is from the center of the training data distribution in the model’s feature space. Normal data sits close to the center; adversarial data usually sits on the fringes (Out-of-Distribution).
Let’s look at the data.

In Figure 2, compare the blue bars (Original data) with the pink bars (Adversarial data generated by BERT-Attack). The original data is heavily clustered around high confidence (1.0). The adversarial data, however, shifts to the left. A defender simply needs to set a threshold: “If confidence is below 0.9, flag it.”

Figure 3 shows the Mahalanobis Distance. The original data (blue) clusters at a lower distance. The adversarial data (red) shifts to the right, indicating it is statistically distant from what the model considers “normal.”
Because previous attacks ignore these shifts, they are easily neutralized by Out-of-Distribution (OOD) detectors.
The Solution: DA³ (Distribution-Aware Adversarial Attack)
The core innovation of DA³ is to incorporate these distribution metrics directly into the attack generation process. It forces the generated examples to align with the original data’s distribution in terms of both confidence (MSP) and distance (MD).
Architecture Overview
DA³ operates in two phases: Fine-tuning and Inference.

Phase 1: Fine-Tuning with Data Alignment Loss
In this phase, the goal is not to attack yet, but to train a generator that understands how to create “stealthy” perturbations. The researchers take a Pre-trained Language Model (PLM) and add LoRA (Low-Rank Adaptation) adapters. LoRA allows them to fine-tune a small number of parameters efficiently while keeping the massive PLM frozen.
The model is trained using a Masked Language Modeling (MLM) task—similar to how BERT is pre-trained—but with a twist. The loss function, called Data Alignment Loss (DAL), forces the model to generate embeddings that look statistically normal.
Phase 2: Inference
Once the LoRA layers are fine-tuned, the model is used to generate attacks.
- Token Importance: The system identifies which words in a sentence are most critical for the current prediction.
- Mask and Fill: It masks those critical words.
- Generator: The fine-tuned DA³ model fills in the blanks. Because it was trained with DAL, the words it chooses are likely to result in a sentence that not only fools the victim model but also resides deep within the “safe” statistical distribution.
The Math Behind the Stealth: Data Alignment Loss (DAL)
The secret sauce of DA³ is the objective function used during fine-tuning. The total loss, DAL, is the sum of two components designed to counter the two detection methods we discussed earlier.

Let’s break down the two components.
1. MSP Loss (\(\mathcal{L}_{MSP}\))
The goal here is to ensure that when the victim model makes a prediction on the adversarial example, it does so with high confidence. Usually, we want a model to be unsure about wrong answers, but an attacker wants the model to be confidently wrong to avoid detection.

By minimizing this loss, the attacker maximizes the probability of the predicted class (even if it’s the wrong class), pushing the adversarial example’s confidence profile closer to that of legitimate data.
2. MD Loss (\(\mathcal{L}_{MD}\))
This component minimizes the Mahalanobis Distance between the adversarial example’s embedding (\(X^{adv}\)) and the training data distribution (represented by mean \(\mu\) and covariance \(\Sigma\)).

Minimizing this equation pulls the generated adversarial example from the “outlier” regions of the feature space back toward the dense center where normal training data lives. This effectively blinds distance-based detectors.
A New Metric: Non-detectable Attack Success Rate (NASR)
In the past, researchers used Attack Success Rate (ASR)—the percentage of inputs that successfully flipped the model’s prediction. But if 90% of those successful attacks are immediately blocked by a detector, the effective success rate is terrible.
To measure this reality, the authors propose NASR.

This formula calculates success by ensuring the adversarial example satisfies two conditions:
- \(y^{adv} = y^{orig}\): The attack actually changed the label (note: the formula subtracts the failures and detected items from 1).
- It is NOT in the set \(\mathcal{D}_k\), where \(\mathcal{D}_k\) represents attacks caught by detectors (MSP or MD).
In simple terms: NASR = (Attacks that work AND allow you to get away with it) / Total Examples.
Experimental Results
The researchers tested DA³ against standard baselines (like TextFooler and BERT-Attack) on datasets including sentiment analysis (SST-2) and grammar correctness (CoLA). They attacked both white-box models (where model internals are known) and black-box models (like Llama-2).
White-Box Performance
When attacking BERT and RoBERTa models, DA³ showed impressive results.

Looking at Table 1, pay attention to the NASR columns.
- BERT-Attack often has decent ASR, but its NASR drops significantly. For example, on the SST-2 dataset (sentiment), BERT-Attack has an ASR of 58.44%, but an \(NASR_{MSP}\) of only 33.62%. This means nearly half of its successful attacks were easily detected!
- DA³ (Ours) achieves an ASR of 77.17% and an \(NASR_{MSP}\) of 54.22%. It maintains a much higher ratio of non-detectable attacks.
- On the MRPC dataset, DA³ achieves a massive 99.16% ASR with extremely high non-detectability scores (93.29% for MD).
Visualizing Stealth with t-SNE
Numbers are great, but visuals are undeniable. The researchers used t-SNE to project the high-dimensional embeddings of the text into 2D space to see where the adversarial examples “sit” relative to the original data.

- Left (BERT-Attack): The adversarial examples (yellow and red dots) are scattered chaotically. They often land in the “no-man’s-land” between the clean clusters (blue circles). This makes them easy to spot.
- Right (DA³): The adversarial examples are neatly tucked inside the clusters of the original data. The red dots (successful attacks) are mixed right in with the original negative examples. To a detector looking at geometry, these points look perfectly normal.
Transferability to Black-Box LLMs (Llama-2)
Perhaps the most exciting result is how well these attacks transfer. The researchers generated adversarial examples using a BERT-based DA³ model and fed them to Llama-2-7B, a completely different Large Language Model that DA³ never saw during training.

As shown in Table 2, DA³ outperforms baselines significantly on almost all datasets.
- On SST-2, DA³ achieves an ASR of 29.42% compared to TextFooler’s 23.81%.
- Crucially, the NASR scores remain high. This suggests that by learning the distribution of the language, DA³ learns universal features of “stealth” that apply even to massive models like Llama-2.
Do the Loss Components Matter? (Ablation Study)
You might wonder if you really need both MSP Loss and MD Loss. The authors checked this by turning them off one by one.
Table 4 (MSP Loss Ablation):
Removing MSP Loss often increased the raw ASR (easier to fool the model if you don’t care about confidence), but the Detection Rate (\(DR_{MSP}\)) skyrocketed. On SST-2, the detection rate jumped from 29.74% to 51.89% without MSP loss.
Table 5 (MD Loss Ablation):
Similarly, removing the MD loss caused the detection rate via Mahalanobis Distance to increase. The combination of both losses (Equation 007) provides the best balance of attack power and stealth.
Qualitative Examples
What do these attacks actually look like?

In Table 14, we see that DA³ often makes very subtle changes.
- Original: “The sailors rode the breeze…”
- Adversarial: “The sailors wandered the breeze…”
- Result: The grammar checker flips from “Acceptable” to “Unacceptable,” but the sentence structure remains statistically plausible enough to evade detection.
Conclusion
The DA³ paper highlights a critical evolution in the arms race between AI attackers and defenders. It proves that simply checking for “weird” statistical patterns—low confidence or outlier embeddings—is no longer sufficient. By incorporating Data Alignment Loss, attackers can generate inputs that are not only effective but also statistically indistinguishable from legitimate data.
For students and researchers in NLP security, DA³ serves as a warning: Robustness isn’t just about accuracy; it’s about understanding the entire distribution of your data. As attacks become more “distribution-aware,” our defenses must evolve to look beyond simple statistical thresholds.
](https://deep-paper.org/en/paper/file-2914/images/cover.png)