Manuscript Offprint
arXiv:2610.35593SAP-ViT: A Self-Attributing Patch Vision Transformer for Medical Image Classification
WEI ZHANG, WOLFGANG NEJDL, MING TANG
L3S Research Center, Leibniz University Hannover, 30167 Hannover, Germany
Corresponding author: Wei Zhang (wei.zhang@l3s.de).
ABSTRACT Vision Transformer (ViT) classifiers commonly rely on a global classification (CLS) token for image-level prediction, which is poorly aligned with local interpretability requirements in medical imaging. We propose SAP-ViT, a Self-Attributing Patch Vision Transformer that replaces CLS-based classification with direct aggregation of last-layer patch embeddings. This design makes class predictions decomposable into patch-level contributions as part of the forward pass. To encourage concise and readable evidence, SAP-ViT applies sparsity regularization to the patch-weight distribution. Since self-attention mixes information across patch tokens, we further introduce an input-space back-mapping mechanism to estimate which input patches contribute to influential output patch embeddings. We evaluate SAP-ViT qualitatively and quantitatively on multiple medical image classification datasets spanning different imaging modalities. The results show that SAP-ViT maintains strong classification performance while providing consistent and interpretable patch-level explanations across datasets. Ablation results further show that both sparsity regularization and the alignment component of input-space back-mapping contribute to the final explanation quality. Overall, SAP-ViT provides a favorable trade-off between predictive accuracy and interpretability for ViT-based medical image classification.
INDEX TERMS Interpretability, Vision transformer, Medical image classification.
arXiv:2610.3593v1
1. INTRODUCTION
Transformer-based models have recently been explored across diverse medical imaging tasks [1]. In medical image classification, models are increasingly expected not only to make accurate predictions but also to provide interpretable evidence for those predictions. This requirement is especially important in clinical settings, where model outputs may support high-stakes decisions and where clinicians need to inspect whether the model relies on medically meaningful image regions.
Vision Transformer (ViT) [2] classifiers have shown strong performance in image classification, but standard ViT classifiers usually rely on a global classification (CLS) token for prediction. The CLS token aggregates information across patch tokens and produces an image-level representation, which is effective for classification but poorly aligned with local interpretability. In medical imaging, where disease evidence is often spatially localized, it is desirable to understand how individual image regions contribute to the prediction.
A natural solution is to make the prediction itself patch-decomposable. However, patch-level attribution in ViT is non-trivial because self-attention [3] mixes information across patch tokens. As a result, an influential last-layer patch embedding may contain information not only from its corresponding input patch but also from other regions of the image. Therefore, patch-level attribution in ViT requires both a decomposable prediction mechanism and a way to relate influential output patch embeddings back to input-space evidence.
In this work, we propose SAP-ViT, a Self-Attributing Patch Vision Transformer for medical image classification. SAP-ViT replaces CLS-based classification with direct aggregation of last-layer patch embeddings. Each patch embedding is assigned a learned aggregation weight, allowing the class prediction to be decomposed into patch-level contributions as part of the forward pass. We use the term self-attributing because attribution is built into the prediction mechanism itself, rather than being produced only by an external post-hoc explainer.
To encourage concise and readable explanations, SAP-ViT applies sparsity regularization to the patch-weight distribution. This encourages the model to rely on a compact set of informative patches rather than distributing evidence diffusely across the entire image. Since self-attention mixes information across tokens, SAP-ViT further introduces an input-space back-mapping mechanism. This module estimates which input patches contribute to influential output patch embeddings, providing an approximate input-space attribution of the model's patch-level decision evidence.
Our contributions are threefold:
First, we propose a patch-additive ViT classifier that predicts directly from last-layer patch embeddings rather than the final CLS representation, enabling explicit decomposition of class predictions into patch-level contributions.
Second, we introduce sparsity regularization on patch weights to encourage the model to rely on a compact set of informative image regions.
Third, we propose an input-space back-mapping mechanism that estimates which input patches contribute to influential output patch embeddings, addressing the token-mixing effect of self-attention.
A. POST-HOC EXPLANATION METHODS
Post-hoc explanation methods explain a trained classifier without modifying its prediction mechanism. Gradient-based methods estimate importance from the sensitivity of a class score to the input or an intermediate representation. Vanilla gradient saliency directly differentiates the class score with respect to the input, integrated Gradients accumulates gradients along a path from a reference input, SmoothGrad averages gradients over perturbed inputs, and Gradient-weighted Class Activation Mapping (Grad-CAM) combines gradients with intermediate activations to produce localization maps [4]–[7]. More recently, LeGrad adapts gradient-based explanation to ViTs by estimating patch relevance through feature-formation sensitivity [8]. Although these approaches do not require changes to the model architecture, their explanations may be noisy, sensitive to the selected baseline or layer, or affected by gradient saturation.
Perturbation-based methods instead estimate importance by measuring how predictions change when parts of the input are modified. Representative approaches include occlusion analysis, Randomized Input Sampling for Explanation (RISE), meaningful perturbation, differentiable patch masking for ViTs, Local Interpretable Model-agnostic Explanations (LIME), and SHapley Additive exPlanations (SHAP) [9]–[12], [29], [30]. Perturbation provides a direct way to examine the model response to selected image regions, but it can be computationally expensive and sensitive to the masking, sampling, superpixel, or reference-distribution strategy. Moreover, heavily perturbed images may depart from the distribution on which the classifier was trained.
For ViTs, attention-based methods exploit the information available in the Transformer architecture. Attention rollout estimates information flow by aggregating attention matrices across layers [15], while transformer attribution and attention-aware relevance propagation combine attention with gradients or relevance-propagation rules to produce class-specific explanations [17], [18]. However, attention can represent information routing rather than contribution to the prediction [13], [14]. More generally, these methods produce explanations after the prediction has been computed, whereas SAP-ViT incorporates a patch-level decomposition into its prediction mechanism.
B. INTERPRETABLE-BY-DESIGN MODELS
Interpretable-by-design models construct predictions from components whose contributions can be inspected directly. BagNet predicts by aggregating evidence from local image regions, making it possible to examine the spatial evidence supporting the output [31]. Neural Additive Models extend additive prediction by learning a nonlinear contribution function for each input feature, while Sum-of-Parts constructs predictions from learned feature groups [32], [33]. These approaches provide important foundations for decomposable prediction, but they are not specifically designed for contextualized ViT patch embeddings, where self-attention repeatedly mixes information across image regions.
Several architectural approaches have been developed specifically for ViT interpretation. The Interpretability-Aware Vision Transformer (IA-ViT) jointly trains an interpreter and predictor to generate an explanation alongside the prediction [19]. Disentangling Visual Transformers aims to make patch representations more interpretable by reducing token entanglement [20], while Prompt-CAM introduces class-specific prompts and uses prompt attention to localize discriminative regions [21]. These methods improve ViT interpretability through a separate interpreter, modified token representations, or prompt attention. In contrast, SAP-ViT uses a linear classification head so that each class logit can be decomposed into patch-specific terms. The contribution to a particular class is jointly determined by the learned patch weight, the corresponding patch embedding, and the class-specific parameters of the classification head.
Recent work has also investigated patch selection for regularizing and interpreting ViTs in medical imaging. Nilsson and Azizpour learn stochastic token selection for echocardiography video analysis and left ventricular ejection fraction prediction, demonstrating the relevance of patch-level selection in medical applications [36]. Their approach interprets the model through the selected patch tokens, whereas SAP-ViT focuses on decomposing class predictions through contextualized last-layer patch embeddings and approximately mapping this evidence back to the input space.
C. INTERPRETABILITY IN ViT
Two properties of ViTs are particularly important for local interpretation. First, a CLS token is commonly used as the global representation for classification. Through self-attention, it interacts with the patch tokens and aggregates information from the image, making a CLS-based prediction difficult to decompose into local contributions [2], [34]. Second, self-attention repeatedly mixes information across patch tokens. Consequently, a last-layer patch embedding may contain information from several input regions rather than only its spatially corresponding input patch. The emergence of high-norm or special-purpose tokens further demonstrates that token representations should not automatically be interpreted as direct spatial evidence [35]. Therefore, the location of an influential output patch token does not necessarily identify the input region responsible for its contribution.
Existing attention- and relevance-based methods attempt to trace information flow through the Transformer [15], [17], [18], but they do not make the class prediction itself additive over patch-level evidence. Conversely, weighting the last-layer patch embeddings and applying a linear classification head produces a decomposable class prediction, but the resulting output embeddings remain contextualized through self-attention. Their weights therefore do not by themselves establish which input regions supplied the information used by each output embedding. This leaves a specific interpretability gap: connecting patch-additive prediction to input-space evidence while explicitly accounting for token mixing. SAP-ViT addresses this gap through patch-additive prediction, sparsity regularization, and input-space back-mapping. The back-mapping provides an approximate association between contextualized output evidence and input patches rather than guaranteed recovery of causal input contributions.
III. METHOD
We propose SAP-ViT, a Self-Attributing Patch Vision Transformer for medical image classification. Figure 1 presents an overview of the complete framework and its three main components: patch-additive prediction, sparsity regularization, and input-space back-mapping. The goal of SAP-ViT is to make the image-level prediction decomposable into patch-level contributions while accounting for token mixing in self-attention.
SAP-ViT does not use the final CLS representation for classification. Given an input image, we split it into a sequence of patch tokens and process them using the pretrained Transformer encoder, in which the CLS token remains present during encoding. The final prediction is computed exclusively from the last-layer patch embeddings. This design allows the class score to be decomposed into contributions from individual output patch tokens.
However, because self-attention mixes information across tokens, an output patch embedding should not be interpreted as representing only its corresponding input patch. To address this issue, SAP-ViT introduces an input-space back-mapping module that estimates which input patches contribute to influential output patch embeddings.
A. PRELIMINARIES
A Vision Transformer (ViT) processes an image as a sequence of patch tokens. Given an input image, we divide it into M non-overlapping patches. Each patch is projected into a feature space and combined with positional encoding, producing the input patch-token sequence
where denotes the embedding of the j-th input patch.
SAP-ViT uses a Transformer encoder with N layers. Each layer takes a sequence of tokens as input and outputs a sequence of updated tokens. Due to the self-attention mechanism, each output token can integrate information from other tokens in the sequence. Therefore, after multiple Transformer layers, each patch embedding becomes context-aware.
Unlike standard ViT classifiers that use the final CLS representation for image-level classification, SAP-ViT computes its prediction exclusively from the final-layer patch embeddings. Suppressing the CLS state for notational simplicity, the patch-token states are written as
where denotes the i-th Transformer layer.
The final-layer patch embeddings are denoted as
Each may contain information not only from its corresponding input patch , but also from other input patches. This token-mixing property is important for SAP-ViT: it motivates both the patch-additive prediction mechanism and the input-space back-mapping module introduced below.
B. PATCH-ADDITIVE PREDICTION
Given the final-layer patch embeddings , SAP-ViT computes the image-level prediction by aggregating patch-level evidence instead of using the CLS representation for classification. For each output patch embedding , a small multilayer perceptron (MLP) produces an unnormalized patch score :
where denotes the patch-scoring MLP.
The scores are normalized using a softmax function to obtain the aggregation weights:
The final image representation is computed as a weighted sum of the final-layer patch embeddings:
The class prediction is obtained using a linear classification head h parameterized by W and b:
where denotes the logit for class , denotes the class-specific weight vector such that is the -th row of , and is the corresponding bias. Because the classification head is linear, the class logit can be decomposed as
where is the contribution of the i-th last-layer patch embedding to class c. The normalized aggregation weight determines how strongly the patch embedding enters the

approximate attribution map
FIGURE 1: Overview of SAP-ViT. The input image is divided into patches and processed by the ViT to obtain contextualized patch embeddings. SAP-ViT learns a weight for each output patch, while sparsity regularization encourages the model to focus on a compact set of informative patches. The weighted patch embeddings are additively aggregated and passed to a linear classification head to obtain the predicted class. Because self-attention mixes information across patches, an influential last-layer patch embedding may contain both local information from its corresponding input patch embedding and contextual information from other image regions, represented by the latent context embedding . This motivates input-space back-mapping, which uses the pair to estimate the contextual representation through a conditional VAE. The recovered context representation is compared with all input patch embeddings, and the resulting matching maps for the top-K output patches are combined to produce an approximate input-space attribution map.
image representation, but it is not alone a class-specific contribution. The contribution to class jointly depends on , the contextualized patch embedding , and the class-specific classifier parameters .
C. SPARSITY REGULARIZATION FOR SELECTIVE EVIDENCE
To make the patch-level evidence easier to interpret, we encourage SAP-ViT to rely on a compact set of informative patch tokens rather than distributing the aggregation weights diffusely across all patches. The strength of this sparsity bias is controlled by a regularization hyperparameter.
We apply an entropy regularization term to the normalized aggregation weights:
The final classifier-training objective is
where is the classification loss and controls the strength of sparsity regularization.
Minimizing the entropy encourages the aggregation-weight distribution to become more concentrated, so that a smaller number of output patch embeddings receive high weights. This improves the readability of the patch-level evidence while still allowing the model to use multiple patches when necessary.
D. INPUT-SPACE BACK-MAPPING
The patch-additive prediction mechanism identifies influential final-layer patch embeddings. However, due to self-attention, an influential output patch embedding should not be interpreted as representing only its corresponding input patch. For the k-th input patch embedding , the Transformer encoder produces the corresponding final-layer embedding . While represents the local input patch, may also contain contextual information from other patches. Therefore, when receives a high aggregation weight, we further estimate which input patches are associated with the contextual information contained in this output embedding.
SAP-ViT introduces an input-space back-mapping module for this purpose. Given the pair , the module estimates a context embedding that captures information in beyond the local input patch . The embeddings , , and have the same dimensionality. We model this context estimation using a conditional variational autoencoder (conditional VAE) [22], [23]. After training, the projected encoder mean is compared with all input patch embeddings to obtain input-space match scores. A higher match score indicates that an input patch is more aligned with the contextual signal represented in .
1 ) Conditional VAE
We model as a function of its local input patch and a latent context embedding . The encoder produces a Gaussian posterior, and the decoder reconstructs from . The training objective of conditional VAE consists of a reconstruction term and a Kullback–Leibler (KL) regularization term:
(9)
where is the Gaussian prior and controls the strength of the KL regularization.
2 ) Alignment
The latent embedding learned by the conditional VAE is not guaranteed to be directly comparable with the input patch embeddings, because latent variables are only identifiable up to transformations. Consequently, cosine similarity between and input tokens may not be meaningful without additional constraints. Since our goal is to retrieve input patches aligned with the contextual information in , we introduce an alignment term that places the estimated context embedding in the input-token space.
Specifically, we take the encoder mean and pass it through a lightweight projection head that maps the latent representation into the input-token space. The alignment loss penalizes the angular discrepancy between the projected context representation and the corresponding input patch embedding:
The full objective for the back-mapping module is
where controls the strength of the alignment term. The first term encourages the estimated context embedding to reconstruct together with the local patch embedding , while the alignment term provides an inductive bias that makes the estimated context comparable to input patch embeddings.
3 ) Scoring
After training the back-mapping module, we compare the projected encoder mean for the k-th output patch with each input patch embedding :
The score measures the alignment between the j-th input patch and the projected latent representation inferred from the output patch embedding . We use these scores to produce an input-space attribution map. This back-mapping should be interpreted as an approximate attribution mechanism, rather than a guaranteed recovery of the true causal contribution of each input patch.
For input-space back-mapping, we select output patches using the normalized aggregation weights . These weights are input-dependent but class-independent and quantify the
Algorithm 1 Training and inference workflow of SAP-ViT
Input: Training set D, test image x, and number of selected output patches K
Output: Predicted class and input-space attribution map A
1: Train SAP-ViT using patch-additive prediction with sparsity regularization by minimizing the objective in Eq. (8).
2: Freeze the trained SAP-ViT and train the input-space back-mapping module by minimizing the objective in Eq. (11).
3: For x, compute the class prediction and normalized patch weights according to Eqs. (2)–(5).
4: Select the K highest-weight last-layer output patches according to Eq. (13).
5: for each selected output patch do
6: Compute its context embedding and input-patch matching scores according to Eq. (12).
7: end for
8: Obtain A by summing the matching-score maps according to Eq. (13).
9: return and A
relative importance assigned to each patch when constructing the pooled image representation. Let K denote the hyperparameter controlling the number of selected last-layer output patches, and let
where K contains the indices of the K highest-weight output patches and is the aggregated attribution score of the j-th input patch.
Algorithm 1 summarizes the complete training and inference workflow. SAP-ViT is trained first, and its parameters are then frozen while the input-space back-mapping module is trained. During inference, the K highest-weight output patches are selected, and their input-space matching-score maps are summed to produce the final attribution map.
IV. EXPERIMENT
A. SETUP
1 ) Datasets
We evaluate SAP-ViT on four public medical imaging datasets spanning three imaging modalities: brain magnetic resonance imaging (MRI), chest X-ray, and ultrasound. The datasets cover both binary and multi-class classification tasks. The brain tumor MRI dataset [24] is a four-class classification task including glioma, meningioma, no tumor, and pituitary tumor. The COVID chest X-ray dataset [25], [26] is a four-class task including COVID, lung opacity, normal, and viral pneumonia. The pneumonia chest X-ray dataset [27] is a binary classification task including normal and pneumonia. The breast ultrasound dataset [28] is a three-class task including normal, benign, and malignant.
For each dataset, we resize all images to a fixed resolution and apply the same preprocessing pipeline across SAP-ViT
TABLE 1: Dataset statistics.
| Dataset | Modality | # Classes | # Images |
|---|---|---|---|
| Brain tumor MRI | MRI | 4 | 7023 |
| COVID chest X-ray | Chest X-ray | 4 | 21165 |
| Pneumonia chest X-ray | Chest X-ray | 2 | 5856 |
| Breast ultrasound | Ultrasound | 3 | 780 |
and all baselines. We split each dataset into training, validation, and test sets, and report results on the test set. Table 1 summarizes the number of classes and the number of images used for each dataset.
2) Predictive and explainability baselines
For predictive-performance comparison, we include two model-level baselines: a standard CLS-based vanilla ViT and IA-ViT [19]. The vanilla ViT uses the same Transformer configuration and training protocol as SAP-ViT but retains the CLS token and the standard CLS-based classification head. IA-ViT jointly trains an interpreter and a predictor. SAP-ViT, vanilla ViT, and IA-ViT are compared in terms of classification performance.
For explanation evaluation, we compare SAP-ViT and IA-ViT with four post-hoc explanation methods: Grad-CAM [7], attention rollout [15], LIME [29], and SHAP [30]. All four post-hoc methods are applied to the same trained vanilla ViT described above. They therefore do not constitute separate predictive models and are used solely for explanation evaluation. The classification performance of their shared vanilla ViT backbone is reported only once.
To support reproducibility, the complete implementation code and all hyperparameter configurations for SAP-ViT are publicly available in our GitHub repository.
B. RESULTS
1) Model performance
Table 2 reports classification accuracy for the models evaluated under the same experimental protocol. Among these implemented models, SAP-ViT achieves the highest mean accuracy on all four datasets, including brain tumor MRI, COVID chest X-ray, pneumonia chest X-ray, and breast ultrasound. Additional classification metrics are reported in Appendix D. As shown in Table 8, SAP-ViT also achieves the highest mean macro-averaged precision, sensitivity, and F1 score among the implemented models on all four datasets.
Compared with IA-ViT, SAP-ViT obtains substantially higher accuracy on all four datasets. This indicates that the proposed patch-level self-attributing design does not compromise predictive performance compared with the interpretable-by-design baseline. Compared with the vanilla ViT model used for the post-hoc explanation baselines, SAP-ViT also achieves higher accuracy across all datasets, showing that the proposed architecture remains competitive with standard ViT-based classification while providing intrinsic patch-level attribution.
To contextualize SAP-ViT's predictive performance, Appendix C compares SAP-ViT with representative recent stud- ies [37]–[39] evaluated on the same brain tumor MRI dataset. Despite differences in data splits, preprocessing, and training protocols, SAP-ViT achieves classification performance comparable to that reported by these studies. Its principal advantage lies in combining competitive predictive performance with an intrinsic patch-attribution mechanism, rather than universally outperforming existing classifiers in accuracy. We next evaluate the faithfulness of the resulting attribution maps.
2) Explanation evaluation
We evaluate explanation faithfulness using insertion (I), deletion (D), and their difference (I - D). A higher insertion score indicates that the most important regions identified by the explanation are sufficient to recover the model prediction when progressively inserted into a masked image. A lower deletion score indicates that removing the most important regions more strongly suppresses the prediction. Therefore, a larger I - D gap reflects explanations that are both more sufficient under insertion and more necessary under deletion.
These perturbation-based metrics evaluate explanation faithfulness with respect to the model's prediction under the selected insertion and deletion protocol. They do not establish that the highlighted regions are clinically correct, causally related to the disease, or consistent with expert interpretation. Establishing clinical validity would require expert assessment or ground-truth lesion annotations, which are beyond the scope of this study.
As shown in Table 3, SAP-ViT achieves the highest mean across all datasets, indicating the most consistent overall explanation quality among the evaluated methods. In addition, SAP-ViT obtains the best score on three of four datasets: brain tumor MRI, COVID chest X-ray, and breast ultrasound.
Compared with the interpretable-by-design baseline IA-ViT, SAP-ViT produces substantially larger gaps on all datasets. IA-ViT obtains near-zero or negative values, suggesting that its explanation maps do not consistently identify regions that are both sufficient and necessary for the prediction. In contrast, SAP-ViT explicitly decomposes the prediction into sparse patch-level contributions, leading to more discriminative attribution maps.
Compared with post-hoc baselines, SAP-ViT also shows stronger overall performance. It outperforms LIME, SHAP, Grad-CAM, and Rollout on brain tumor MRI and COVID chest X-ray, and achieves the best result on breast ultrasound. These results suggest that integrating attribution into the prediction mechanism can improve explanation faithfulness while maintaining competitive performance.
SAP-ViT does not achieve the best score on the pneumonia chest X-ray dataset. This suggests that, although SAP-ViT provides the strongest overall performance across datasets, its sparse patch-level attribution mechanism may not be equally advantageous in all imaging settings. Pneumonia chest X-ray may represent a case where discriminative evidence is more spatially distributed, making it less aligned
TABLE 2: Model performance measured by classification accuracy.
| Brain tumor MRI | COVID chest X-ray | Pneumonia chest X-ray | Breast ultrasound | |
|---|---|---|---|---|
| SAP-ViT | 0.993 ± 0.003 | 0.955 ± 0.003 | 0.909 ± 0.019 | 0.878 ± 0.019 |
| IA-ViT | 0.905 ± 0.020 | 0.658 ± 0.066 | 0.713 ± 0.067 | 0.559 ± 0.006 |
| Vanilla ViT (post-hoc backbone) | 0.973 ± 0.008 | 0.929 ± 0.006 | 0.888 ± 0.025 | 0.780 ± 0.074 |
TABLE 3: Explanation evaluation. I denotes the insertion score, D denotes the deletion score, and I - D represents the gap between insertion and deletion. The last column reports the mean I - D across all datasets.
| Brain tumor MRI | COVID chest X-ray | Pneumonia chest X-ray | Breast ultrasound | Mean I - D | ||
|---|---|---|---|---|---|---|
| SAP-ViT | D | 0.400 ± 0.020 | 0.449 ± 0.025 | 0.659 ± 0.013 | 0.522 ± 0.024 | - |
| I | 0.733 ± 0.007 | 0.677 ± 0.033 | 0.789 ± 0.025 | 0.693 ± 0.022 | - | |
| I - D | 0.333 ± 0.022 | 0.228 ± 0.035 | 0.130 ± 0.024 | 0.171 ± 0.012 | 0.216 | |
| IA-ViT | D | 0.423 ± 0.015 | 0.425 ± 0.043 | 0.580 ± 0.056 | 0.408 ± 0.010 | - |
| I | 0.416 ± 0.020 | 0.439 ± 0.031 | 0.577 ± 0.023 | 0.412 ± 0.025 | - | |
| I - D | -0.007 ± 0.013 | 0.014 ± 0.031 | -0.003 ± 0.047 | 0.004 ± 0.027 | 0.002 | |
| LIME | D | 0.380 ± 0.015 | 0.363 ± 0.042 | 0.608 ± 0.040 | 0.502 ± 0.059 | - |
| I | 0.518 ± 0.041 | 0.484 ± 0.067 | 0.856 ± 0.038 | 0.568 ± 0.020 | - | |
| I - D | 0.138 ± 0.030 | 0.121 ± 0.047 | 0.248 ± 0.066 | 0.066 ± 0.048 | 0.143 | |
| SHAP | D | 0.401 ± 0.024 | 0.413 ± 0.051 | 0.714 ± 0.008 | 0.581 ± 0.015 | - |
| I | 0.490 ± 0.031 | 0.481 ± 0.063 | 0.791 ± 0.030 | 0.568 ± 0.034 | - | |
| I - D | 0.089 ± 0.010 | 0.068 ± 0.021 | 0.076 ± 0.028 | -0.013 ± 0.024 | 0.055 | |
| Grad-CAM | D | 0.402 ± 0.023 | 0.461 ± 0.060 | 0.694 ± 0.033 | 0.506 ± 0.062 | - |
| I | 0.519 ± 0.053 | 0.515 ± 0.031 | 0.881 ± 0.036 | 0.669 ± 0.025 | - | |
| I - D | 0.117 ± 0.039 | 0.055 ± 0.049 | 0.187 ± 0.049 | 0.163 ± 0.051 | 0.131 | |
| Rollout | D | 0.371 ± 0.018 | 0.452 ± 0.048 | 0.689 ± 0.019 | 0.533 ± 0.034 | - |
| I | 0.554 ± 0.035 | 0.595 ± 0.053 | 0.825 ± 0.010 | 0.599 ± 0.036 | - | |
| I - D | 0.183 ± 0.022 | 0.143 ± 0.044 | 0.136 ± 0.017 | 0.067 ± 0.014 | 0.132 | |
with explanations that emphasize a small number of highly influential patches.
To further examine whether this dataset-dependent behavior is related to image characteristics, we conducted a model-independent patch-level radiomics-style concentration analysis. For each dataset, we sampled up to 500 images, computed simple patch-level texture features, summarized their spatial concentration per image, and averaged the resulting metrics at the dataset level. We report normalized entropy and Gini coefficient as complementary measures. Higher normalized entropy indicates a more spatially diffuse patch-level texture distribution, whereas higher Gini coefficient indicates stronger spatial concentration.
As shown in Table 4, breast ultrasound has the lowest normalized entropy and the highest Gini coefficient, followed by brain tumor MRI, indicating that their patch-level texture responses are relatively spatially concentrated. SAP-ViT achieves the best I - D scores on both datasets, which is consistent with its main advantage: sparse patch aggregation can isolate a compact set of influential output patches, while input-space back-mapping approximately relates their contextualized information to the corresponding input regions.
In contrast, both chest X-ray datasets exhibit higher normalized entropy and lower Gini values, indicating more spa-

(d) SHAP
(e) GradCAM
(f) Rollout
FIGURE 2: Qualitative attribution comparison on a Brain Tumor MRI example. The ground-truth label is meningioma. SAP-ViT produces a compact attribution map concentrated around the tumor region, while the baseline methods generate either less localized or more diffuse saliency patterns across surrounding anatomical structures and background regions.
tially diffuse texture responses. Pneumonia chest X-ray has the highest normalized entropy and the lowest Gini coefficient, providing one possible explanation for why SAP-
TABLE 4: Model-independent patch-level radiomics-style concentration analysis. Entropy measures the spatial spread of patch-level texture responses, where higher values indicate more diffuse responses. Gini measures concentration, where higher values indicate stronger spatial concentration.
| Dataset | Entropynorm | Gini |
|---|---|---|
| Brain tumor MRI | 0.901 | 0.476 |
| COVID chest X-ray | 0.949 | 0.333 |
| Pneumonia chest X-ray | 0.953 | 0.322 |
| Breast ultrasound | 0.705 | 0.488 |
TABLE 5: Ablation study of SAP-ViT on the Brain Tumor MRI dataset.
| Variant | Deletion ↓ | Insertion ↑ | |
|---|---|---|---|
| SAP-ViT w/o sparsity | |||
| SAP-ViT w/o alignment | |||
| Full SAP-ViT |
ViT does not achieve the best score on this dataset: its sparsity bias may under-represent information distributed across broad image regions. Nevertheless, SAP-ViT achieves the best score on the COVID chest X-ray dataset despite its relatively diffuse texture responses. This result indicates that SAP-ViT is not restricted to strongly localized image patterns and can still identify compact, prediction-relevant evidence within globally diffuse images.
The radiomics-style analysis is complementary rather than conclusive, because these model-independent texture statistics do not directly measure class-discriminative evidence. Overall, the results suggest that SAP-ViT is particularly advantageous when informative patterns can be represented by a compact set of patches, while remaining effective across datasets with substantially different spatial characteristics.
3) Ablation study
Table 5 reports the ablation study on the Brain Tumor MRI dataset. Removing the sparsity regularization leads to a substantial drop in explanation quality, with the score becoming negative. This indicates that without sparsity, the model no longer identifies compact and discriminative evidence regions, and the resulting attribution becomes less faithful under insertion and deletion evaluation.
Removing the alignment term also degrades performance, although the drop is less severe than removing sparsity. This suggests that the alignment component is important for making the recovered context embedding comparable to the input patch space, thereby improving the quality of input-space back-mapping. The full SAP-ViT achieves the best deletion, insertion, and scores, showing that both sparsity and alignment contribute to the final explanation quality.
To examine whether these findings generalize across datasets, we further conduct the same ablation study on COVID chest X-ray, pneumonia chest X-ray, and breast ultrasound. The corresponding results are reported in Appendix A, specifically in Table 6. The results show a consistent trend across all three datasets: removing sparsity causes the largest degradation, while removing alignment also reduces explanation quality compared with the full SAP-ViT.
4) Qualitative attribution analysis
Figure 2 shows a qualitative comparison on the Brain Tumor MRI dataset. The example contains a visible tumor region in the left intracranial area. SAP-ViT produces a compact and highly localized attribution map, with the strongest response concentrated around the tumor region and limited activation elsewhere. This suggests that SAP-ViT identifies a small set of discriminative patches that are spatially aligned with the lesion.
In contrast, IA-ViT also produces sparse high-saliency regions, but these regions are less aligned with the tumor and appear around regions outside the visually apparent tumor area, such as the skull boundary and lower head region. LIME highlights a broader superpixel region that partially overlaps with the tumor, but the attribution also extends to surrounding brain areas, making the localization less precise. SHAP produces fragmented and widespread superpixel regions across the image, including large areas outside the lesion and background, which makes the explanation harder to interpret as localized medical evidence.
Grad-CAM and Rollout generate smoother heatmaps, but their saliency is more diffuse than SAP-ViT. Grad-CAM assigns high responses to multiple regions around the skull boundary and image periphery, while Rollout spreads attribution over a larger part of the brain and nearby anatomical structures. Although these methods capture some relevant image regions, their explanations are less spatially specific. Overall, this qualitative example shows that SAP-ViT provides more localized and visually interpretable attribution than the evaluated baselines.
Additional qualitative comparisons for other datasets are provided in Appendix B. Specifically, Figs. 3, 4, and 5 present the corresponding attribution comparisons. Across these examples, SAP-ViT generally produces more compact attribution patterns, whereas the baseline methods tend to generate less localized or more diffuse responses.
C. LIMITATIONS AND APPLICABILITY
SAP-ViT is most applicable when the discriminative evidence can be represented by a relatively compact set of image regions. Its entropy regularization introduces a sparsity bias rather than an assumption that is universally valid. When evidence is spatially distributed or multifocal, strong sparsity may suppress complementary regions and reduce explanation faithfulness, as suggested by the pneumonia chest X-ray results. The regularization strength therefore represents a dataset-dependent trade-off between attribution concentration and coverage of distributed evidence. Furthermore, input-space back-mapping provides approximate associations rather than causal attribution, while insertion and deletion evaluate faithfulness to model behavior rather than clinical correctness. Finally, the present evaluation is limited to four public datasets spanning MRI, chest X-ray, and ultrasound; further evaluation is required before generalizing the findings to other medical imaging settings.
V. CONCLUSION
In this paper, we proposed SAP-ViT, a self-attributing Vision Transformer for medical image classification. Rather than relying on a global CLS token for prediction, SAP-ViT directly aggregates last-layer patch embeddings, enabling class predictions to be decomposed into patch-level contributions. To further improve interpretability, SAP-ViT incorporates a sparsity regularization term that encourages the model to focus on a compact set of informative patches, together with an input-space back-mapping mechanism that mitigates the ambiguity introduced by token mixing in self-attention.
Experiments on multiple medical imaging datasets demonstrate that SAP-ViT maintains strong classification performance while improving the interpretability of ViT predictions. Overall, SAP-ViT provides a favorable trade-off between predictive accuracy and interpretability, making it a promising framework for transparent ViT-based medical image classification.
APPENDIX A ADDITIONAL ABLATION RESULTS
Table 6 reports the ablation results on the three additional datasets. Consistent with the brain-tumor MRI results presented in the main text, the complete SAP-ViT outperforms the variants without sparsity regularization or alignment.
TABLE 6: Additional ablation studies of SAP-ViT on the COVID chest X-ray, Pneumonia chest X-ray, and Breast Ultrasound datasets.
| Variant | Deletion ↓ | Insertion ↑ | |
|---|---|---|---|
| COVID chest X-ray | |||
| SAP-ViT w/o sparsity | |||
| SAP-ViT w/o alignment | |||
| Full SAP-ViT | |||
| Pneumonia chest X-ray | |||
| SAP-ViT w/o sparsity | |||
| SAP-ViT w/o alignment | |||
| Full SAP-ViT | |||
| Breast ultrasound | |||
| SAP-ViT w/o sparsity | |||
| SAP-ViT w/o alignment | |||
| Full SAP-ViT | |||
APPENDIX B ADDITIONAL QUALITATIVE ATTRIBUTION EXAMPLES
Figures 3, 4, and 5 provide qualitative attribution comparisons on the three additional datasets. Within each comparison, all methods are applied to the same input image. These examples illustrate the spatial characteristics of the attribution maps and are intended to complement the dataset-level quantitative evaluation.

FIGURE 3: Qualitative attribution comparison on a chest radiograph from the COVID chest X-ray dataset with the ground-truth label lung opacity. SAP-ViT produces a compact attribution map concentrated in an upper-lung region exhibiting visible opacity, whereas the baseline methods generate less localized or more diffuse saliency patterns across the lungs, surrounding anatomical structures, and background.

FIGURE 4: Qualitative attribution comparison on an example from the pneumonia chest X-ray dataset with the ground-truth label pneumonia. SAP-ViT produces a compact attribution map concentrated in an upper-lung region exhibiting visible opacity, whereas the baseline methods generate less localized or more diffuse saliency patterns across the lungs, surrounding anatomical structures, and background.
APPENDIX C COMPARISON WITH PUBLISHED CLASSIFICATION RESULTS
Table 7 compares SAP-ViT with representative recent classification results reported on the same brain tumor MRI dataset. Because the studies use different experimental protocols, the values provide literature context rather than a controlled head-to-head comparison.
APPENDIX D ADDITIONAL CLASSIFICATION METRICS
Table 8 supplements the accuracy results in Table 2 with macro-averaged precision, sensitivity, and F1 score. Macro-
(a) SAP-ViT

(b) IA-ViT
(c) LIME
(d) SHAP
(e) GradCAM
(f) Rollout
0.6
0.4
0.2
0.0
FIGURE 5: Qualitative attribution comparison on a breast ultrasound example. The ground-truth label is malignant. SAP-ViT produces a compact attribution map concentrated around the lesion, with its strongest hotspot overlapping the boundary of the supplied tumor mask. In contrast, the baseline methods generate either less localized or more diffuse saliency patterns across the surrounding tissue and background regions.
TABLE 7: Comparison with representative published classification results.
| Study | Model | Accuracy (%) |
|---|---|---|
| Disci et al. [39] | Xception | 98.73 |
| Haque et al. [38] | NeuroNet19 | 99.30 |
| Shahin [37] | Fine-tuned ResNet34 | 99.66 |
| SAP-ViT (ours) | SAP-ViT | 99.30 ± 0.30 |
averaging assigns equal importance to every class, providing a class-balanced assessment of predictive performance.
TABLE 8: Additional classification metrics for models evaluated under the same experimental protocol.
| Model | Precision | Sensitivity | F1 |
|---|---|---|---|
| Brain tumor MRI | |||
| SAP-ViT | 0.992 ± 0.003 | 0.992 ± 0.003 | 0.992 ± 0.003 |
| IA-ViT | 0.903 ± 0.020 | 0.900 ± 0.022 | 0.901 ± 0.021 |
| Vanilla ViT | 0.972 ± 0.008 | 0.971 ± 0.009 | 0.971 ± 0.009 |
| COVID chest X-ray | |||
| SAP-ViT | 0.965 ± 0.004 | 0.959 ± 0.004 | 0.962 ± 0.002 |
| IA-ViT | 0.560 ± 0.193 | 0.495 ± 0.151 | 0.462 ± 0.176 |
| Vanilla ViT | 0.944 ± 0.003 | 0.929 ± 0.009 | 0.935 ± 0.006 |
| Pneumonia chest X-ray | |||
| SAP-ViT | 0.934 ± 0.011 | 0.880 ± 0.026 | 0.897 ± 0.024 |
| IA-ViT | 0.672 ± 0.208 | 0.644 ± 0.108 | 0.616 ± 0.159 |
| Vanilla ViT | 0.920 ± 0.013 | 0.853 ± 0.034 | 0.872 ± 0.032 |
| Breast ultrasound | |||
| SAP-ViT | 0.871 ± 0.018 | 0.865 ± 0.028 | 0.866 ± 0.019 |
| IA-ViT | 0.215 ± 0.065 | 0.341 ± 0.018 | 0.256 ± 0.040 |
| Vanilla ViT | 0.805 ± 0.051 | 0.721 ± 0.127 | 0.733 ± 0.111 |
REFERENCES
[1] Khawaji, A., Martin, R.J. and Daspin, D., 2025. High-Resolution Medical Image Generation With Leak-Prevention Mechanism Using Quantum Transformer Learning. IEEE Access, 13, pp.206381-206401.
[2] Dosovitskiy, A., 2020. An image is worth words: Transformers for image recognition at scale. arXiv preprint arXiv:2010.11929.
[3] Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A.N., Kaiser, L. and Polosukhin, I., 2017. Attention is all you need. Advances in neural information processing systems, 30.
[4] Simonyan, K., Vedaldi, A. and Zisserman, A., 2013. Deep inside convolutional networks: Visualising image classification models and saliency maps. arXiv preprint arXiv:1312.6034.
[5] Sundararajan, M., Taly, A. and Yan, Q., 2017, July. Axiomatic attribution for deep networks. In International conference on machine learning (pp. 3319-3328). PMLR.
[6] Smilkov, D., Thorat, N., Kim, B., Viégas, F. and Wattenberg, M., 2017. Smoothgrad: removing noise by adding noise. arXiv preprint arXiv:1706.03825.
[7] Selvaraju, R.R., Cogswell, M., Das, A., Vedantam, R., Parikh, D. and Batra, D., 2017. Grad-cam: Visual explanations from deep networks via gradient-based localization. In Proceedings of the IEEE international conference on computer vision (pp. 618-626).
[8] Bousselham, W., Boggust, A., Chaybouti, S., Strobelt, H. and Kuehne, H., 2025. Legrad: An explainability method for vision transformers via feature formation sensitivity. In Proceedings of the IEEE/CVF International Conference on Computer Vision (pp. 20336-20345).
[9] Zeiler, M.D. and Fergus, R., 2014, September. Visualizing and understanding convolutional networks. In European conference on computer vision (pp. 818-833). Cham: Springer International Publishing.
[10] Petsiuk, V., Das, A. and Saenko, K., 2018. Rise: Randomized input sampling for explanation of black-box models. arXiv preprint arXiv:1806.07421.
[11] Fong, R.C. and Vedaldi, A., 2017. Interpretable explanations of black boxes by meaningful perturbation. In Proceedings of the IEEE international conference on computer vision (pp. 3429-3437).
[12] Nalmpantis, A., Panagiotopoulos, A., Gkountouras, J., Papakostas, K. and Aziz, W., 2023. Vision difmask: Faithful interpretation of vision transformers with differentiable patch masking. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (pp. 3756-3763).
[13] Jain, S. and Wallace, B.C., 2019, June. Attention is not explanation. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers) (pp. 3543-3556).
[14] Serrano, S. and Smith, N.A., 2019, July. Is attention interpretable?. In Proceedings of the 57th annual meeting of the association for computational linguistics (pp. 2931-2951).
[15] Abnar, S. and Zuidema, W., 2020. Quantifying attention flow in transformers. arXiv preprint arXiv:2005.00928.
[16] Bach, S., Binder, A., Montavon, G., Klauschen, F., Müller, K.R. and Samek, W., 2015. On pixel-wise explanations for non-linear classifier decisions by layer-wise relevance propagation. PloS one, 10(7), p.e0130140.
[17] Chefer, H., Gur, S. and Wolf, L., 2021. Transformer interpretability beyond attention visualization. In Proceedings of the IEEE/CVF conference on computer vision and pattern recognition (pp. 782-791).
[18] Achtibat, R., Hatefi, S.M.V., Dreyer, M., Jain, A., Wiegand, T., Lapuschkin, S. and Samek, W., 2024. Attnlrp: attention-aware layer-wise relevance propagation for transformers. arXiv preprint arXiv:2402.05602.
[19] Qiang, Y., Li, C., Khanduri, P. and Zhu, D., 2023. Interpretability-aware vision transformer. arXiv preprint arXiv:2309.08035.
[20] Jeanneret, G., Simon, L. and Jurie, F., 2025. Disentangling Visual Transformers: Patch-level Interpretability for Image Classification. In Proceedings of the Computer Vision and Pattern Recognition Conference (pp. 2679-2689).
[21] Chowdhury, A., Paul, D., Mai, Z., Gu, J., Zhang, Z., Mehrab, K.S., Campolongo, E.G., Rubenstein, D., Stewart, C.V., Karpatne, A. and Berger-Wolf, T., 2025. Prompt-CAM: Making Vision Transformers Interpretable for Fine-Grained Analysis. In Proceedings of the Computer Vision and Pattern Recognition Conference (pp. 4375-4385).
[22] Diederik, P.K. and Max, W., 2019. An introduction to variational autoencoders. Foundations and Trends® in Machine Learning, 12(4), pp.307-392.
[23] Sohn, K., Lee, H. and Yan, X., 2015. Learning structured output representation using deep conditional generative models. Advances in neural information processing systems, 28.
[24] Msoud Nickparvar. (2021). Brain Tumor MRI Dataset [Data set]. Kaggle. https://doi.org/10.34740/KAGGLE/DSV/2645886
[25] M.E.H. Chowdhury, T. Rahman, A. Khandakar, R. Mazhar, M.A. Kadir, Z.B. Mahbub, K.R. Islam, M.S. Khan, A. Iqbal, N. Al-Emadi, M.B.I. Reaz, M. T. Islam, “Can AI help in screening Viral and COVID-19 pneumonia?” IEEE Access, Vol. 8, 2020, pp. 132665 - 132676.
[26] Rahman, T., Khandakar, A., Qiblawey, Y., Tahir, A., Kiranyaz, S., Kashem, S.B.A., Islam, M.T., Maadeed, S.A., Zughaier, S.M., Khan, M.S. and Chowdhury, M.E., 2020. Exploring the Effect of Image Enhancement Techniques on COVID-19 Detection using Chest X-ray Images. arXiv preprint arXiv:2012.02238.
[27] Kermany, Daniel; Zhang, Kang; Goldbaum, Michael (2018), “Large Dataset of Labeled Optical Coherence Tomography (OCT) and Chest X-Ray Images”, Mendeley Data, V3, doi: 10.17632/rscbjbr9sj.3
[28] Al-Dhabyani, W., Gomaa, M., Khaled, H. and Fahmy, A., 2020. Dataset of breast ultrasound images. Data in brief, 28, p.104863.
[29] Ribeiro, M.T., Singh, S. and Guestrin, C., 2016, August. " Why should i trust you?" Explaining the predictions of any classifier. In Proceedings of the 22nd ACM SIGKDD international conference on knowledge discovery and data mining (pp. 1135-1144).
[30] Lundberg, S.M. and Lee, S.I., 2017. A unified approach to interpreting model predictions. Advances in neural information processing systems, 30.
[31] Brendel, W. and Bethge, M., 2019. Approximating cnns with bag-of-local-features models works surprisingly well on imagenet. arXiv preprint arXiv:1904.00760.
[32] Agarwal, R., Melnick, L., Frosst, N., Zhang, X., Lengerich, B., Caruana, R. and Hinton, G.E., 2021. Neural additive models: Interpretable machine learning with neural nets. Advances in neural information processing systems, 34, pp.4699-4711.
[33] You, W., Qu, H., Gatti, M., Jain, B. and Wong, E., 2025, October. Sum-of-parts: Self-attributing neural networks with end-to-end learning of feature groups. In Forty-second International Conference on Machine Learning.
[34] Marouani, A., Siméoni, O., Jégou, H., Bojanowski, P. and Vo, H.V., 2026. Revisiting [cls] and patch token interaction in vision transformers. arXiv preprint arXiv:2602.08626.
[35] Darcet, T., Oquab, M., Mairal, J. and Bojanowski, P., 2024, May. Vision transformers need registers. In International conference on learning representations (Vol. 2024, pp. 2632-2652).
[36] Nilsson, A. and Azizpour, H., 2024, July. Regularizing and Interpreting Vision Transformer by Patch Selection on Echocardiography Data. In CHIL (pp. 155-168).
[37] Shahin, A., 2025. Fine-tuned ResNet34 for efficient brain tumor classification. Scientific Reports, 15(1), p.36910.
[38] Haque, R., Hassan, M.M., Bairagi, A.K. and Shariful Islam, S.M., 2024. NeuroNet19: an explainable deep neural network model for the classification of brain tumors using magnetic resonance imaging data. Scientific reports, 14(1), p.1524.
[39] Disci, R., Gurcan, F. and Soylu, A., 2025. Advanced brain tumor classification in MR images using transfer learning and pre-trained deep CNN models. Cancers, 17(1), p.121.

WEI ZHANG received the B.Sc. degree in Computer Science from Xidian University, China, and the M.Sc. degree in Computer Science from Leibniz University Hannover, Germany. He is currently pursuing the Ph.D. degree with the Faculty of Electrical Engineering and Computer Science at Leibniz University Hannover. He is working as a Research Assistant with the L3S Research Center, Hannover. He is involved in the CAIMed project (Lower Saxony Center for AI and Causal Methods in Medicine), where he focuses on uncovering the underlying biological mechanisms of post-acute infection symptoms, specifically long COVID. His research interests include interpretability of neural networks, particularly in the areas of graph neural networks and vision transformers; the integration of causality and reinforcement learning; and foundation models in biomedicine, with a focus on predicting gene expression profiles under gene perturbations.

WOLFGANG NEJDL was born in 1960. He received the Dipl.Ing. and Dr.Techn. degrees in computer science from Vienna University of Technology, in 1984 and 1988, respectively. He has been a Full Professor of computer science with Leibniz University Hannover, since 1995. He was an Assistant Professor in Vienna, from 1988 to 1992, and an Associate Professor at RWTH Aachen University, from 1992 to 1995. He was a Visiting Researcher/a Professor with Xerox PARC, Stanford University, the University of Illinois at UrbanaChampaign, EPFL Lausanne, PUC Rio, Trento, and Politecnico di Milano. He heads the L3S Research Center, www.L3S.de, and the Data Science Institute/Knowledge-Based Systems at Leibniz University. From 2014 to 2019, he was a Principal Investigator of the ERC Advanced Grant ALEXANDRIA, where he worked on foundations for temporal search, exploration, and analytics in web archives. He has published more than 440 scientific articles listed at DBLP, with an H-index (based on Google Scholar) of 78. His research interests include information retrieval/search, web science, artificial intelligence, social and semantic web, digital libraries, and technology enhanced learning.

MING TANG received the M.Sc. degree in informatics from the Free University of Berlin, Germany, and the Ph.D. degree in systems biology from the Johns Hopkins University School of Medicine, USA. She is currently a Group Leader with the L3S Research Center, Faculty of Electrical Engineering and Computer Science, Leibniz University Hannover. Her research interests include biomedical foundation models and agentic AI for biomedicine. She is involved in the CAIMed project (AI and Causal Methods in Medicine) and was previously involved in the International Future Lab for Artificial Intelligence, funded by the German Federal Ministry of Education and Research (BMBF).