Using Topological Data Analysis to Characterize the Layers of Language Models Before and After Word Substitution Attacks
Summary
A new topological data analysis (TDA) framework has been introduced to investigate the structural effects of adversarial word substitution attacks on large language models' internal representations. This framework evaluates small encoder-based architectures like BERT, RoBERTa, and DistilBERT, fine-tuned for binary classification on the IMDb review dataset and attacked using TextFooler. The method converts attention maps into distance matrices, applies TDA to extract topological features, and compares these features using Wasserstein distances between original and perturbed states. A non-TDA baseline using per-head L1 distances was also computed. Findings indicate that adversarial perturbations induce systematic and statistically significant topological changes across model layers, with the largest deviations observed in late layers and notable effects in early layers. These patterns are consistent across models and validated by non-parametric (Kruskal–Wallis, Dunn) and parametric (one-way ANOVA, Tukey) tests. The TDA framework provides more distinct layer-wise separation and a robust, interpretable method compared to the L1 baseline.
Key takeaway
For AI Security Engineers evaluating language model robustness, this TDA framework offers a powerful new lens. You should consider integrating topological analysis to gain deeper, layer-by-layer insights into how adversarial attacks structurally alter internal model representations, beyond just output behavior. This approach provides a more robust and interpretable understanding of perturbation propagation, enabling more targeted defense strategies against synonym-based word substitutions.
Key insights
Topological Data Analysis reveals systematic structural changes in LLM internal representations due to adversarial word substitutions.
Principles
- Adversarial perturbations induce systematic topological changes.
- Late layers show largest deviations in internal structure.
- TDA offers robust, interpretable analysis of model structure.
Method
Convert attention maps into distance matrices, apply TDA to extract topological features, then compare original and perturbed features using Wasserstein distances.
In practice
- Apply TDA to analyze adversarial influence on attention maps.
- Compare TDA with L1 distances for structural insights.
- Evaluate layer-by-layer changes in model representations.
Topics
- Topological Data Analysis
- Adversarial Attacks
- Language Models
- Attention Maps
- BERT
- Model Robustness
Code references
Best for: Research Scientist, AI Scientist, Machine Learning Engineer, AI Security Engineer
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Paper Index on ACL Anthology.