Agatha: Gated Hopfield Attention for Adversarially Robust Natural Language Processing

Andreia Podasca, Anup Das


Abstract
Transformer encoders are used for natural language understanding tasks, yet they remain vulnerable to gradient-based attacks in the embedding space. Existing defenses either use adversarial training or modify the inference pipeline, incurring additional computational overhead without a principled mechanism to contract the gradient flow. We propose Agatha, a transformer encoder that achieves adversarial robustness through architectural modifications. First, Agatha replaces softmax attention with an iterative Hopfield mechanism that projects representations into deep, sharply-bounded semantic attractors in its energy landscape. Second, Agatha introduces a gated residual connection that scales down the identity path, so adversarial gradients must propagate through the energy landscape where they contract layer by layer due to the landscape’s steep curvature.

Agatha’s geometric structure contracts adversarial gradients layer by layer in the backward pass while preserving task-relevant information in the forward pass. Evaluations on standard NLP tasks demonstrate that Agatha reduces attack success rates by 13 percentage points over the best defended baseline at 4.37M scale, with the advantage growing to over 33 points at BERT-base scale (110M), without adversarial training. AutoAttack, transfer attacks, and discrete text-level evaluations confirm the robustness is not an artifact of gradient masking. Agatha adds no parameters, achieves 1.2x faster inference than the best robust baseline, and maintains clean performance within 2 points of the undefended model.
Anthology ID:
2026.emnlp-main.709
Volume:
Proceedings of the 2026 Conference on Empirical Methods in Natural Language Processing
Month:
October
Year:
2026
Address:
Budapest, Hungary
Editors:
Hung-Yi Lee, Sunipa Dev, Jessy Li, Desmond Elliott
Venue:
EMNLP
SIG:
SIGDAT
Publisher:
Association for Computational Linguistics
Note:
Pages:
16437–16482
Language:
URL:
https://aclanthology.org/2026.emnlp-main.709/
DOI:
Bibkey:
Cite (ACL):
Andreia Podasca and Anup Das. 2026. Agatha: Gated Hopfield Attention for Adversarially Robust Natural Language Processing. In Proceedings of the 2026 Conference on Empirical Methods in Natural Language Processing, pages 16437–16482, Budapest, Hungary. Association for Computational Linguistics.
Cite (Informal):
Agatha: Gated Hopfield Attention for Adversarially Robust Natural Language Processing (Podasca & Das, EMNLP 2026)
Copy Citation:
PDF:
https://aclanthology.org/2026.emnlp-main.709.pdf