本文是根据WildML的Recurrent Neural Networks Tutorial写的学习笔记。
循环神经网络适用于处理序列化信息,比如:语言翻译,语音识别等。
如果,我们要实现一个翻译功能。首先需要理解原句中每个单词的含义。 这就需要根据上下文来理解。 假如:原句中的每个单词,以此对应神经网络中一个隐藏层。 在传统的神经网络框架中,隐藏层直接传递的是一个矢量Out。 这个Out矢量是原句当前每个词的一个输出,比如:含义等等。 那么,如何保存和传递上下文这个信息呢? 循环神经网络提出一个状态(state)的概念,用于传递上下文。
与传统的神经网络架构有许多不同之处。
原文中计划实现一个循环神经网络,用于发现自然语言句子中单词出现的模式,最终可以生成一些合理的句子。
理解:y的每n位是x前n位的期望输出。
每个输入\(X_t\)(尽管有8000维),只有一个维度有值且为1,代表第\(t\)的单词的token的维度。 比如:what的token是51。那么\(X_t\)只有第51位为1,其它都是0。 这个叫做one-hot vector。 输出:每个token的可能性。
state的维度是100。
s_t = tanh(x_tU + s_{t_1}W) \\ o_t = softmax(s_tV) \\ where \\ x_t.dimension = 8000 \\ o_t.dimension = 8000 \\ s_t.dimension = 100 \\ U.dimension = 100 * 8000 : x_tU \text{ is a 100 dimension vector} \\ W.dimension = 100 * 100 : s_{t-1}W \text{ is a 100 dimension vector} \\ V.dimension = 8000 * 100 : s_tV \text{ is a 8000 dimension vector}
i = \sigma(U^ix_i + W^is_{t-1} + b^i) \\ i \text{: input gate, defines how much of the newly computed state for the current input you want to let through.} \\ f = \sigma(U^fx_i + W^fs_{t-1} + b^f) \\ f \text{: forget gate, defines how much of the previous state you want to let through.} \\ o = \sigma(U^ox_i + W^os_{t-1} + b^o) \\ o \text{: output gate, defines how much of the internal state you want to expose to the external network.} \\ g = tanh(U^gx_i + W^gs_{t-1} + b^g) \\ g \text{: a candidate hidden state.} \\ c_t = c_{t-1} \circ f + g \circ i \\ c_t \text{: the internal memory of the unit.} \\ s_t = tanh(c_t) \circ o
先看看计算公式: x_e = Ex_t \\ z = \sigma(U^zx_e + W^zs_{t-1} + b^z) \\ r = \sigma(U^rx_e + W^rs_{t-1} + b^r) \\ h = tanh(U^hx_e + W^h(s_{t-1} \circ r) + b^h) \\ s_t = (1 - z) \circ h + z \circ s_{t-1} \\ o_t = Vs_t + c