Self-attention is actually doing kernel PCA under the hood - now we can make it robust
So how does Self-attention works: it's kernel PCA in disguise, as proposed in this paper.
π https://arxiv.org/abs/2406.13762
π€ Original Problem:
Self-attention in transformers has been developed through heuristics and experience, lacking a systematic theoretical framework to understand its inner workings and improve robustness against data corruption.
-----
π§ Solution in this Paper:
β Derives self-attention from kernel Principal Component Analysis (kernel PCA), showing it projects query vectors onto principal component axes of key matrix
β Introduces RPC-Attention (Attention with Robust Principal Components) that uses Principal Component Pursuit to handle corrupted data
β Implements PAP (Principal Attention Pursuit) algorithm that iteratively recovers clean data from corrupted inputs
-----
π‘ Key Insights:
β Self-attention mathematically performs kernel PCA in feature space
β Value matrix captures eigenvectors of Gram matrix of key vectors
β Number of principal components used must be β€ number of data points
β Different value matrix parameterizations lead to different attention architectures
-----
π Results:
β RPC-Attention outperforms baseline on ImageNet-1K by 1% accuracy
β Shows 3% improvement in AUPR on ImageNet-O
β Better performance against PGD, FGSM, SPSA adversarial attacks
β 1 PPL improvement on WikiText-103 language modeling










