Selective Attention: Enhancing Transformer through Principled Context Control

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.

Paper

References (55)

Scroll for more · 38 remaining

Similar papers

Peer review

Reviewer TP8j7/10 · confidence 4/52024-07-12

Summary

The authors introduce a modification to the widely-used self-attention mechanism, which modulates the queries and values in the attention computation with a per-token temperature parameter. They demonstrate that this allows the attention layer to model certain observations better for toy problems, and they also adapt several large language models to use this Selective Self-Attention (SSA), demonstrating that it moderately boosts overall perplexity & accuracy scores.

Strengths

The technical contribution represents an interesting and intuitive addition to standard attention. The addition of learnable query and value temperature clearly benefits the attention mechanism, both on illustrative toy examples and on real-world data. The mathematical exploration is comprehensive, leaving the reader with solid reasoning for why SSA solves several problems. The approach not only improves the performance of attention on standard modeling problems, but promises to improve on long-context tasks and positional encoding as well.

Weaknesses

My main concern is the claim that the performance improvement on the LM task is due to "strategic integration of SSA" rather than an increase in parameter count. The improvements in perplexity/accuracy look statistically significant, but I don't think it's obvious that the improvement couldn't come from the increase in parameter count. There at least needs to be more argumentation to support this claim. Another weakness is that the mathematical sections are pretty dense at times. Terms and mathematical propositions were introduced quickly without a lot of background. I found it difficult to understand the motivation for the lemma and propositions. I also think the denoising task, "feature imbalance", "effective weights", and "specificity" needed more introduction.

Questions

Could we bolster the claim that SSA packs more benefit than just extra parameters by testing models that are scaled up with normal attention by equivalent amounts? Or can we instead argue this by looking at model scaling work that shows that a lot more parameter scaling is required to achieve similar drops in perplexity?

Rating

7

Confidence

4

Soundness

3

Presentation

3

Contribution

4

Limitations

Attention is used extremely broadly, and the only real-world task used to evaluate SSA was the language modeling task. I would mention this as an important limitation on the claims of the paper.

Reviewer qMbv5/10 · confidence 3/52024-07-17

Summary

This paper presents Selective Self-Attention (SSA), which introduces trainable temperature functions to adapt the contextual sparsity of attention weights. SSA uses a query temperature to adjust the sparsity for each query and its context position, and a value temperature to suppress irrelevant or noisy tokens. Experimental results show that SSA reduces perplexity in language modeling and improves optimization, with only a slight increase in parameters.

Strengths

1. The paper is well-written and easy to follow. 2. The motivation behind the method is clear and reasonable.

Weaknesses

1. The evaluation is limited to perplexity and accuracy in language modeling; conducting experiments on downstream tasks would provide a more comprehensive evaluation. 2. The perplexity improvement over the original models is modest. 3. The paper lacks comparisons with other selective or sparse attention methods from the existing literature. 4. The claim that SSA benefits long text scenarios lacks supporting evidence. There are no studies on performance relative to text length. 5. There is no detailed description of the datasets used, such as average text length or the number of training instances, which could help explain performance differences. Minor comment: In the abstract, it should be Q and K rather than V and K.

Questions

1. How does SSA's performance vary with different parameter numbers? With more parameters, attention weight dilution might be alleviated, potentially weakening SSA's effect. 2. There is no detailed description of the accuracy mentioned in Table 3. Could you clarify what this accuracy refers to?

Rating

5

Confidence

3

Soundness

2

Presentation

3

Contribution

2

Limitations

Please refer to the weaknesses.

Authorsrebuttal2024-08-12

Thanks again for your valuable suggestions. Before the discussion period is over, we wanted to kindly remind you that we have conducted comprehensive evaluations, which we believe, address your concerns. Specifically, our evals demonstrate that SSA facilitates noticeable improvements on multiple benchmarks (addressing W1,2,4) and we have provided two simple methods to reduce the computational/parameter cost of SSA (only <0.5% or <0.01% extra parameters) (addressing Q1). We appreciate your time.

Reviewer qMbv2024-08-14

The new results address my main concerns. I have raised my score to 5.

Reviewer Lp6e5/10 · confidence 5/52024-07-17

Summary

The paper proposes token-aware and position-aware gating for query, key and value vectors in self-attention layers.

Strengths

1. The position-aware gating is interesting, and, in theory, can alleviate dispersed attention and thus may lead to better length extrapolation. 2. The inductive bias introduced in the paper can lead to faster convergence when finetuning a small language model with less than 200M parameters.

Weaknesses

1. The terminology and the positioning of the paper is misleading. The whole paper claims that they are doing qkv selection but there is actually no sparse attention involved. The author should look at some papers [1,2] focusing on real selection of the input for self-attention. Also, the paper claims that they are doing temperature scaling but actually their temperatures can be negative, so it is basically doing gating of the query, key and value vector because of its element-wise product nature. The authors also use the terminology, "soft sparsity", which is self-contradictory and unclear. I suggest a better terminology can be used as "spikiness of attention" instead of "sparsity of softmax". 2. No actual wall-time efficiency benefits of the proposed method as a result of it essentially being a gating mechanism. 3. The scale of the experiments are rather small with LMs below than 200M parameters. 4. Lack of the experimental supports for the claim that position-aware gating can alleviate dispersed attention. --- [1] Fast Attention Over Long Sequences With Dynamic Sparse Flash Attention. https://openreview.net/forum?id=UINHuKeWUa [2] Sparse Modular Activation for Efficient Sequence Modeling. https://openreview.net/forum?id=TfbzX6I14i

Questions

1. For token-aware "temperature scaling", why not using a simpler formulation of tanh() but 2*sigmoid()-1? Do you have some empirical results supporting such formulation? 2. Do you have some theoretical explanations for why Key vector gating is not used in practice?

Rating

5

Confidence

5

Soundness

2

Presentation

2

Contribution

4

Limitations

Yes.

Reviewer NV9t5/10 · confidence 3/52024-07-18

Summary

This work introduces Selective Self-Attention (SSA), an additional trainable module for standard transformer self-attention that applies temperature scaling to its three components: queries, keys, and values. By performing both token-based and position-based scaling to modulate the influence of different tokens and positions dynamically, SSA aims to improve control over contextual sparsity and relevance in self-attention mechanisms. The authors empirically demonstrate that SSA can be integrated into existing transformer architectures such as Pythia and LLaMA, adding approximately 5% more trainable parameters. In terms of training efficiency, SSA shows potential for accelerating training achieving similar performance with fewer tokens.

Strengths

1) The paper focuses on an interesting area of understanding attention patterns and developing attention mechanisms to enhance contextual sparsity given a particular query. 2) The paper is well-written and majority of sections are easy to follow.

Weaknesses

1. Computational overhead: the proposed selective self-attention modules lead to an approximate 5% increase in model parameters. The authors should address the additional computational cost at inference time, which could be substantial for large-scale deployments. In the case of larger models with billions of parameters, even a 5% increase could significantly impact both training and inference costs. 2. Baseline model comparisons: The vanilla models evaluated in this work are relatively smaller in terms of parameter size, potentially making the comparison unfair. 3. Need for pre-training: The SSA-based LLMs studied in the work are pre-trained from scratch. Can the authors provide a justification for this approach? 4. Evaluation tasks: The evaluations are mainly on language modeling tasks (Wikitext and Lambada). Given the research motivation, I believe it is important to demonstrate SSA's effectiveness on other NLP tasks where the learned contextual sparsity can address practical issues such as reducing inference latency over longer sequences, KV cache reduction for improving prefill latency, etc.

Questions

Please see weaknesses section.

Rating

5

Confidence

3

Soundness

2

Presentation

2

Contribution

2

Limitations

Yes

Authorsrebuttal2024-08-12

Thanks again for your valuable suggestions. Before the discussion period is over, we wanted to kindly remind you that we have conducted comprehensive evaluations, which we believe, address your concerns. For instance, we provided two simple methods to reduce the computational cost of SSA (only 0.5% or 0.01% extra parameters). We appreciate your time.

Reviewer TP8j2024-08-08

Thank you for the thorough responses. I have increased the confidence of my review based on how you've addressed the concerns of all reviewers. I believe this work constitutes a meaningful contribution and should be accepted. Reviewer Lp6e referenced some existing works which use "hard" sparse attention in order to increase efficiency. It would be important to include a brief discussion of these works in the related work section of the paper, so as to better situate and distinguish the goals of the present work from that body of research.

Authorsrebuttal2024-08-10

We appreciate your positive feedback. We also agree regarding Reviewer Lp6e's comments. Indeed, rather than efficiency, our work aims to improve the accuracy and approximation capability of the model. We will incorporate a paragraph on sparse attention under the Related Work section to distinguish these. We will discuss earlier works, such as BigBird, LongFormer, Reformer, as well as the recent efficient sparse methods, such as [1,2] mentioned by Reviewer Lp6e.

Authorsrebuttal2024-08-12

Dear Reviewer: Thanks again for your comprehensive feedback which will really help with better situating our manuscript. As the discussion period comes to an end, we would be happy to clarify if you have any further questions, especially regarding our response and supporting experiments.

Reviewer Lp6e2024-08-13

Thanks for the clarifiaction and the promising additional experimental results. I still think the usage of "selection" is misleading since there is already a popular work called selective attention [1], which leverages sparse attention for efficient contextualized selection. [1] Selective Attention for Context-aware Neural Machine Translation (NAACL 2019)

Authorsrebuttal2024-08-13

We acknowledge the reviewer's concern. To convey the contribution and method more clearly, we will revise the name of the method, potentially to "Temperature-scaled Attention". We would be happy to hear if the reviewer has other suggestions.

Reviewer Lp6e2024-08-13

I have raised my score from 4 to 5 given that the authors update the paper as discussed. Since Attention is already temperature-scaled, so I would suggest other names such as scalar-gated self-attention to emphasize more on its input-dependent nature.

Authorsrebuttal2024-08-13

Thanks for the suggestion, we agree that scalar-gated would capture the basic idea well. It's worth noting that there is relatively little theoretical understanding of how gating aids sequence modeling. We believe our theoretical results, well supported empirically, also represent a significant contribution on that front.

Reviewer NV9t2024-08-13

Thank you for the response

Thank you for addressing my concerns. I have increased my score to 5.

Authorsrebuttal2024-08-13

Dear Reviewer, Thanks for getting back and adjusting your rating. Let us know if you have any outstanding concerns. We particularly appreciated your "computational overhead" feedback which led us to investigate efficient SSA. In the revised manuscript and GitHub release, we plan to make weight-shared SSA the default method as it retains expressivity while having essentially no architectural overhead. Thanks Authors

Program Chairsdecision2024-09-25

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC