D ENSE R ECURRENT N EURAL N ETWORK WITH A TTENTION G ATE
Anonymous authors
Paper under double-blind review
A BSTRACT
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 ﬂows 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 ﬂows.
We describe the relation between the attention gate and the gradient ﬂows 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.
I NTRODUCTION
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.
, the boundary information is also learned by implementing three operations such as update, copy and ﬂush 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 (cid:48)
(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, which enhances overall performance.
Feedforward depth and recurrent depth has orthogonal property.
As the connection for gated feedback is not overlapped with extensions to two orthogonal directions, all three features can be modeled as one architecture, which enhances 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.
B ACKGROUND
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 overﬁtting.
2. E XTENSION OF R ECURRENT N EURAL N ETWORK M ODELS
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 deﬁned as follows:
[Equation]
where U and W are respectively the feedforward and recurrent weight matrix and φ means an element-wise nonlinear function such as Tanh .
In simple recurrent layer, the last hidden state h t −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 deﬁned 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 deﬁned 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 jt 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 jt from the preceding hidden states h
it − 1 at different layer of h jt , the model adaptively captures the multiple timescales from long-term dependency, which is deﬁned 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 ﬂows 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 ﬂows from each hidden state to multiple preceding hidden states of all layers, which is deﬁned as follows:
[Equation]
where w jg 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 jt , forget gate f jt , output gate o jt , and memory cell gate
˜ c
jt are deﬁned as follows:
[Equation]
Compared with conventional LSTM, the gated feedback LSTM has gated feedback function in the memory cell gate
˜ c jt .
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]
where the dot product means element-wise multiplication.
2. D ROPOUT OF R ECURRENT N EURAL N ETWORK
As dropout is one method of neural network regularization, it prevents the model from being overﬁtted 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 jt , 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 efﬁciently.
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:
[Equation]
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:
[Equation]
D ENSE R ECURRENT N EURAL N ETWORK
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 deﬁned as follows:
[Equation]
where g ( k,i ) → j is the attention gate, which is deﬁned 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 deﬁned as follows:
[Equation]
[Table]
(a)
[Table]
ℎ
[Table]
ℎ  ℎ  ℎ 
[Table]
ℎ  ℎ   (d)
[Table] [Figure]
[Equation]
14d
[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. I NTUITIVE A NALYSIS
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 jt − 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
[Figure] 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 reﬂect 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 deﬁne 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
jt − k and input h j − 1 t at certain time step as in ( 13 ).
3. T HEORETICAL A NALYSIS
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 ﬁnd 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 jmax is less than 1, the gradient with respect to U j would be exploded and if the A jmin is greater than 1, gradient with respect to U j would be vanished.
In dense recurrent network, there are more paths to ﬂow 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 jmax is KLA ( k,i )
→ j max , which reduces the vanishing gradient boundary fromto 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]
(18) 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 ) · Ux + θ ) .
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ˇsgorin circle theorem (GST, Gerˇshgorin (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 =
φ ( Uh t ) .
Then, the Jacobian matrix
A =
∂h t +1 ∂h t is U T diag [ φ (cid:48)
( Uh t )] .
By letting γ be a maximal bound on diag [ φ (cid:48)
( Uh t )] and ρ max be the largest singular value of U T , the norm of the Jacobian satisﬁes using the triangle inequality as follows:
[Equation]
The value γρ max is less than 1, the vanishing gradient problem happens and the (cid:107) A (cid:107) is greater than 1, the exploding gradient problem happens as the range of the (cid:107) A (cid:107) 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 simpliﬁed recurrent connection with the attention gate is h t +
= φ ( gUh t ) where g is U g , h t .
Then, the
Jacobian matrix A =
∂h t +1 ∂h t is expressed as follows:
[Equation]
The spectrum of (22) is expressed as follows:
[Equation]
The scaled term term g + g (cid:48)
U g,i h t,i in (23) can be approximated as g as shown in Figure 2(b).
Thus, the upper bound of (cid:107) A (cid:107) is approximately less than 1 so that the attention gate g can alleviate the exploding problem.
[Table]
E XTENSION OF V ARIATIONAL D ROPOUT
In dense RNN, as recurrent depth increases
[Table]
the number of parameters also increases
[Table]
which makes the model vulnerable to overﬁtting to training dataset.
To prevent the model from overﬁtting to training dataset
[Table]
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
[Table]
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]
E XPERIMENT
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 ﬁxed as 200, 650, and 1500, which are called as small, medium, and large network.
In this paper, we ﬁxed 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:
[Equation]
The (12) is rewritten as follows:
[Equation] [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 conﬁgured 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.
C ONCLUSION
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 ﬂows.
To evaluate the effect of dense connections, we used Penn
Treebank corpus (PTB).
The result of dense connection was conﬁrmed 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.