Reversed Attention: On The Gradient Descent Of Attention Layers In GPT

Shahar Katz, Lior Wolf
12/22/2024
cs.CL

No official code found. Best implementation: shacharKZ/Reversed-Attention (3 stars, last commit 2025-04-23).

Abstract

The success of Transformer-based Language Models (LMs) stems from their attention mechanism. While this mechanism has been extensively studied in explainability research, particularly through the attention values obtained during the forward pass of LMs, the backward pass of attention has been largely overlooked. In this work, we study the mathematics of the backward pass of attention, revealing that it implicitly calculates an attention matrix we refer to as "Reversed Attention". We examine the properties of Reversed Attention and demonstrate its ability to elucidate the models' behavior and edit dynamics. In an experimental setup, we showcase the ability of Reversed Attention to directly alter the forward pass of attention, without modifying the model's weights, using a novel method called "attention patching". In addition to enhancing the comprehension of how LM configure attention layers during backpropagation, Reversed Attention maps contribute to a more interpretable backward pass.

View on arXivView PDF

Code Implementations(1)

30Shell, PythonDec 18, 20241 years ago

Similar Papers

Cite this paper

@article{katz2024reversed,
  title  = {Reversed Attention: On The Gradient Descent Of Attention Layers In GPT},
  author = {Shahar Katz and Lior Wolf},
  year   = {2024},
  eprint = {2412.17019},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2412.17019v1}
}

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/2412.17019.svg)](https://codeofpaper.com/paper/2412.17019)

Discussion