[论文解读] A Study on ReLU and Softmax in Transformer
论文分析 Transformer 组件中的 ReLU 与 Softmax,显示在层归一化下 FFN 与键值记忆变得等价,证明 ReLU 在多值槽位和长序列中的优势,并引入 ReLUFormer 以改进长序列翻译。
The Transformer architecture consists of self-attention and feed-forward networks (FFNs) which can be viewed as key-value memories according to previous works. However, FFN and traditional memory utilize different activation functions (i.e., ReLU and Softmax respectively), which makes them not equivalent. In this paper, we first rebuild the connections between FFN and key-value memory by conducting extensive studies on ReLU and Softmax, and find they are equivalent when adding an additional layer normalization module on Softmax. In addition, ReLU outperforms Softmax on both FFN and key-value memory when the number of value slots is large. We analyze the reasons and then explore this good property of ReLU on the self-attention network where the original Softmax activation performs poorly on long input sequences. We then propose a full ReLU architecture named ReLUFormer which performs better than the baseline Transformer on long sequence tasks such as document translation. This paper sheds light on the following points: 1) Softmax and ReLU use different normalization methods over elements which lead to different variances of results, and ReLU is good at dealing with a large number of key-value slots; 2) FFN and key-value memory are equivalent, and thus the Transformer can be viewed as a memory network where FFNs and self-attention networks are both key-value memories.
研究动机与目标
- Investigate how activation choices (ReLU vs Softmax) affect FFN and key-value memory in Transformers.
- Examine differences in variance and normalization between ReLU and Softmax.
- Explore ReLU performance in self-attention on long sequences and propose stabilization techniques.
- Propose and evaluate a fully ReLU Transformer (ReLUFormer) for translation tasks, including long document scenarios.
提出的方法
- Replace FFN activation with Softmax to align with key-value memory and inspect performance.
- Add a layer normalization module after Softmax in FFN to restore equivalence with key-value memory.
- Vary the number of value slots (hidden dimension) to compare ReLU vs Softmax at scale.
- Analyze variance growth in self-attention with ReLU and introduce a variance reduction factor γ√(n/2).
- Introduce entropy-based regularization and normalization loss to balance attention weight distributions in ReLU-based SAN.
- Assemble ReLUFormer by integrating ReLU in both SAN and FFN and evaluate on sentence- and document-level translation.
实验结果
研究问题
- RQ1Are FFN and key-value memory equivalent when appropriate normalization is applied?
- RQ2How do ReLU and Softmax differ in variance and distribution, particularly as the number of memory slots grows or the input sequence length increases?
- RQ3Can a fully ReLU Transformer (ReLUFormer) outperform Softmax-based Transformers on long-sequence tasks such as document translation?
- RQ4What mechanisms are needed to stabilize ReLU-based self-attention during training and improve its effectiveness on long sequences?
主要发现
- Softmax provides exponential normalization that yields an over-centralized distribution, which hurts performance when the number of value slots is large.
- FFN and key-value memory become equivalent when an additional layer normalization is applied to Softmax in the memory formulation.
- ReLU outperforms Softmax when the memory size (value slots) is large, and with LN Softmax can approach ReLU performance; however, with very large slots ReLU remains superior.
- Directly replacing Softmax with ReLU in self-attention causes variance explosions; applying a variance-reduction factor stabilizes training (and improves BLEU to 33.19 in IWSLT14 De-En with scale factor).
- To close the gap between ReLU and Softmax in SAN, the authors introduce regularization: normalization loss and entropy-margin regularization, which help achieve better attention distributions and translation quality.
- ReLUFormer, a fully ReLU architecture, outperforms the vanilla Transformer on long-document translation (e.g., document-level Europarl7 shows gains; ReLUFormer achieves 1.15 BLEU gain at length 1024).
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。