Attention-Based Prototypical Learning

Sercan Ö. Arık, Tomas Pfister

Abstract

We propose a novel inherently interpretable machine learning method that bases decisions on few relevant examples that we call prototypes. Our method, ProtoAttend, can be integrated into a wide range of neural network architectures including pre-trained models. It utilizes an attention mechanism that relates the encoded representations to samples in order to determine prototypes. The resulting model outperforms state of the art in three high impact problems without sacrificing accuracy of the original model: (1) it enables high-quality interpretability that outputs samples most relevant to the decision-making; (2) it achieves state of the art confidence estimation by quantifying the mismatch across prototype labels; and (3) it obtains state of the art in distribution mismatch detection. All this can be achieved with minimal additional test time and a practically viable training time computational cost.

Introduction

Standard deep neural networks are often criticized as "black boxes." While they achieve high accuracy, understanding the rationale behind a specific classification remains a challenge. Post-hoc explanation methods, like saliency maps, attempt to explain models after training but are frequently unreliable because the underlying model was not designed for interpretability. Furthermore, black-box models often struggle with trust, confidence calibration, and sensitivity to label noise.

We propose that an ideal AI should reason similarly to a human: by comparing a new input to specific, relevant examples encountered previously. ProtoAttend makes neural networks inherently interpretable by basing decisions on a small set of "prototypes" (relevant training examples). By using an attention mechanism to select these examples, the model provides high-quality explanations and robust confidence estimation without sacrificing classification accuracy.

Conceptual overview of the ProtoAttend framework.

The ProtoAttend Architecture

The core of our framework is the ProtoAttend architecture, which replaces the standard final classification layer with a sample-based reasoning module. Instead of mapping an input directly to a label, the model compares the input against a database of candidate samples.

Relational Attention Mechanism

The model employs a relational attention mechanism to select prototypes. An encoder transforms both the input and the database samples into a common embedding space. The input is treated as a query, while database samples act as keys. The dot-product between them determines the attention weights, identifying which prototypes are most relevant to the current input.

Sparsity and Decision Making

To ensure human-readable explanations, we apply sparsity regularization (e.g., sparsemax). This forces the model to rely on a minimal set of prototypes—often just one to five—rather than a broad distribution. The final decision is a linear combination of the input's representation and the chosen prototypes. Confidence is calculated based on the label agreement among these prototypes; if the selected prototypes have conflicting labels, the model's confidence score naturally decreases.

Detailed architecture for training and inference.

Experimental Evaluation

We evaluated ProtoAttend across diverse datasets, including MNIST, Fashion-MNIST, CIFAR-10, DBPedia (text), and Adult Census Income (tabular).

  • Accuracy Preservation: On Fashion-MNIST, ProtoAttend achieved 94.42% accuracy, nearly matching the 94.74% of a standard ResNet.
  • Interpretability through Sparsity: Using sparsemax, the model successfully performed MNIST classification using a median of only 2 prototypes without accuracy loss.
  • Confidence Calibration: The model's confidence scores, derived from prototype agreement, are better calibrated than standard softmax probabilities. Evaluations show that higher confidence scores correlate strongly with actual accuracy, making the system effective for detecting out-of-distribution samples.
  • Resilience to Label Noise: In high-noise scenarios (e.g., CIFAR-10 with 80% noisy labels), ProtoAttend outperformed standard models by over 3%, as its reliance on a sparse set of prototypes helps it ignore mislabeled outliers.

Conclusion

ProtoAttend provides a path toward inherently interpretable deep learning without sacrificing performance. By "baking in" interpretability through an attention-based prototype selection mechanism, we achieve superior confidence estimation and robustness. While training requires additional computational overhead to process the candidate database, the resulting model offers a transparent reasoning process that is essential for high-stakes applications.

Summary updated

BibTeX
@misc{ark2019attention,
  author = {Sercan Ö. Arık and Tomas Pfister},
  title = {{Attention-Based Prototypical Learning}},
  year = {2019},
  eprint = {1902.06292},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1902.06292},
}
Figure