Title: DENSE RECURRENT NEURAL NETWORK WITH ATTENTION GATE

Abstract: We propose the dense RNN, which has fully connections from each hidden state directly to multiple preceding hidden states of all layers. As the density of the connection increases, the number of paths through which the gradient flows is increased. The magnitude of gradients is also increased, which helps to prevent the vanishing gradient problem in time. Larger gradients, however, may cause exploding gradient problem. To complement the trade-off between two problems, we propose an attention gate, which controls the amounts of gradient flows. We describe the relation between the attention gate and the gradient flows by approximation. The experiment on the language modeling using Penn Treebank corpus shows dense connections with the attention gate improve the model's performance of the RNN.

1. INTRODUCTION:

In order to analyze sequential data, it is important to choose an appropriate model to represent the data. Recurrent neural network (RNN), as one of the model capturing sequential data, has been applied to many problems such as natural language (Mikolov et al., 2013) , machine translation (Bahdanau et al., 2014) , speech recognition (Graves et al., 2013) . There are two main research issues to improve the RNNs performance: 1) vanishing and exploding gradient problems and 2) regularization.

The vanishing and exploding gradient problems occur as the sequential data has long-term dependency (Hochreiter, 1998; Pascanu et al., 2013) . One of the solutions is to add gate functions such as the long short-term memory (LSTM) and gated recurrent unit (GRU). The LSTM has additional gate functions and memory cells (Hochreiter & Schmidhuber, 1997) . The gate function can prevent the gradient from being vanished during back propagation through time. Gated recurrent unit (GRU) has similar performance with less gate functions (Chung et al., 2014) .

The part of sequential data whose boundary to distinguish the consecutive other parts, has the hierarchical structures. To handle the hierarchy, the model should capture the multiple timescales. In hierarchical multiple recurrent neural network (HM-RNN, Chung et al. (2016) ), the boundary information is also learned by implementing three operations such as update, copy and flush operator. In clockwork RNN (Koutnik et al., 2014) , the hidden states are divided into multiple sub-modules, which act with different periods to capture multiple timescales. As all previous states within the recurrent depth do not always affect the next state, memory-augmented neural network (MANN, Gulcehre et al. (2017) ) uses the memory to remember previous states and retrieve some of previous states if necessary.

The basic way to handle multiple timescales along with preventing the vanishing gradient problem is to increases both of feedforward depth and recurrent depth to capture multiple timescales. Feedforward depth is the longest path from the input layer to the output layer. Recurrent depth is the longest path from arbitrary hidden state at time t to same hidden sate at time t + t (Zhang et al., 2016) . Increasing feedforward depth means stacking multiple recurrent layers deeply. It can capture fast and slow changing components in the sequential data (Schmidhuber, 1992; El Hihi & Bengio, 1996; Hermans & Schrauwen, 2013) . The low level layer in the stacked RNN captures short-term dependency. As the layer is higher, the aggregated information from lower layer is abstracted. Thus, as the layer is higher, the capacity to model long-term dependency increases. The number of nonlinearities in the stacked RNN, however, is proportional to the number of unfolded time steps regardless of the feedforward depth. Thus, the simple RNN and stacked RNN act identically in terms of long run.

Increasing recurrent depth also increases the capability to capture long-term dependency in the data. The hidden state in vanilla RNN has only connection to previous time step's hidden state in the same layer. Adding the connections to multiple previous time steps hidden states can make the shortcut paths, which alleviates the vanishing problem. Nonlinear autoregressive exogenous model (NARX) handles the vanishing gradient problem by adding direct connections from the distant past in the same layer (Lin et al., 1996) . Similarly, higher-order RNN (HO-RNN) has the direct connections to multiple previous states with gating to each time step (Soltani & Jiang, 2016) . Unlike other recurrent models that use one connection between two consecutive time steps, the recurrent highway network (RHN) adds multiple connections with sharing parameters between transitions in the same layer (Zilly et al., 2016) .

The vanilla RNN has only one path connected with previous hidden states. Thus, it is hard to apply standard dropout technique for regularization as the information is being diluted during training of long-term sequences. By selecting the same dropout mask for feedforward, recurrent connections, respectively, the dropout can apply to the RNN, which is called a variational dropout (Gal & Ghahramani, 2016) . This paper proposes a dense RNN that has both of feedforward and recurrent depths. The stacked RNN increases the complexity by increasing feedforward depth. NARX-RNN and HO-RNN increase the complexity by increasing recurrent depth. The model with the feedforward depth can be combined with the model with the recurrent depth, as the feedforward depth and recurrent depth have an orthogonal relationship. Gated feedback RNN has the fully connection between two consecutive timesteps. As the connection of gated feedback is not overlapped with the model with orthogonal depths, all three features, adding feedforward depth, recurrent depth, and gated feedback, can be modeled jointly . With the three features, we propose the attention gate, which controls the flows from each state so that it enhances the overall performance.

The contributions of this paper are summarized: 1) dense RNN that is aggregated model with feedforward depth, recurrent depth and gated feedback function, 2) extension of the variational dropout to the dense RNN.

2. BACKGROUND:

There are largely two methods to improve the performance of RNN. One is to extend previous model by stacking multiple layers or adding gate functions. The other is using regularization such as dropout to avoid overfitting.

2.1. EXTENSION OF RECURRENT NEURAL NETWORK MODELS:

In simple recurrent layer, h t , the hidden state at time t, is a function of input x t and preceding hidden state h t-1 , which is defined as follows:

EQUATION

where U and W are respectively the feedforward and recurrent weight matrix and φ means an element-wise nonlinear function such as T anh. In simple recurrent layer, the last hidden state h t-1 has to memorize all historical inputs. As the memorizing capacity of the hidden state is limited, it is hard to capture long-term dependency in sequential data. Stacked recurrent neural network, stacked of the simple recurrent layers can capture the long-dependency, which is defined as follows:

EQUATION

where W j is the weight matrix for transition from layer j -1 to j and U j is the weight matrix for transition from in timestep t -1 to timestep t at layer j. The stacked RNN can model multiple timescales of the sequential data. As the information travels toward upper layer, the hidden state can memorize abstracted information of sequential data that covers more long-term dependency.

The other way to capture the long term dependency is to increase the recurrent depth by connecting the hidden state at timestep t directly to multiple preceding hidden states (Soltani & Jiang, 2016) , which is defined as follows:

EQUATION

where U (k,j)→j is the weight matrix from layer j at timestep t -k to layer j at timestep t, and K is the recurrent depth. The direct connections make the shortcut paths from preceding multiple hidden states. Compared with the model without shortcut paths, the model with shortcut paths enables to access preceding hidden states further way from h j t with same number of transitions. Most recurrent models have only recurrent connections between hidden states with same layers. By adding feedback connections to the hidden state h j t from the preceding hidden states h i t-1 at different layer of h j t , the model adaptively captures the multiple timescales from long-term dependency, which is defined as follows:

EQUATION

where U i→j is the weight matrix from layer i at timestep t -1 to layer j at timestep t, and L is the feedforward depth. To control the amount of flows between different hidden states with different time scales (Chung et al., 2014) , the global gate is applied as follows:

EQUATION

In ( 5), g i→j is the gate to control the information flows from each hidden state to multiple preceding hidden states of all layers, which is defined as follows:

EQUATION

where w j g is a vector whose dimension is same with h j-1 t , u i→j g is a vector whose dimension is same with h * t-1 that is a concatenated vector of all hidden states from previous time step, and σ is an element-wise sigmoid function.

Gated feedback function is also applied to LSTM. In gated LSTM, input gate i j t , forget gate f j t , output gate o j t , and memory cell gate cj t are defined as follows:

EQUATION

EQUATION

EQUATION

)

EQUATION

)

Compared with conventional LSTM, the gated feedback LSTM has gated feedback function in the memory cell gate cj t . Through gates and memory cell state in (7a)-(7d), the new memory cell state c j t and hidden state h j t respectively are calculated as follows:

EQUATION

EQUATION

where the dot product means element-wise multiplication.

2.2. DROPOUT OF RECURRENT NEURAL NETWORK:

As dropout is one method of neural network regularization, it prevents the model from being overfitted to training set. However, it is hard to apply the standard dropout to recurrent connections. As the sequence is longer, the information is affected by the dropout many time during backpropagation through time, which makes memorizing long sequences hard. Thus, applying the standard dropout only to feedforward connections is recommended (Zaremba et al., 2014) . It is expressed as follows:

EQUATION

where D j t , as a dropout operator for every time step, makes h j-1 t being masked with Bernoulli dropout mask m j-1 t randomly generated for every time step. Moon et al. (2015) proposed how to apply the dropout to recurrent connections efficiently. By considering the whole sequential data as one input at a sequential level, same dropout mask is applied to recurrent connections at all time steps during training, which is expressed as follows:

h j t = φ(W j D j t (h j-1 t ) + U j→j D j→j (h j t-1 )) = φ(W j (m j-1 t • h j-1 t ) + U j→j (m j • h j t-1 )) (10)

where D j→j , as a time-independent dropout operator, makes h j t-1 being masked with Bernoulli dropout mask m j randomly generated regardless of time. Gal & Ghahramani (2016) applied variational dropout to RNN and proved the relation between Bayesian inference and dropout theoretically. Variational dropout in RNN applies same masks regardless of time to feedforward connections, similar to recurrent connections, which is expressed as follows:

h j t = φ(W j D j (h j-1 t ) + U j→j D j→j (h j t-1 )) = φ(W j (m j-1 • h j-1 t ) + U j→j (m j • h j t-1 )). (11)

3. DENSE RECURRENT NEURAL NETWORK:

The skip connections that bypass some layers enables deep networks to be trained better than the models without skip connections. Many research (He et al., 2016; Huang et al., 2016) uses skip connections toward feedback connections. In this paper, we apply the skip connections toward recurrent connections. The shortcut paths from preceding multiple hidden states to the hidden state at time t is equal to the skip connections through time. The shortcut paths include the feedback connections between different layers of different timesteps. Each connection is controlled by the attention gate, similar to the global gate in the gated feedback RNN. The dense RNN is defined as follows:

EQUATION

where g (k,i)→j is the attention gate, which is defined as follows:

EQUATION

(13) is a function of preceding hidden state at layer i and time t -k, while ( 6) is a function of concatenated all preceding hidden states. The intuition why we change the gate function and we call it to attention gate is described in Section 3.1.

The dense RNN can be easily extended to dense LSTM. The dense LSTM is defined as follows: 

EQUATION

EQUATION

EQUATION

) (a) (b) (c)         ℎ   ℎ           ℎ   ℎ   ℎ   ℎ   ℎ   ℎ   (d) (e)

EQUATION

Unlike gated feedback LSTM, the attention gate g is applied to all gates and memory cell state.

We analyze the advantages of dense connections intuitively and theoretically. In addition, we propose the dropout method for dense connections.

3.1. INTUITIVE ANALYSIS:

Recurrent connections enable to predict next data given previous sequential data. In the language modeling, the RNNs can predict next word based on the last word and the last context accumulated before the last word. It assumes only last word affect to predict next word. For instance, "the sky is" is given from the full sentence "the sky is blue" and the goal is to predict the word "blue". In this case, the preceding word "sky provides the better clue than the preceding word "is". Inspired by the fact, we propose the dense model that predicts the next word by directly referring to recent preceding words. In other words, the output h j t is a function of input h j-1 t and recent preceding output h j t-k as in (3). The higher the layer in a neural network, the more abstract the hidden states. In language modeling, hidden states represent the characteristics of words, sentences, and paragraphs as the layer increases. The conventional RNN has only the connection between same layer. It means the preceding words, sentences, paragraphs determine next words, sentences and paragraphs, respectively. The given word, however, can also determine the context of next paragraph. Also, the given paragraph can determine next word. For instance, the word "mystery" in "it is mystery" can be followed by the paragraph related to "mystery" and vice versa. The feedback connections can reflect the fact.

In (4), preceding words, sentences, and paragraphs affects next words, sentences, and paragraphs with same scale. Preceding words, however, dont affects next word prediction evenly. In the sentence "The sky is blue", the word "sky" has a very close relation with the word "blue". The word "The", as an article, has a less relation with the word "blue". The amount how two words are related depends on the kind of the two words. We define the the degree of relevance as gated attention g as in (5).

The attention g is determined by the preceding word itself and the last word given as input. In the sentence "The sky is blue", the features of the word "the", and "sky" denote h t-2 , and h t-1 , respectively and the word "is" denotes x t or h 0 t . Then, the attention to predict the word"blue" from the word "The" is determined by the word "The and "blue". The attention to predict the word "blue" from the word "is" is determined by the word "is" and "blue". In other words, the attention is dependent on the previous hidden state h j t-k and input h j-1 t at certain time step as in (13).

3.2. THEORETICAL ANALYSIS:

The vanishing and exploding gradient problems happen the sequential data has long term dependency. During backpropagation through time, error E T 's gradient with respect to the recurrent weight matrix U j is vanished or exploded as the sequence is longer, which is expressed as follows:

EQUATION

The critical term related to vanishing and exploding gradient problems is ∂h j τ /∂h j τ -1 . To find the relation between vanishing and exploding gradient problems and dense connections, we assume the worst situation in which the vanishing and exploding gradient problem may arise. The term ∂h j τ /∂h j τ -1 denotes A j . If the A j max is less than 1, the gradient with respect to U j would be exploded and if the A j min is greater than 1, gradient with respect to U j would be vanished. In dense recurrent network, there are more paths to flow the gradients. The A j in dense recurrent network is approximated as follows:

EQUATION

where the superscript (k, i) → j means the direction of the path from h i τ +k-1 to h j τ . Assuming

A (k,i)→j is A (k,i)→j max , A j max is KLA (k,i)→j max

, which reduces the vanishing gradient boundary from 1 to 1/(KL) as shown in Figure 2(a) .

Though dense connections are able to alleviate the vanishing gradient problem, it causes the gradient exploding. To alleviate the problem caused by dense connection, we add the attention gates as in (13). The attention gate g (k,i)→j can control the magnitude of A (k,i)→j , which is expressed as follows:

EQUATION

In ( 17), the g (k,i)→j is trainable so that the vanishing and exploding boundary is determined adaptively. In dense RNN with attention gates, h i τ +k-1 is expressed as follows:

EQUATION

)

where θ is not relevant parameters with h j τ -1 , g (k,i)→j is σ(U (k,i)→j g h j τ -1 ). For simplicity, ( 18) is expressed as y = φ(g(U g x) • U x + θ). Gradient of y with respect to x is calculated as follows:

EQUATION

The ( 19) is scaled with g compared to ∂y ∂x = y(1 -y)U without attention gate g. As g and g are similar as shown in Figure 2 (c), g is approximated g as in ( 19).

In recurrent highway network (RHN, Zilly et al. (2016) ), the effect of highway was described using the Geršgorin circle theorem (GST, Geršhgorin (1931) ). Likewise, the dffect of the attention gate in the proposed model can be interpreted using GST. For simplicity, we only formulate recurrent connection with omitting feedforward connection, h t+1 = φ(U h t ). Then, the Jacobian matrix

A = ∂ht+1 ∂ht is U T diag[φ (U h t )]

. By letting γ be a maximal bound on diag[φ (U h t )] and ρ max be the largest singular value of U T , the norm of the Jacobian satisfies using the triangle inequality as follows:

A

EQUATION

The value γρ max is less than 1, the vanishing gradient problem happens and the A is greater than 1, the exploding gradient problem happens as the range of the A has no explicit boundary. The spectrum of A, the set of λ in A, is evaluated as follows:

EQUATION

which means the eigenvalue λ lies on the circle whose radius is the summation of abstract values of all elements except the diagonal element a ii and center is the diagonal element a ii . The simplified recurrent connection with the attention gate is h t+1 = φ(gU h t ) where g is U g , h t . Then, the Jacobian matrix A = ∂ht+1 ∂ht is expressed as follows:

EQUATION

The spectrum of ( 22) is expressed as follows:

EQUATION

The scaled term term g + g U g,i h t,i in ( 23) can be approximated as g as shown in Figure 2 (b). Thus, the upper bound of A is approximately less than 1 so that the attention gate g can alleviate the exploding problem. In dense RNN, as recurrent depth increases, the number of parameters also increases, which makes the model vulnerable to overfitting to training dataset. To prevent the model from overfitting to training dataset, the dropout is applied. The variational dropout, proved to show good performance in the RNN models, uses same random masks at every time step for feedforward connections, and recurrent connections, respectively. In implementation of variational dropout, each state is dropped with the random mask, which is followed by weighted sum. This concept is extensively applied to dense RNN so that the same random mask is used regardless of time and recurrent depth. Extension of variational dropout to the dense connection is expressed as follows:

EQUATION

4 EXPERIMENT

In our experiment, we used Penn Tree corpus (PTB) for language modeling. PTB consists of 923k training set, 73k validation set, and 82k test set. As a baseline model, we select the model proposed by Zaremba et al. (2014) , which proposed how to predict next word based on the previous words.

To improve the accuracy, Zaremba et al. (2014) proposed regularization method for RNN.

The baseline models hidden sizes are fixed as 200, 650, and 1500, which are called as small, medium, and large network. In this paper, we fixed hidden size as 200 for all hidden layers with varying the feedforward depth from 2 to 3, recurrent depth from 1 to 5. The word embedding weights were tied with word prediction weights.

To speed up the proposed method, all of matrix multiplications in (12) was performed by the batch matrix-matrix product of two matrices. Each of batches is rewritten as follows:

hj→i t-k = U (k,i)→j h i t-k .

(25)

The ( 12) is rewritten as follows:

EQUATION

The proposed dense model is trained with stochastic gradient decent. The initial rate was set to 20, which was decayed with 1.1 after the epoch was over 12. The training was terminated when the epoch reaches 120. To prevent the exploding gradient, we clipped the max value of gradient as 5.

As a regularization, we adopt variational dropout, which uses the random masks regardless of time.

We configured the word embeddings dropout to 0.3, feedforward connections dropout 0.2, and recurrent connections dropout rate varies from 0.2 to 0.5. The Table 1 , as a trained result, compares the baseline model, RNN model with variational dropout and using same word space. In dense RNN, the perplexity is better than two models. The best models recurrent depth is 2 and the perplexity of valid set is 83.28 and that of test set is 78.82.

5. CONCLUSION:

This paper proposed dense RNN, which has fully connections from each hidden state to multiple preceding hidden states of all layers directly. Each previous hidden state has its attention gate that controls the amount of information flows. To evaluate the effect of dense connections, we used Penn Treebank corpus (PTB). The result of dense connection was confirmed by varying the recurrent depth with the attention gate. The dense connections with the attention gate made the model's perplexity less than conventional RNN.

:



Figures and Tables:

Figure 1: (a) Conventional RNN unfolded in time. (b) Gated feedback RNN. (c) RNN with connections across multiple preceding states. (d) Dense RNN integrated with (b) and (c). Hidden states are represented in red. The connections used in current steps feedforward are highlighted in bold. The feedback connections between upper and lower layers are represented in yellow. (e) Unfolded Dense RNN in both of time and the number of preceding states.

Figure 2: (a) The stable region from exploding gradient problem. The attention gate increases the stable region from 1 to 1/(KL). (b) The stable region from vanishing gradient problem. The attention gate decreases the stable region from 1 to 1/(KL). (c) The approximation of the attention gate to determine vanishing and exploding gradient boundary.

Perplexity on the Penn Treebank language modeling task.

Table content: <table><tr><td>Network</td><td># Hidden size</td><td># Feed forward</td><td colspan="4"># Recurrent # Param. Valid Test</td></tr><tr><td>LSTM (Zaremba et al., 2014)</td><td>200 650 1500</td><td>2 2 2</td><td>1 1 1</td><td>5M 20M 66M</td><td>104 86.2 82.2</td><td>100.4 82.7 78.4</td></tr><tr><td>VD-LSTM+RE (Inan et al., 2016)</td><td>200 650 1500</td><td>2 2 2</td><td>1 1 1</td><td>2.65M 8.6M 19.8M</td><td>89.9 77.4 74.5</td><td>85.1 74.7 71.2</td></tr><tr><td/><td>200</td><td>2</td><td>1</td><td>3.0M</td><td colspan="2">85.39 80.35</td></tr><tr><td>Dense LSTM (2 hidden layers)</td><td>200 200 200</td><td>2 2 2</td><td>2 3 4</td><td>3.6M 4.3M 4.9M</td><td colspan="2">83.39 78.64 83.56 79.05 83.28 78.82</td></tr><tr><td/><td>200</td><td>2</td><td>5</td><td>5.6M</td><td colspan="2">83.70 78.99</td></tr><tr><td/><td>200</td><td>3</td><td>1</td><td>3.9M</td><td colspan="2">83.12 78.95</td></tr><tr><td>Dense LSTM (3 hidden layers)</td><td>200 200 200</td><td>3 3 3</td><td>2 3 4</td><td>5.4M 6.9M 8.3M</td><td colspan="2">83.08 78.67 82.38 78.15 82.56 77.91</td></tr><tr><td/><td>200</td><td>3</td><td>5</td><td>9.8M</td><td colspan="2">82.98 78.69</td></tr><tr><td colspan="3">3.3 EXTENSION OF VARIATIONAL DROPOUT</td><td/><td/><td/><td/></tr></table>

Peer review (iclr2018):
 This paper proposes a new type of RNN architectures called Dense RNNs. The authors combine several different RNN architectures and claim that their RNN can model long-term dependencies better, can learn multiscale representation of the sequential data, and can sidestep the exploding or vanishing gradients problem by using parametrized gating units. Unfortunately, this paper is hard to read, it is difficult to understand the intention of the authors. The authors make several claims without any supportive reference or experimental evidence. Both intuitive and theoretical justifications of the proposed architecture are not so convincing. The experiment is only done on PTB dataset, and the reported numbers are not that promising either. This paper tries to combine three different features from previous works, and unfortunately, it is not so well conducted.