본문 바로가기
AI/딥러닝 기초(Deep learning)

[딥러닝] GRU(Gated Recurrent Unit)

by Hyen4110 2021. 5. 10.
반응형

이 글은 아래 사이트를 정리하여 작성한 글입니다. 

pdfs.semanticscholar.org/25f0/625a92f6054b11057423111f9285c78376fe.pdf

d2l.ai/chapter_recurrent-modern/gru.html

 

9.1. Gated Recurrent Units (GRU) — Dive into Deep Learning 0.16.3 documentation

 

d2l.ai

 

GRU 이미지는 아래 블로그를 일부 참고하였습니다.

excelsior-cjh.tistory.com/185

 

1. GRU의 등장 배경

-  LSTM은 RNN의 치명적인 한계점이었던, 'Long-term dependency' 문제를 해결하면서 긴 시퀀스를 가진 데이터에서도 좋은 성능을 내는 모델이 되었지만, 복잡한 구조 때문에 RNN에 비하여 파라미터가 많이 필요하게 되었습니다. 

- 파라미터가 많아지는데 데이터가 충분하지 않은 경우, 오버피팅이 발생하는데, 이러한 단점을 개선하기 위하여 LSTM의 변형인 GRU가 등장하게 되었습니다. 

- GRU는 2014년 조경현 외 3인의 논문에서 처음 제안되었습니다.

 

2. GRU란?

- GRU의 핵심은 아래 두가지 입니다.

  (1) LSTM의 forget gate와 input gate를 통합하여 하나의 'update gate'를 만든다.

  (2) Cell State와 Hidden State를 통합한다.

- GRU는 LSTM에 비하여 파라미터수가 적기 때문에 연산 비용이 적게 들고, 구조도 더 간단하지만, 성능에서도 LSTM과 비슷한 결과를 냅니다. 

 

<LSTM과 다른점>

LSTM GRU
gate 수 3개(forget, input, output) gate 수 2개(reset, update)

Control the exposure of memory content (cell state) Expose the entire cell state to other units in the network
Has separate input and forget gates Performs both of these operations together via update gate
More parameters Fewer parameters

 

1. LSTM의 Cell State(C(t))와 Hidden state(h(t))가 GRU에서는 하나의 벡터 (h(t))로 합쳐졌다.

2. LSTM의 forget, input gate는 update gate로 통합, output gate는 없어지고, reset gate로 대체(이후 자세히 설명)

3. LSTM에서는 forget과 input이 서로 독립적이었으나, GRU에서는 전체 양이 정해져있어(=1), forget한 만큼 input하는 방식으로 제어한다. 이는 gate controller인 z(t)에 의해서 조절된다.  

   => z(t)가 1이면 forget gate가 열리고, 0이면 input gate가 열린다.

https://excelsior-cjh.tistory.com/185

 

3. GRU 진행 단계

3.1 Gate

 

 

[1] Reset gate, r(t)

 : 이전의 정보를 얼마나 잊어야하는지를 결정합니다.

 

[2] Update gate, z(t)

 : 이전의 정보(기억)을 얼마나 통과(유지)시킬지를 결정합니다. 

 

 

 

 

 

 

 

3.2 Candidate Hidden State

: hidden layer의 후보(candidate)로 reset gate인 r(t)와 Uh(t-1)을 곱하여, 이전 타임 스텝에서 무엇을 지워야할지를 결정합니다.

: tanh 함수는 -1 에서 1 사이의 값을 가지므로, candidate hidden state도 -1에서 1사이 값을 가집니다.

 

: updat gate를 아직 반영하지 않았기 때문에 아직까지는

'candidate' hidden state입니다.

: reset gate 를 모두 1, update gate를 모두 0으로 설정한다면, 모델은 Vanilla RNN과 같아집니다. 

 

 

 

3.3 Hidden State

: 이제 update gate를 합칠 차례입니다. update gate는 얼마나 새로운 hidden state(h(t)) 가 이전 hidden state(h(t-1)과 같을지 아니면 새로운 cadidate hidden state이 많이 사용될지를 결정합니다.

: z(t)가 0이라면 old state(h(t-1))을 유지하고, 1이라면 candidate state(tilda h(t))로 완전히 대체됩니다.

 

 

4. Summary

- Reset gate는 short-term dependency를 의미

- Update gate는 long-term dependency를 의미

 

 

[그 외]

1. https://towardsdatascience.com/understanding-gru-networks-2ef37df6c9be

 

Understanding GRU Networks

In this article, I will try to give a fairly simple and understandable explanation of one really fascinating type of neural network…

towardsdatascience.com

 

반응형

댓글