[논문 리뷰] 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.
연구 동기 및 목표
- 활성화 선택(ReLU 대 Softmax)이 Transformer의 FFN 및 키-값 메모리에 어떤 영향을 미치는지 조사한다.
- ReLU와 Softmax 사이의 분산 및 정규화 차이를 검사한다.
- 자기 주의에서 긴 시퀀스에서 ReLU 성능을 탐구하고 안정화 기술을 제안한다.
- 번역 작업을 위한 완전히 ReLU인 Transformer(ReLUFormer)을 제안하고 평가하며, 긴 문서 시나리오를 포함한다.
제안 방법
- FFN 활성화를 Softmax로 바꿔 키-값 메모리와의 정합성을 확인하고 성능을 관찰한다.
- 메모리 구성에서 Softmax 뒤에 Layer Normalization 모듈을 추가해 키-값 메모리와의 등가를 회복한다.
- 메모리 슬롯 수(은닉 차원)를 다양하게 바꿔 ReLU와 Softmax를 대규모에서 비교한다.
- ReLU의 자기 주의에서 분산 증가를 분석하고 분산 감소 계수 γ√(n/2)를 도입한다.
- ReLU 기반 SAN의 주의 가중치 분포를 균형 있게 만들기 위한 엔트로피 기반 정규화 및 정규화 손실을 도입한다.
- ReLUFormer를 구성해 SAN과 FFN 모두에 ReLU를 통합하고 문장-문서 단위 번역에서 평가한다.
실험 결과
연구 질문
- RQ1적절한 정규화를 적용하면 FFN과 키-값 메모리가 동등한가?
- RQ2ReLU와 Softmax는 특히 메모리 슬롯 수가 증가하거나 입력 시퀀스 길이가 늘어날 때 분포와 분산에서 어떻게 다를까?
- RQ3완전히 ReLU인 Transformer(ReLUFormer)이 문서 번역과 같은 긴 시퀀스 작업에서 Softmax 기반 Transformer를 능가할 수 있는가?
- RQ4ReLU 기반 자기 주의를 훈련 중 안정화하고 긴 시퀀스에서의 효과를 개선하기 위해 필요한 메커니즘은 무엇인가?
주요 결과
- Softmax는 지수 정규화를 제공하여 분포를 과도하게 중앙집중화시키며, 값 슬롯 수가 많아지면 성능을 해친다.
- 메모리 형식에서 Softmax에 추가 Layer Normalization을 적용하면 FFN과 키-값 메모리가 동등해진다.
- 메모리 크기(값 슬롯)가 크면 ReLU가 Softmax보다 우수하고, LN Softmax는 ReLU 성능에 근접할 수 있지만 슬롯이 매우 크면 ReLU가 여전히 우수하다.
- Self-attention에 Softmax를 직접 ReLU로 교체하면 분산 폭발이 발생하고, 분산 감소 계수 적용으로 안정화되며(스케일 컨스 따라 BLEU가 IWSLT14 De-En에서 33.19로 향상).
- SAN에서 ReLU와 Softmax 간의 차이를 줄이기 위해 정규화 손실과 엔트로피-여백 정규화라는 정규화를 도입하여 더 나은 주의 분포와 번역 품질을 달성하는 데 도움을 준다.
- ReLUFormer는 완전한 ReLU 아키텍처로써, 일반 Transformer보다 긴 문서 번역에서 우수하며(Europarl7 문서 수준에서 이득이 나타남; 길이 1024에서 ReLUFormer가 BLEU 1.15 향상을 달성).
이 논문 읽기
누빈트 뷰어에서 원문을 열고, 읽으면서 궁금한 곳을 바로 물어보세요.
누빈트에서 이 논문 읽기이 리뷰는 AI가 논문 원문을 바탕으로 만들었습니다. 인용하기 전에 원문을 확인해 주세요.