Abstract
Standard Language Models (LMs) are highly accurate but notoriously vulnerable to adversarial perturbations. This paper investigates Prototype-Based Networks (PBNs) as a robust and interpretable alternative for text classification. By classifying inputs based on their similarity to learned "prototypes" rather than abstract linear boundaries, PBNs significantly reduce vulnerability to adversarial attacks. Our experiments across multiple benchmarks show that PBNs can drop Attack Success Rates (ASR) by nearly half compared to vanilla LMs, sometimes even outperforming massive models like GPT-4o in robustness.
Introduction
State-of-the-art Language Models (LMs) often fail when faced with human-imperceptible changes to text, such as synonym swaps or typos. This lack of robustness is a significant barrier to deploying AI in sensitive applications. Furthermore, the "black-box" nature of standard LMs makes it difficult to diagnose these failures. Prototype-Based Networks, which have shown promise in Computer Vision, offer a solution by grounding classification in similarity to representative data points, or "prototypes."
Methodology
PBNs are implemented as an architectural layer on top of standard LM backbones like BERT, BART, and ELECTRA. Unlike standard classifiers that use a linear layer for class scores, a PBN identifies $Q$ prototypes—points in the embedding space that capture key semantic patterns.
As depicted in Figure 2, the PBN pipeline involves:
- Embedding: An input $x_j$ is mapped to an embedding $e_j$ via the LM backbone $E$.
- Distance Calculation: The model calculates the distance (Euclidean or Cosine) between $e_j$ and each prototype $P_k$.
- Multi-part Loss Training: The model is trained using a composite loss function $\mathcal{L}$ that balances classification accuracy ($\mathcal{L}_{ce}$), clustering ($\mathcal{L}_c$), interpretability ($\mathcal{L}_i$), and prototype separation ($\mathcal{L}_s$).
- Similarity-Based Inference: Final predictions are determined by the proximity of the input to specific prototype clusters.
Experimental Setup
The researchers evaluated PBNs using four diverse benchmarks:
- IMDB: Binary sentiment analysis.
- AG_NEWS: Four-category news topic classification.
- DBPedia: Nine-category hierarchical classification.
- AdvGLUE (SST-2 subset): Specialized adversarial perturbation testing.
Results and Discussion
Architectural Robustness
PBNs provide an inherent "robustness boost" through their design. While standard models draw hyperplanes between classes, PBNs act as class centroids. An input must move significantly in the embedding space to shift its similarity from one prototype cluster to another. On the IMDB dataset, a BERT-based PBN reduced the Attack Success Rate (ASR) from approximately 82.5% to 42.8%.
The "Goldilocks" Zone for Prototypes
Robustness is highly sensitive to the clustering hyperparameter $\lambda_c$.
As shown in Figure 6, there is an optimal "Goldilocks" zone for $\lambda_c$. If clustering is too loose or too tight, the model's ability to handle semantic diversity diminishes, leading to higher ASR. This suggests that the model requires a balanced degree of clustering to maintain its defensive properties.
Interpretability and Performance
Because prototypes are mapped to real training examples, PBNs provide inherent interpretability. Researchers can visualize which prototype was activated, making model failures transparent. Surprisingly, these smaller, prototype-based models often outperformed massive LLMs like GPT-4o and Llama 3 in robust classification tasks, highlighting the efficiency of the prototype-based approach.
Conclusion
Prototype-Based Networks offer a compelling path toward more stable and transparent NLP systems. By shifting from linear boundaries to similarity-based prototypes, they achieve significant gains in robustness without requiring additional training data. Future work will explore extending this architecture to generative tasks and optimizing training for larger model backbones.
Summary updated