5. RNN(순환신경망) 1강. RNN 원리
학습목표
- RNN의 개념과 구조를 설명할 수 있다.
- LSTM 구조 및 동작에 대해 설명할 수 있다.
- LSTM 실습 데이터셋을 준비할 수 있다.
학습내용
- RNN 개념과 구조 - LSTM 구조 및 동작 - LSTM 실습 데이터셋
1. RNN 개념과 구조 (1) RNN 개념
∙ Recurrent(반복적인, 순환적인) Neural Network
∙ 신호를 순환하여 시계열 신호와 같이 상호 관계가 있는 신호를 처리하는 인공 신경망
∙ 기존 Neural Network와는 달리 ‘기억(Hidden State)’을 가지고 있음
(2) RNN 구조
∙ 주로 순차적인 정보(Sequence)를 입력으로 받음 - 시계열 데이터(글의 문장, 음성 신호, 주가 차트 등)
[출처] 한빛미디어-코딩셰프의 3분 딥러닝, 케라스맛
(3) 입력-출력에 따른 활용 사례
∙ 입력과 출력은 네트워크에게 시키고 싶은 것이 무엇이냐에 따라 얼마든지 달라짐
2. LSTM 구조 및 동작 (1) LSTM
∙ Long Short-Term Memory
∙ Gradient Vanishing 문제를 해결하여 Long-Term Dependency 학습 가능
[출처] 한빛미디어-코딩셰프의 3분 딥러닝, 케라스맛
∙ Tanh 활성화 함수
- 입력 신호를 –1과 1 사이의 값으로 정규화
(2) LSTM 구조
∙ Long Short-Term Memory
∙ Gradient Vanishing 문제를 해결하여 Long-Term Dependency 학습 가능
[출처] https://colah.github.io/posts/2015-08-Understanding-LSTMs/
[출처] https://colah.github.io/posts/2015-08-Understanding-LSTMs/
(3) LSTM 동작 단계
① 지금까지의 Cell State에 저장된 정보 중에서 얼마만큼 망각(Forget)할 것인 지 결정
∙ Forget Gate
- 이전 단계의 Hidden State 와 현 단계의 입력 으로부터 0과 1 사이 의 출력 (Sigmoid 함수 사용)
[출처] https://colah.github.io/posts/2015-08-Understanding-LSTMs/
② 새로운 정보를 얼마만큼 Cell State에 저장할 것인지 결정
∙ Input Gate
- 어떤 값을 업데이트할 것인지 결정
- Tanh Layer를 사용하여 새로운 Cell State의 후보
을 생성[출처] https://colah.github.io/posts/2015-08-Understanding-LSTMs/
③ 예전 Cell State를 새로운 Cell State로 업데이트
- 예전 Cell State를 얼마만큼 망각할 것인가를 계산한 Forget Gate 결과값과 곱함
- 새로운 Cell State 후보와 얼마만큼 보존할 것인가를 계산한 Input Gate 결 과값을 곱함
- 두 값을 더하여 새로운 Cell State 값으로 결정
[출처] https://colah.github.io/posts/2015-08-Understanding-LSTMs/
④ 출력 값을 결정
∙ Output Gate
- 이전 Hidden State 값과 현재의 입력 값을 이용하여 산출
- 현재의 Cell State 값을 결합하여 현재의 Hidden State 값을 계산
[출처] https://colah.github.io/posts/2015-08-Understanding-LSTMs/
ü LSTM의 Gate 전체 구조
[출처] https://colah.github.io/posts/2015-08-Understanding-LSTMs/
3. LSTM 실습 데이터셋 (1) IMDB
∙ Internet Movie Database(IMDB)에서 수집한 감정(긍정적/부정적)으로 분류된 50,000개의 영화 리뷰 텍스트
- 실제 데이터셋의 일부
Review Text Sentiment
The movie has pointless story and worst music of all. 0 I loved this movie and music was best of all. 1 The screenplay of movie is amazing and I loved the action scenes. 1 The movie is just poor with no story and poor music. Combination of worst casting and music. 0 The movie is amazing because the fact that the romantic scenes are best. 1
(2) Reuters News Classification
∙ 46가지 토픽으로 라벨이 달린 11,228개의 뉴스로 이루어진 데이터셋 - 실제 데이터셋의 일부
News
The wattie nondiscriminatory mln loss for plc said at only ended said commonwealth could traders now april a after said from 1985 and from foreign
april prices its account year a but in this mln home an states earlier and rise and revs its a but psbr oils several and shareholders and dividend its all mln
agreed largely april are states will billion total and against pct dlrs the termination payment airport takes visibility geological begin up said fully
bank expects commodity total is giant a recreation this takes leroy series termination payment airport mln a for capital 1 pre 50 american east said in
council takes leroy recommend's france a but u any 4 s 1st losses pct dlrs the major It owned year reuter consumption year major an studying location
reuter any were product trade reuter country's had some agreed largely shareholders farm year It reuter paid had from standard It exchange an position
point consumers It company its then report tomorrow sluggish shopping figures said level one conditions june kuomintang sources which treasury stocks had
were is its for reported pct dlrs
(3) International Airline Passengers
∙ 세계 항공 여행 승객 수의 증가에 대한 데이터 - 실제 데이터셋의 일부
Month
International Airline Passengers
1949-01 112
1949-02 118
1949-03 132
1949-04 129
1949-05 121
1949-06 135
1949-07 148
Month
International Airline Passengers
1960-06 535
1960-07 622
1960-08 606
1960-09 508
1960-10 461
1960-11 390
1960-12 432
2006-03-01 78.099999999999994
2006-04-01 81.400000000000006
2006-05-01 83.599999999999994
2006-06-01 83.799999999999997
2006-07-01 83.599999999999994
학습정리
1. RNN 개념과 구조
∙ 신호를 순환하여 시계열 신호와 같이 상호 관계가 있는 신호를 처리하는 인공신경망
2. LSTM 구조 및 동작
∙ RNN의 장기의존성 문제를 해결한 LSTM 구조와 동작 단계에 대해 설명
3. LSTM 실습 데이터셋
∙ IMDB, International Airline Passengers, Reuter News, 아파트 매매 지수 데이터셋 평가하기
1. 기억 노드를 가지고 순차적인 데이터를 처리하는 인공신경망으로 올바른 것은?
① ANN
② DNN
③ CNN
④ RNN
- 정답 : ④번
해설 : RNN은 다른 인공신경망과 달리 기억 노드를 가지고 있어 순차적인 데이터를 처리하기 쉽다.
2. Cell state에 저장된 정보 중 얼마만큼 망각할 것인지 결정하는 Gate를 고르시오.
① Forget Gate
② Cell State
③ Input Gate
④ Output Gate
- 정답 : ①번
해설 : Cell State에 저장된 정보 중 얼마만큼 망각할 것인지 결정하는 Gate는 Forget Gate이다.