arXiv(opens in a new tab)cs.LGFeb 2020Cited by 184 papers on PaperVantageClassic Paper

Manuscript Offprint

arXiv:2002.05202

GLU Variants Improve Transformer

Noam Shazeer

Abstract

Gated Linear Units [Dauphin et al., 2016] consist of the component-wise product of two linear projections, one of which is first passed through a sigmoid function. Variations on GLU are possible, using different nonlinear (or even linear) functions in place of sigmoid. We test these variants in the feed-forward sublayers of the Transformer [Vaswani et al., 2017] sequence-to-sequence model, and find that some of them yield quality improvements over the typically-used ReLU or GELU activations.

1 Introduction

The Transformer [Vaswani et al., 2017] sequence-to-sequence model alternates between multi-head attention, and what it calls "position-wise feed-forward networks" (FFN). The FFN takes a vector xx (the hidden representation at a particular position in the sequence) and passes it through two learned linear transformations, (represented by the matrices W1W_1 and W2W_2 and bias vectors b1b_1 and b2b_2). A rectified-linear (ReLU) [Glorot et al., 2011] activation function applied between the two linear transformations.

FFN⁡(x,W1,W2,b1,b2)=max⁡(0,xW1+b1)W2+b2(1)\operatorname{FFN}(x,W_1,W_2,b_1,b_2)=\max(0,xW_1+b_1)W_2+b_2 \tag{1}

Following the T5 codebase [Raffel et al., 2019] 1^{1}, we use a version with no bias:

FFN⁡ReLU(x,W1,W2)=max⁡(xW1,0)W2(2)\operatorname{FFN}_{\mathrm{ReLU}}(x,W_1,W_2)=\max(xW_1,0)W_2 \tag{2}

Subsequent work has proposed replacing the ReLU with other nonlinear activation functions such as Gaussian Error Linear Units, GELU⁡(x)=xΦ(x)\operatorname{GELU}(x)=x\Phi(x) [Hendrycks and Gimpel, 2016], and Swish⁡β(x)=xσ(βx)\operatorname{Swish}_\beta(x)=x\sigma(\beta x) [Ramachandran et al., 2017].

FFN⁡GELU(x,W1,W2)=GELU⁡(xW1)W2FFN⁡Swish(x,W1,W2)=Swish⁡1(xW1)W2(3)\begin{aligned}\operatorname{FFN}_{\mathbb{GELU}}(x,W_1,W_2)&=\operatorname{GELU}(xW_1)W_2\\\operatorname{FFN}_{\mathbb{Swish}}(x,W_1,W_2)&=\operatorname{Swish}_1(xW_1)W_2\end{aligned} \tag{3}

Cited by (184)