일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- NMF
- 자기조직화지도
- TFX
- gaze estimation
- Clustering
- cross domain
- VGGNet
- 경사하강법
- nlp
- Support Vector Machine
- Binary classification
- NER
- Generative model
- Python
- tensorflow
- SOMs
- ResNet
- AI 윤리
- Transfer Learning
- Ann
- MLOps
- Logistic Regression
- stemming
- textmining
- RNN
- LSTM
- 군집화
- BERT
- Attention
- Gradient Descent
- Today
- Total
juooo1117
[Module 6] Deep Learning: Seq2Seq with Attention for Natural Language Understanding and Generation 본문
[Module 6] Deep Learning: Seq2Seq with Attention for Natural Language Understanding and Generation
Hyo__ni 2024. 1. 13. 20:53Part 4. Seq2Seq with Attention for Natural Language Understanding and Generation
RNN(Recurrent Neural Networks)
Given a sequence data, we recursively run the same function over time. → sequence data에 특화된 형태이다.
We can process a sequence of vectors x by applying a recurrence formula at every time step → 동일한 function을 반복적으로 호출하는 형태를 가지고 있다.
(시간에 따라 순차적으로 변화하는 입력이 들어온다면, 현재 시간과 이전 시간의 hidden state vector를 고려해서 현재 시간의 hidden state vector를 만듦)
→ Note: the same function with the same set of parameters are used at every time step.
Character-level Language Model
e.g. training sequence : 'hello'
각각의 character들을 하나의 vocabulary로 구성하고, vocabulary 상에서 각각의 character들을 categorical variable 형태로 encoding한다. → one-hot vector 형태로 나타내게 된다.
At test-time sample characters one at a time, feed back as an input to the model at the next time step, which is called auto-regressive model.
- Vanilla RNNs are simple but don't work very well due to a gradient vanishing or exploding problem.
- Thus, an advanced RNN models such as LSTM or GRU are often used in practice.
Seq2Seq Model
It takes a sequence of words as input and gives a sequence of words as ouput.
It is composed of an encoder and a decoder.
Many NLP applications exist, e.g., machine translation, dialog systems, and so on.
Encode source into a fixed dimensional vector, use it as an initial hidden-state vector h0 for a decoder model.
Process of Encoder
*정보를 추출
입력 문장은 단어별로 각 time step에 해당 vector로 주어진다. → RNN module이 매 time step마다 정보를 처리하고 축적하는 과정을 거친다. → 문장을 다 읽고 나서 마지막 time step 에서 나온 hidden state vector ht는 기본적으로 입력 sequence에 있는 모든 단어들의 정보를 잘 축적하는 역할을 하는 vector
Process of Decoder
*예측과정을 수행
Start of sentence 단어를 주어서 문장생성을 시작할 것임을 알려주고 → 다음에 나타날 단어를 예측하는 task를 수행하게 된다. (즉, 예측한 단어를 다음 time step에 입력으로 주어서 그다음 단어를 연쇄적으로 예측하는 방식!) → End of sentence token이 예측될 때까지 생성과정을 반복적으로 수행하게 된다.
단, seq2seq model 의 경우, 입력 sequence가 짧던 길던 매 time step마다 생성되는 RNN의 각 time step의 hidden state vector는 특정한 같은 dimension으로 이루어져 있어야 한다는 제약 조건이 있다. (dim이 같아야 이전 step의 output vector가 다시 다음 step의 input vector 로 사용될 수 있기 때문!)
→ sequence가 길어지면 정보가 유실되는 부분이 많아서 결과가 좋지않은 경우가 있음! (bottleneck problem)
Attention provides a solution to the bottleneck problem of the original seq2seq model
→ at each time step of the decoder, allow the decoder to utilize a different part of the osurce sequence.
Use the attention distribution to weighted sum of the encoder hidden states.
The attention output mostly contains information the hidden states that received high attention.
Concatenate attention output with decoder hidden state, then use to compute 'y(1)hat' as before.
Advantages of Attention
1. Attention significantly imporves NMT performance (It is effective to allow the decoder to focus on particular part of the source sequence)
2. Attention solves the bottleneck problem (Attention allows the decoder to look directly at the source sequence, addressing the bottleneck problem)
3. Attention helps with vanishing gradient problem (Provides a shortcut to faraway states)
4. Attention provides interpretability(해석가능능력)
'Artificial Intelligence > LG Aimers: AI전문가과정' 카테고리의 다른 글
[Module 6] Deep Learning: Self-Supervised Learning & Pre-Trained Models (0) | 2024.01.14 |
---|---|
[Module 6] Deep Learning: Transformer (1) | 2024.01.14 |
[Module 6] Deep Learning: CNN and Image Classification (0) | 2024.01.12 |
[Module 6] Deep Learning: Training Neural Networks (0) | 2024.01.12 |
[Module 6] Deep Learning: Deep Neural Networks (0) | 2024.01.12 |