LSTM(Long Short-Term Memory)

임정민·2024년 5월 15일
0

딥러닝 개념

목록 보기
2/13
post-thumbnail

*본 게시글은 유튜브 '김성범[ 교수 / 산업경영공학부 ]' [핵심 머신러닝 RNN, LSTM and GRU] 자료를 참고한 점임을 알립니다.

LSTM에 대해서

1. 기본 컨셉

  • 장기 의존성 문제를 완화한 RNN 개선 모델
  • 기존 RNN의 'Hidden State(hth_{t})'와 더불어 'Cell State(ctc_{t})'를 제안
  • Forget gate (ftf_{t}), Input gate (iti_{t}), Output gate (oto_{t}) 세가지 gate를 추가한 구조

  • hth_{t}를 다른 방식으로 계산하여 장기 의존성 문제 완화
  • 핵심인 hth_{t}를 구하는 데 있어 ctc_{t}를 활용

2. 전체 구조

  • 최종 목표인 tt시점의 yty_{t}를 구하기 위한 hth_{t}

3. 원리

  • 첫번째 단계
    c~t\tilde{c}_t(임시 Cell State)를 구하기 위한 xtx_{t}(현재 Input), ht1h_{t-1}(이전 Hidden State)

  • 두번째 단계
    ctc_{t}(현재 Cell State)를 구하기 위한 ftf_{t}(Forget gate), ct1c_{t-1}(이전 Cell State), iti_{t}(Input gate), c~t\tilde{c}_t(임시 Cell State)

  • 세번째 단계
    hth_{t}(Hidden State)를 구하기 위한 oto_{t}(Output gate), ctc_{t}(현재 Cell State)

  • 종합

4. Forget / Input / Output Gate

  • 과거 Cell State에서 사용하지 않을 데이터에 대한 가중치

    ft=σ(Wxhfxt+Whhfht1+bhf)f_{t}=\sigma(W_{xh_{f}}x_{t}+W_{hh_{f}}h_{t-1}+b_{h_{f}})

  • 현재 Input에서 사용할 데이터를 저장하기 위한 가중치

    it=σ(Wxhixt+Whhiht1+bhi)i_{t}=\sigma(W_{xh_{i}}x_{t}+W_{hh_{i}}h_{t-1}+b_{h_{i}})

  • 출력할 Hidden State에 Cell State를 얼마나 반영할 것인지에 대한 가중치

    ot=σ(Wxhoxt+Whhoht1+bho)o_{t}=\sigma(W_{xh_{o}}x_{t}+W_{hh_{o}}h_{t-1}+b_{h_{o}})

  • Gate는 0~1 사이의 값을 가지는 벡터

5. Cell State

  • c~t\tilde{c}_t (임시 Cell State)

    c~t=tanh(Wxhgxt+Whhght1+bhg)\tilde{c}_t = tanh(W_{xh_{g}}x_{t}+W_{hh_{g}}h_{t-1}+b_{h_{g}})

  • ct{c}_t (현재 Cell State)

    ct=ftct1itc~t(=elementwiseproduct)c_{t} = f_{t} \otimes c_{t-1} \oplus i_{t} \otimes \tilde{c}_t (\otimes = elementwise-product)

  • [1] Forget Gate의 역할 (ct1c_{t-1}의 정보를 조절)

  • [2] Input Gate의 역할 (c~t\tilde c_{t}의 정보를 조절)

  • [1] + [2] 를 합하여 ct{c}_t (현재 Cell State)

6. Hidden State

  • Output Gate

    ot=σ(Wxhoxt+Whhoht1+bho)o_{t}=\sigma(W_{xh_{o}}x_{t}+W_{hh_{o}}h_{t-1}+b_{h_{o}})
  • Hidden State

    ht=ottanh(ct)h_{t} = o_{t} \odot tanh(c_{t})

7. ETC

  • LSTM with peephole connections
  • Gate에 ctc_{t} or ct1c_{t-1} 정보를 활용
    ft=σ(Wxhfxt+Whhfht1+Wchfct1+bhf)f_{t}=\sigma(W_{xh_{f}}x_{t}+W_{hh_{f}}h_{t-1}+W_ch_{f}c_{t-1}+b_{h_{f}})
    it=σ(Wxhixt+Whhiht1+Wchict1+bhi)i_{t}=\sigma(W_{xh_{i}}x_{t}+W_{hh_{i}}h_{t-1}+W_ch_{i}c_{t-1}+b_{h_{i}})
    ot=σ(Wxhoxt+Whhoht1+Wchoct+bho)o_{t}=\sigma(W_{xh_{o}}x_{t}+W_{hh_{o}}h_{t-1}+W_ch_{o}c_{t}+b_{h_{o}})

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

참고 자료

profile
https://github.com/min731

0개의 댓글

관련 채용 정보