*본 게시글은 유튜브 '김성범[ 교수 / 산업경영공학부 ]' [핵심 머신러닝 RNN, LSTM and GRU] 자료를 참고한 점임을 알립니다.
LSTM에 대해서
1. 기본 컨셉
- 장기 의존성 문제를 완화한 RNN 개선 모델
- 기존 RNN의 'Hidden State(ht)'와 더불어 'Cell State(ct)'를 제안
- Forget gate (ft), Input gate (it), Output gate (ot) 세가지 gate를 추가한 구조

- ht를 다른 방식으로 계산하여 장기 의존성 문제 완화
- 핵심인 ht를 구하는 데 있어 ct를 활용
2. 전체 구조

- 최종 목표인 t시점의 yt를 구하기 위한 ht
3. 원리
-
첫번째 단계
c~t(임시 Cell State)를 구하기 위한 xt(현재 Input), ht−1(이전 Hidden State)

-
두번째 단계
ct(현재 Cell State)를 구하기 위한 ft(Forget gate), ct−1(이전 Cell State), it(Input gate), c~t(임시 Cell State)

-
세번째 단계
ht(Hidden State)를 구하기 위한 ot(Output gate), ct(현재 Cell State)

-
종합

-
과거 Cell State에서 사용하지 않을 데이터에 대한 가중치
ft=σ(Wxhfxt+Whhfht−1+bhf)

-
현재 Input에서 사용할 데이터를 저장하기 위한 가중치
it=σ(Wxhixt+Whhiht−1+bhi)

-
출력할 Hidden State에 Cell State를 얼마나 반영할 것인지에 대한 가중치
ot=σ(Wxhoxt+Whhoht−1+bho)

-
Gate는 0~1 사이의 값을 가지는 벡터
5. Cell State
-
c~t (임시 Cell State)
c~t=tanh(Wxhgxt+Whhght−1+bhg)

-
ct (현재 Cell State)
ct=ft⊗ct−1⊕it⊗c~t(⊗=elementwise−product)

-
[1] Forget Gate의 역할 (ct−1의 정보를 조절)

-
[2] Input Gate의 역할 (c~t의 정보를 조절)

-
[1] + [2] 를 합하여 ct (현재 Cell State)

6. Hidden State
-
Output Gate
ot=σ(Wxhoxt+Whhoht−1+bho)
-
Hidden State
ht=ot⊙tanh(ct)

7. ETC
- LSTM with peephole connections
- Gate에 ct or ct−1 정보를 활용
ft=σ(Wxhfxt+Whhfht−1+Wchfct−1+bhf) it=σ(Wxhixt+Whhiht−1+Wchict−1+bhi) ot=σ(Wxhoxt+Whhoht−1+Wchoct+bho)

- GRU
- LSTM의 구조를 개선하여 파라미터 개수를 줄임
- Forget Gate, Input Gate를 'Update Gate(zt)'로 통합
- Output Gate를 대체할 'Reset Gate(rt)' 정의
- Cell State, Hidden State를 'Hidden State'로 통합

참고 자료