# A Dot Product Attention Free Transformer

### A Dot Product Attention Free Transformer

论文地址：

* <https://openreview.net/forum?id=JVR4JswsEM>

### 整体思路以及计算方式

利用点乘的方式计算Attention：

* 输入：$$\mathbf Q, \mathbf K, \mathbf V\in \mathbb R^{n\times d}, \mathbf p\_1,\mathbf p\_2\in \mathbb R^{n\times d\_1}$$
* 计算$$\mathbf W= \mathbf p\_1\mathbf p\_2 ^\top \in \mathbb R^{n\times n}$$
* 输出：

  $$
  \mathbf o\_{i}=\sigma\_{q}\left(\mathbf q\_{i}\right) \odot \frac {\sum\_{j=1}^{n} \exp \left(\mathbf k\_{j}+w\_{i,j}\right) \odot \mathbf v\_{j}} {\sum\_{j=1}^{n} \exp \left(\mathbf k\_{j}+w\_{i,j}\right)}
  $$

### 时间复杂度

$$O(d^2n + n^2d\_1)$$

### 训练以及loss

不变。

### 代码

暂无，但是论文里有伪代码。

### 实验以及适用场景

Encoder和Decoder情形都进行了实验，总体来说效果还不错。

### 细节

因为没有计算Attention matrix，所以token之间的交互是通过$$\mathbf W$$矩阵。

### 简评

挺好的一个思路，可以考虑复现。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doraemonzzz.gitbook.io/transformer_evolution_paper/mha/rightproduct/008.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
