Masked Attention Pooling Is Invariant to Padding and Permutation: A Formal Proof in Lean
Not on the map. Why?
Abstract (arXiv)
Attention-based multiple instance learning (MIL) pools a variable-size bag of instance embeddings into one vector. In batched training, bags are padded to a common length, and the pooled output is expected not to depend on how much padding was added or on the order in which instances are stored. This expectation holds only if padded rows are removed from both the numerator and the softmax normalizer. Common implementation idioms meet it only under side conditions. Zeroing padded features alone does not work. Masking logits with -∞ fails on empty bags and on nonfinite padding. Masking with a large negative constant is exact only after floating-point underflow. We define masked attention pooling with a guarded normalizer and prove in Lean 4 with mathlib that it is invariant under any bijective reindexing of rows and under appending any finite number of masked rows with arbitrary real features and logits. We also prove that values at masked positions are irrelevant and that an all-masked bag maps to zero. The theorems hold for arbitrary finite index types and feature dimensions. Using the jax-lean certificate pipeline, we connect these theorems to the Jaxpr traced from the JAX kernel itself. Lean checks translation certificates for two concrete shapes, identifies the generated functions with the generic specification, and transfers both invariances to the imported Jaxpr's real-arithmetic semantics. All audited theorems depend only on Lean's three standard axioms. The results concern ideal real arithmetic. Floating-point execution, XLA, and the JAX tracer and importer remain outside the proof.
Key facts. No citing papers in the map yet (data through 14 Oct 2026). Builds on 5 of its 13 references that are in the map. First posted on arXiv 12 Oct 2026.
Builds on
5 of 13 references.
References · 5
- 2017Deep Setscited by 1,421
- 2018Attention-based Deep Multiple Instance Learningcited by 1,095
- 2020Data Efficient and Weakly Supervised Computational Pathology on Whole Slide Imagescited by 745
- 2019The Lean mathematical librarycited by 134
- 2017Developing Bug-Free Machine Learning Systems With Formal Mathematicscited by 14
Built on by
Not cited yet.