# Text Perturbation Robustness Eval

> Evaluates the robustness of finetuned transformer models (BERT, GPT-2, T5) to various text perturbations (e.g., dropping nouns/verbs, character changes, adding text) across classification and generation tasks. It measures how much model performance degrades when inputs are syntactically or semantically altered. Use when the user wants to benchmark on GLUE, XSum, CommonGen, SQuAD, or asks about evaluating this task. Reports Accuracy, Robustness Score.

- Skill: `qhjqhj00/text-perturbation-robustness-eval` (Agent Skill)
- Install (CLI): `npx skillmds add qhjqhj00/text-perturbation-robustness-eval`
- Raw SKILL.md: https://api.skillmd.com/api/skills/qhjqhj00/text-perturbation-robustness-eval/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: qhjqhj00 (https://skillmd.com/u/qhjqhj00)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/qhjqhj00/text-perturbation-robustness-eval

---


# text-perturbation-robustness-eval

> On Robustness of Finetuned Transformer-based NLP Models — Neerudu et al. (2023) (arXiv:2305.14453, 2023)

## What this evaluates

Evaluates the robustness of finetuned transformer models (BERT, GPT-2, T5) to various text perturbations (e.g., dropping nouns/verbs, character changes, adding text) across classification and generation tasks. It measures how much model performance degrades when inputs are syntactically or semantically altered.

## Datasets

- **GLUE** — total ?; splits: test (-1); HF `glue`
- **XSum** — total ?; splits: test (-1); HF `xsum`
- **CommonGen** — total ?; splits: val (-1); HF `allenai/common_gen`
- **SQuAD** — total ?; splits: test (-1); HF `squad`

## Metrics

- `Accuracy` **(primary)** — range: [0, 1]
  - Fraction of correctly predicted labels out of total instances.
- `Matthews CC` — range: [-1, 1]
  - Matthews Correlation Coefficient for binary classification tasks (e.g., CoLA).
- `Pearson CC` — range: [-1, 1]
  - Pearson Correlation Coefficient for regression/similarity tasks (e.g., STS-B).
- `ROUGE-1` — range: [0, 1]
  - Unigram overlap F1 score between generated and reference text.
- `ROUGE-2` — range: [0, 1]
  - Bigram overlap F1 score between generated and reference text.
- `ROUGE-L` — range: [0, 1]
  - Longest common subsequence F1 score between generated and reference text.
- `Robustness Score` **(primary)** — range: [0, 1]
  - Ratio of the perturbed task metric to the clean (unperturbed) task metric: metric_perturbed / metric_clean.

## Input / output format

**Input**: Single sentences or sentence pairs for classification tasks; source documents for generation tasks.

**Output**: Predicted class labels or similarity scores for classification; generated text sequences for generation.

## Scoring recipe

```python
def compute_robustness(clean_metric, perturbed_metric):
    return perturbed_metric / clean_metric

def compute_task_metric(predictions, gold, metric_name):
    if metric_name == 'Accuracy':
        return sum(p == g for p, g in zip(predictions, gold)) / len(gold)
    elif metric_name == 'Matthews CC':
        return matthews_corrcoef(gold, predictions)
    elif metric_name == 'Pearson CC':
        return pearsonr(gold, predictions)[0]
    elif metric_name.startswith('ROUGE'):
        return rouge_score(gold, predictions, rouge_types=[metric_name])
```

## Common pitfalls

- Robustness scores are reported as ratios (perturbed/clean), not absolute differences or percentages.
- GLUE sub-tasks use different primary metrics (Accuracy, Matthews CC, Pearson CC) that must be applied correctly per dataset.
- CKA and STIR measure representation similarity, not task performance robustness, and should not be confused with the evaluation metrics.

## Evidence (verbatim from paper)

> Table 1: Accuracy comparison on various GLUE datasets for BERT, GPT-2 and T5 on the test dataset. Table 3: Comparison of robustness scores on various GLUE tasks for finetuned Transformer models under different types of perturbations.

## Citation

```bibtex
@misc{neerudu2023robustness,
  title={On Robustness of Finetuned Transformer-based NLP Models},
  author={Neerudu et al. (2023)},
  year={2023},
  note={arXiv:2305.14453}
}
```

- arXiv: 2305.14453

