Unveiling the Hidden Structure of Self-Attention via Kernel Principal Component Analysis

Rachel S. Y. Teo, Tan M. Nguyen
6/19/2024
cs.LGcs.AIcs.CL

No official code found. Best implementation: rachtsy/KPCA_code (21 stars, last commit 2025-04-04). 1 more below.

Abstract

The remarkable success of transformers in sequence modeling tasks, spanning various applications in natural language processing and computer vision, is attributed to the critical role of self-attention. Similar to the development of most deep learning models, the construction of these attention mechanisms relies on heuristics and experience. In our work, we derive self-attention from kernel principal component analysis (kernel PCA) and show that self-attention projects its query vectors onto the principal component axes of its key matrix in a feature space. We then formulate the exact formula for the value matrix in self-attention, theoretically and empirically demonstrating that this value matrix captures the eigenvectors of the Gram matrix of the key vectors in self-attention. Leveraging our kernel PCA framework, we propose Attention with Robust Principal Components (RPC-Attention), a novel class of robust attention that is resilient to data contamination. We empirically demonstrate the advantages of RPC-Attention over softmax attention on the ImageNet-1K object classification, WikiText-103 language modeling, and ADE20K image segmentation task.

View on arXivView PDF

Code Implementations(2)

rachtsy/KPCA_codeCommunity100%

Implementation for robust ViT and scaled attention

210Shell, PythonAug 12, 20241 years ago

a repo that contains my experiments centered around robust principal component attention introduced in https://arxiv.org/pdf/2406.13762

00Jupyter NotebookJan 8, 20251 years ago

Similar Papers

Cite this paper

@article{teo2024unveiling,
  title  = {Unveiling the Hidden Structure of Self-Attention via Kernel Principal Component Analysis},
  author = {Rachel S. Y. Teo and Tan M. Nguyen},
  year   = {2024},
  eprint = {2406.13762},
  archivePrefix = {arXiv},
  doi    = {10.48550/arXiv.2406.13762},
  url    = {http://arxiv.org/abs/2406.13762v2},
  journal = {NEURIPS 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2406.13762.svg)](https://codeofpaper.com/paper/2406.13762)

Discussion