Robust Text Classification: Analyzing Prototype-Based Networks

Zhivar Sourati, Darshan Deshpande, Filip Ilievski, Kiril Gashteovski, Sascha Saralajew

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.

Overview of the PBN architecture, training losses, and inference process.

As depicted in Figure 2, the PBN pipeline involves:

  1. Embedding: An input $x_j$ is mapped to an embedding $e_j$ via the LM backbone $E$.
  2. Distance Calculation: The model calculates the distance (Euclidean or Cosine) between $e_j$ and each prototype $P_k$.
  3. 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$).
  4. 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$.

Impact of the clustering coefficient $\lambda_c$ on the Attack Success Rate across different datasets.

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

BibTeX
@inproceedings{sourati2024robust,
  author = {Zhivar Sourati and Darshan Deshpande and Filip Ilievski and Kiril Gashteovski and Sascha Saralajew},
  title = {{Robust Text Classification: Analyzing Prototype-Based Networks}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  url = {https://openreview.net/forum?id=hOPSyMdoMb},
}
Figure