모든 정보와 슬라이드는 "MIT 6.S191 (2023): Recurrent Neural Networks, Transformers, and Attention"을 참고했다.
Sequence Modeling
앞으로 나오는 ML을 잘 이해하기 위해 해당 그림을 잘 아는 것이 중요할 것 같다.
단순히 1대1 input output이 아니라 이제부터는 sequence to 1, 1 to sequence, sequence to sequence 형식이 나올 것이다.
그렇다면 single ➡️ single 에서 sequence ➡️ sequence 를 하는 방법은 single을 복사해서 여러 개 만든 방식이 있을 것이다.
😭 하지만 복제된 것들은 서로 영향을 주고 받지 못한다.
그래서 이전 기록 넘겨주기 t = time steps
$h_{t-1}$를 사용해 $h_{t}$를 얻는다. 같은 함수가 각 반복 step에서 똑같이 사용된다.
이렇게 INPUT에서 OUTPUT까지의 과정만 본다면 해당 그림과 같다. 중간 hidden state에서는 h에 대한 weight matrix가 있고, x에 대한 weight matrix가 있다. 마지막에 output에 대해서는 h에 weight를 곱해주면 된다.
sequence를 모델링하기 위해서는
- 다양한 길이의 sequence를 다룰 수 있어야 한다(Handle variable-length sequences)
- 멀리 떨어져 있더라도 서로의 연관성(dependencies)를 track할 수 있어야 한다 (Track long-term dependencies)
- sequence 순서에 대한 정보를 유지할 수 있어야 한다 (Maintain information about order)
- sequence 사이 다른 timestep 사이의 weight를 서로 공유할 수 있어야 한다. (Share parameters across the sequence)
Encoding Language for a Neural Network
one-hot embedding : 각 단어를 index에 따라 임베딩 하기
Learned embedding : NN을 통해 단어 간 관계 알아내기
Backpropagation Through Time (BPTT)
기존 Backpropagation 뿐만 아니라 시간에 따른 backpropagation도 진행 되어야 한다
Gradient issues
Exploding gradients: weight matrix 가 너무 크게 되면 gradient가 blow up 해버림
- gradient clipping을 통해 해결, 큰 gradient를 scale back
Vanishing gradients: weight matrix 가 너무 작으면 gradient가 없어짐
- Activation function
- Weight initialization
- Network architecture
🤔 왜 vanishing gradient가 문제가 될까?
사실 서로 가까운 관계에 있는 단어들일 경우 뻔한 결과를 내는 것은 쉽고 문제가 되지 않음
하지만 서로 멀리 있어 예측하기 어려운 경우(long term dependency) RNN이 이 둘과의 관계를 찾기가 어려워짐
Trick #1 : Activation Functions
ReLU를 사용하여 x>0일때 gradient가 줄어들지 않도록 한다
다른 함수(sigmoid, tanh derivative)와 달리 ReLU는 x>0에서 줄지 않고 1 이여서 가능하다
Trick #2 : Parameter Initialization
identity matrix로 weight를 initialize하거나 bias들을 0으로 initialize해서 0으로 줄지 않도록 도움을 주기
Trick #3 : Gated Cells
각 recurrent unit의 information을 더하거나 빼서 information flow를 control 하는 방법 - 중요한 정보만 유지할 수 있도록 하는 것!
ex) LSTM, GRU
Long Short Term Memory (LSTMs)
controlled information flow through gates
RNN Applications & Limitations
Application example : Music Generation 😏해봐야지 https://github.com/aamini/introtodeeplearning/tree/master/lab1
introtodeeplearning/lab1 at master · aamini/introtodeeplearning
Lab Materials for MIT 6.S191: Introduction to Deep Learning - aamini/introtodeeplearning
github.com
Limitations
- Encoding bottleneck(모든 정보가 maintain 되었는 지 보장하기 어려움)
- Slow, no parallelization
- Not long memory (엄청 큰 sequnce data는 다루지 못함...)
© Alexander Amini and Ava Amini
MIT Introduction to Deep Learning
IntroToDeepLearning.com
'딥러닝' 카테고리의 다른 글
Language Deep Learning 찍먹 (2) | 2024.06.13 |
---|---|
MIT 6.S191 (2023): Convolutional Neural Networks (2) | 2024.06.07 |
MIT 6.S191 (2023): Recurrent Neural Networks, Transformers, and Attention (44:50~) (0) | 2024.06.07 |
MIT 6.S191 (2023): Deep Generative Modeling (41:25~ GAN) (0) | 2024.06.06 |
MIT 6.S191 (2023): Deep Generative Modeling (~41:25 VAE) (0) | 2024.06.06 |