Selective Attention: Enhancing Transformer through Principled Context Control

Xuechen Zhang, Xiangyu Chang, Mingchen Li, Amit Roy-Chowdhury, Jiasi Chen +1 more
11/19/2024
cs.LGcs.CL

No official code found. Best implementation: umich-sota/selective_attention (10 stars, Apache-2.0, last commit 2024-11-15).

Abstract

The attention mechanism within the transformer architecture enables the model to weigh and combine tokens based on their relevance to the query. While self-attention has enjoyed major success, it notably treats all queries $q$ in the same way by applying the mapping $V^\top\text{softmax}(Kq)$, where $V,K$ are the value and key embeddings respectively. In this work, we argue that this uniform treatment hinders the ability to control contextual sparsity and relevance. As a solution, we introduce the $\textit{Selective Self-Attention}$ (SSA) layer that augments the softmax nonlinearity with a principled temperature scaling strategy. By controlling temperature, SSA adapts the contextual sparsity of the attention map to the query embedding and its position in the context window. Through theory and experiments, we demonstrate that this alleviates attention dilution, aids the optimization process, and enhances the model's ability to control softmax spikiness of individual queries. We also incorporate temperature scaling for value embeddings and show that it boosts the model's ability to suppress irrelevant/noisy tokens. Notably, SSA is a lightweight method which introduces less than 0.5% new parameters through a weight-sharing strategy and can be fine-tuned on existing LLMs. Extensive empirical evaluations demonstrate that SSA-equipped models achieve a noticeable and consistent accuracy improvement on language modeling benchmarks.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

Selective Attention Mechanism (NeurIPS 2024)

101Shell, PythonOct 31, 20241 years agoApache-2.0

Similar Papers

Cite this paper

@article{zhang2024selective,
  title  = {Selective Attention: Enhancing Transformer through Principled Context Control},
  author = {Xuechen Zhang and Xiangyu Chang and Mingchen Li and Amit Roy-Chowdhury and Jiasi Chen and Samet Oymak},
  year   = {2024},
  eprint = {2411.12892},
  archivePrefix = {arXiv},
  doi    = {10.48550/arXiv.2411.12892},
  url    = {http://arxiv.org/abs/2411.12892v1},
  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/2411.12892.svg)](https://codeofpaper.com/paper/2411.12892)

Discussion