Abstract
Traditional supervised learning tasks require a label for every instance in the training set, but in many real-world applications, labels are only available for collections (bags) of instances. This problem setting, known as multiple instance learning (MIL), is particularly relevant in the medical domain, where high-resolution images are split into smaller patches, but labels apply to the image as a whole. Recent MIL models are able to capture correspondences between patches by employing self-attention, allowing them to weigh each patch differently based on all other patches in the bag. However, these approaches still do not consider the relative spatial relationships between patches within the larger image, which is especially important in computational pathology. To this end, we introduce a novel MIL model with distance-aware self-attention (DAS-MIL), which explicitly takes into account relative spatial information when modelling the interactions between patches. Unlike existing relative position representations for self-attention which are discrete, our approach introduces continuous distance-dependent terms into the computation of the attention weights, and is the first to apply relative position representations in the context of MIL. We evaluate our model on a custom MNIST-based MIL dataset that requires the consideration of relative spatial information, as well as on CAMELYON16, a publicly available cancer metastasis detection dataset, where we achieve a test AUROC score of 0.91. On both datasets, our model outperforms existing MIL approaches that employ absolute positional encodings, as well as existing relative position representation schemes applied to MIL.
Introduction
In domains such as computational pathology, data is often organized as a "bag" of instances—for example, a high-resolution biopsy slide composed of thousands of individual patches. While a label may exist for the entire slide (e.g., "cancerous"), individual patch-level labels are typically unavailable. This Multiple Instance Learning (MIL) challenge is complicated by the fact that biological significance often arises from the spatial interaction between patches, rather than their isolated features.
Standard self-attention mechanisms allow patches to interact but frequently ignore their relative spatial orientation. While absolute positional encodings are common in other Transformer applications, they are often unsuitable for medical imaging because slides lack a canonical orientation (rotational invariance is required) and absolute coordinates fail to capture the local cell-cell interactions critical for diagnosis.
Methodology: Distance-Aware Self-Attention (DAS-MIL)
The core innovation of this work is the Distance-Aware Self-Attention (DAS-MIL) mechanism. Instead of relying on discrete distance "bins," which can be difficult to tune and generalize poorly, DAS-MIL utilizes a continuous distance-dependent bias.
Key technical features include:
- Continuous Distance Encoding: A continuous interpolation function $\phi$, parameterized as a scaled and shifted sigmoid, maps Euclidean distances between patch centroids to scalar weights.
- Triple-Term Injection: Learned distance representations ($b^K, b^Q, b^V$) are added to the Keys, Queries, and Values. This enables the model to learn spatial dependencies, such as whether certain features are only relevant when physically proximate.
- Computational Efficiency: By employing a mathematical optimization to subtract specific terms from the attention compatibility function, the model maintains low overhead and allows for partial pre-computation of the attention matrix.
Experimental Results
The model was evaluated on both synthetic and real-world benchmarks to test its ability to leverage spatial context.
MNIST-COLLAGE Benchmarks
A custom dataset, MNIST-COLLAGE, was developed where a bag is positive only if specific digits (e.g., a '0' and a '1') appear within a certain distance of each other. DAS-MIL achieved a test accuracy of 95.8%, significantly outperforming standard self-attention (84.8%) and absolute positional encoding methods (78-82%).
CAMELYON16 Performance
On the CAMELYON16 breast cancer metastasis detection dataset, DAS-MIL achieved a state-of-the-art AUROC of 0.914. Notably, the model is highly efficient, reaching these results with only 412K parameters, compared to 2.54M parameters in the TransMIL architecture.
Conclusion
DAS-MIL demonstrates that explicitly modeling relative spatial relationships significantly improves performance in MIL tasks, particularly where rotational invariance and local interactions are paramount. By moving from discrete to continuous distance representations, the model provides a more flexible and efficient way to incorporate inductive biases into self-attention. Future research will explore alternative interpolation functions and hierarchical scaling for even larger whole-slide images.
Summary updated