All writing
AI Safety8 min read · Interactive

Purifying adversarial attacks with topology

A walkthrough of the intuition behind TopoReformer and topological purification for OCR-based attacks.

By Aravinthakshan

A text image can look readable to us while an OCR model transcribes something else. Adversarial perturbations exploit that gap: a small change to the image can push the model toward a very different answer.

Can we preserve what makes a character itself?

TopoReformer studies purification before recognition. Rather than retrain each downstream recognizer, it learns a transformation of the input. The extra prior is topology: the organization of data, including connectivity and loops, that can survive some changes in appearance.

The paper was accepted at the AAAI 2026 AI for Cyber Security workshop. Here is the intuition, the pipeline, and what its experiments actually tell us.

01 — An intuition you can move

What survives as the scale changes?

Each dot represents a sample. Connect samples whose distance is at most ε. Close neighbors merge first; separated groups remain distinct for longer. The barcode records exactly when each component joins another.

Zero-dimensional persistence · H₀3 components remain

Samples & merge connections

ABCDEFGHIJKLOutlined samples participated in the latest merge

Component lifetimes

A: born at 0; persists indefinitelyAB: born at 0; merges at 26.08BC: born at 0; merges at 30.46CD: born at 0; merges at 30.41DE: born at 0; merges at 124.02EF: born at 0; merges at 27.80FG: born at 0; merges at 34.67GH: born at 0; merges at 32.89HI: born at 0; merges at 112.45IJ: born at 0; merges at 27.20JK: born at 0; merges at 31.24KL: born at 0; merges at 28.30L04080120170Distance threshold ε →

Latest merge: at ε = 34.67, component G joins E. Its highlighted bar ends there; its samples stay in the merged group.

Black bars cross the current threshold; pale bars have ended. The highlighted row marks the latest merge. A’s arrow denotes the one component that persists indefinitely.

Short bars capture merges among nearby samples. Longer bars reflect groups that stay separate across more distance scales. Persistence measures that lifetime; it does not by itself tell us which features are noise.

An exact H₀ calculation on an illustrative point cloud, not OCR embeddings. Lines show the merge connections needed to preserve connectivity. All components start at zero, so ties are resolved alphabetically. Inspired by Moor et al., Figure 1.

Preserve these relationships when compressing the input

The autoencoder has two jobs: reconstruct its inputs and preserve their topological relationships in the latent representation. The topology loss compares selected distances from persistence pairings in both spaces. It encourages the encoding to retain how samples are organized across scales.

Topological Autoencoders Figure 2: an encoder maps input X to latent code Z, a decoder reconstructs X, and a separate topological loss compares input and latent persistence diagrams alongside reconstruction loss.
Figure 2 from Topological Autoencoders, Moor et al., ICML 2020—the prior work cited by TopoReformer for its topology loss. Original diagram, cropped from the paper. © 2020 the authors.

02 — Inside TopoReformer

Reconstruct the image. Preserve the relationships.

A Topological Autoencoder learns a reconstruction and a representation constrained by persistent homology. Its output feeds a variational Reformer, while an Auxiliary module carries the topological latent representation into the Reformer’s bottleneck. A frozen classifier reads the result.

TopoReformer pipeline: Topological Autoencoder reconstruction and an auxiliary latent path feed a Reformer, followed by a frozen classifier.
Figure 1 from the paper, reproduced without changes. The blocks illustrate the pipeline, rather than exact network layer specifications. Open full resolution ↗

01 / Learn structureTrain the Topological Autoencoder on unperturbed data, balancing reconstruction with preservation of relationships in latent space.

02 / ReformFix the Topological Autoencoder and train the Reformer and Auxiliary path. The classifier’s weights remain frozen.

03 / Balance the pathsA freeze–flow warm-up initially freezes the Reformer encoder so the Auxiliary path can contribute, before joint refinement.

The OCR experiment uses a lighter variant: it leaves out the Reformer for efficiency, purifies character crops, and recombines them into word images. That distinction matters when comparing the OCR results with the digit and character classification experiments.

03 — A closer look

Where does the model look?

These Grad-CAM panels come from Figure 3 of the paper. They visualize model attention on the letter “i” before and after reformation. The colors are retained from the original figure.

True character: i
Before · j · 0.18Reformed · i · 0.88
Reformed adversarial Grad-CAM: predicted i · 0.88Original adversarial Grad-CAM: predicted j · 0.18
↔

Drag to compare · Arrow keys work too

Figure 3, TopoReformer. Labels show predicted character and confidence for this example. Grad-CAM maps are qualitative visualizations, not segmentation masks or a dataset-level accuracy measurement.

04 — Reading the results

One defense, different tests

All values are percentages from the paper. Attack success rate (ASR) should fall; F1 and precision should rise. OCR character accuracy measures correctly recognized characters and is distinct from whole-word attack success.

Adaptive attacks, MNIST; baseline and defended results
Attack / settingASR ↓F1 ↑Precision ↑
EOTNo defense99.053.385.21
EOTTopoReformer9.1990.7391.07
EOT + BPDANo defense99.703.214.89
EOT + BPDATopoReformer36.5964.7166.65
BPDANo defense99.604.447.28
BPDATopoReformer81.1415.6540.98

Table 2. EOT accounts for randomness; BPDA approximates the backward pass through a defense. Their combined evaluation tests both. Full paper ↗

The strongest result depends on the test. Under EOT on MNIST, ASR falls from 99.05% to 9.19%. Under BPDA alone it remains 81.14%, with an F1 of 15.65%. Those numbers are an important limit on the robustness claim.

In the classical-attack ablations, adding every module does not improve every score: on EMNIST under PGD and FGSM, the Reformer-only stage can outperform the final warm-up configuration. The value of topology is something to test under a defined threat model, not a guarantee that every perturbation will disappear.

Figures and results: Bhagyesh Kumar, A S Aravinthakashan, Akshat Satyanarayan, Ishaan Gakhar, and Ujjwal Verma. TopoReformer, arXiv:2511.15807. Figures © 2026 Association for the Advancement of Artificial Intelligence. The point-cloud explorer is an educational illustration created for this article.