概要
本文介绍如何用Theano实现LSTM结构的循环神经网络。文中将以IMDB数据为例,用LSTM进行情绪分析。
数据
Large Movie Review Dataset dataset(IMDB dataset)
模型
在传统的RNN中,梯度反馈过程中的梯度反馈信号,会在大量的递归传递中逐渐消失。这意味着,传递矩阵的两级对学习过程有着巨大的影响:如果传递矩阵很小(比如最大特征值小于1),会导致消失;如果传递矩阵很大(比如最大特征值大于1),会导致学习的偏移。
LSTM引入了一种记忆单元的新结构:
记忆单元包括以下要素:
- 输入门(input gate)
- 与自递归链接的神经元(self-recurrent connection)
- 遗忘门(forget gate)
- 输出门(output gate)
定义变量如下:
-
xt
表示
t
时间存储单元(memory cell)层
-
-
bi
,
bf
,
bc
,
bo
是偏置向量
具体的计算过程如下:
- 计算
t
时间输入门的值
计算 t 时间遗忘门的激活值
ft :
t <script type="math/tex" id="MathJax-Element-2517">t</script>时间计算记忆单元的新状态:
结构图
代码
参考文献
LSTM模型介绍:
- Hochreiter, S., & Schmidhuber, J. (1997). Long short-term memory. Neural computation, 9(8), 1735-1780.
带有遗忘门的 LSTM:
Gers, F. A., Schmidhuber, J., & Cummins, F. (2000). Learning to forget: Continual prediction with LSTM. Neural computation, 12(10), 2451-2471.
More recent LSTM paper:Graves, Alex. Supervised sequence labelling with recurrent neural networks. Vol. 385. Springer, 2012.
关于Theano:Bastien, Frédéric, Lamblin, Pascal, Pascanu, Razvan, Bergstra, James, Goodfellow, Ian, Bergeron, Arnaud, Bouchard, Nicolas, and Bengio, Yoshua. Theano: new features and speed improvements. NIPS Workshop on Deep Learning and Unsupervised Feature Learning, 2012.
- Bergstra, James, Breuleux, Olivier, Bastien, Frédéric, Lamblin, Pascal, Pascanu, Razvan, Desjardins, Guillaume, Turian, Joseph, Warde-Farley, David, and Bengio, Yoshua. Theano: a CPU and GPU math expression compiler. In Proceedings of the Python for Scientific Computing Conference (SciPy), June 2010.
Thank you!