RNN의 장기문맥 의존성을 해결하기 위해 탄생한 모델

게이트의 여닫는 정도는 가중치로 표현되며 가중치는 학습으로 알아낸다.

가중치

순환 신경망의 $\{U, V, W\}$에 4개를 추가하여 $\{U, U_i , U_o , W, W_i , W_o , V\}$

Model Concept

Cell State

Cell State에서 gate에 의해 정보가 추가되거나 삭제된다.

Gate

  1. Forget Gate

    Untitled

    $$ f_t=\sigma\left(W_f \cdot\left[h_{t-1}, x_t\right]+b_f\right) $$

  2. Input Gate

    Untitled

    $$ \begin{aligned}i_t & =\sigma\left(W_i \cdot\left[h_{t-1}, x_t\right]+b_i\right) \\\tilde{C}t & =\tanh \left(W_C \cdot\left[h{t-1}, x_t\right]+b_C\right)\end{aligned} $$

  1. Output Gate

    Untitled

    $$ \begin{aligned}o_t & =\sigma\left(W_o\left[h_{t-1}, x_t\right]+b_o\right) \\h_t & =o_t * \tanh \left(C_t\right)\end{aligned} $$

수식 요약

$$ \begin{aligned}f_t & =\sigma_g\left(W_f x_t+U_f h_{t-1}+b_f\right) \\i_t & =\sigma_g\left(W_i x_t+U_i h_{t-1}+b_i\right) \\o_t & =\sigma_g\left(W_o x_t+U_o h_{t-1}+b_o\right) \\\tilde{c}t & =\sigma_c\left(W_c x_t+U_c h{t-1}+b_c\right) \\c_t & =f_t \odot c_{t-1}+i_t \odot \tilde{c}_t \\h_t & =o_t \odot \sigma_h\left(c_t\right)\end{aligned} $$

ft = sigmoid(np.dot(xt, Wf) + np.dot(ht_1, Uf) + bf)  # forget gate
it = sigmoid(np.dot(xt, Wi) + np.dot(ht_1, Ui) + bi)  # input gate
ot = sigmoid(np.dot(xt, Wo) + np.dot(ht_1, Uo) + bo)  # output gate
Ct = ft * Ct_1 + it * np.tanh(np.dot(xt, Wc) + np.dot(ht_1, Uc) + bc)
ht = ot * np.tanh(Ct)

모델 요약