文章目录
往期文章链接目录
Sequence Data
There are many sequence data in applications. Here are some examples
-
Machine translation
- from text sequence to text sequence.
-
Text Summarization
- from text sequence to text sequence.
-
Sentiment classification
- from text sequence to categories.
-
Music Generation
- from nothing or some simple stuff (character, integer, etc) to wave sequence.
-
Name entity recognition (NER)
- From text sequence to label sequence.
Why not use a standard neural network for sequence tasks
-
Inputs, outputs can be different lengths in different examples. This can be solved by standard neural network by paddings with the maximum lengths but it’s not a good solution since there would be too many parameters.
-
Doesn’t share features learned across different positions of text/sequence. Note that Convolutional Neural Network (CNN) is a good example of parameter sharing, so we should have a similar model for sequence data.
RNN
![](https://i-blog.csdnimg.cn/blog_migrate/8700c8484407a8988c240c235b1f7210.png#pic_center)
A Recurrent Neural Network (RNN) can be thought of as multiple copies of the same network, each passing a message to a successor. This chain-like nature reveals that recurrent neural networks are intimately related to sequences. Therefore, they’re the natural architecture of neural network to use for sequence data. Note that it also allows previous outputs to be used as inputs.
![](https://i-blog.csdnimg.cn/blog_migrate/ad79a805ec798c29cc73dccc21201375.png#pic_center)
For each time step t t t, the activation a < t > a^{<t>} a<t> and the output y < t > y^{<t>} y<t> are expressed as follows:
-
a < t > = g 1 ( W a a a < t − 1 > + W a x x < t > + b a ) a^{<t>}=g_{1}\left(W_{a a} a^{<t-1>}+W_{a x} x^{<t>}+b_{a}\right) a<t>=g1(Waaa<t−1>+Waxx<t>+ba)
-
y < t > = g 2 ( W y a a < t > + b y ) y^{<t>}=g_{2}\left(W_{y a} a^{<t>}+b_{y}\right) y<t>=g2(Wyaa<t>+by)
These calculation could be visualized in the following figure
![](https://i-blog.csdnimg.cn/blog_migrate/d9b5f2ae2b121d908f2db6738a560142.png#pic_center)
Note:
-
dimension of W a a W_{a a} Waa: (number of hidden neurons, number of hidden neurons)
-
dimension of W a x W_{a x} Wax: (number of hidden neurons, length of x x x)
-
dimension of W y a W_{y a} Wya: (length of y y y, number of hidden neurons)
-
The weight matrix W a a W_{a a} Waa is the memory the RNN is trying to maintain from the previous layers.
-
dimension of b a b_a ba: (number of hidden neurons, 1)
-
dimension of b y b_y by: (length of