[NLP] Transformer 구조
1. Transformer 의 전체 구조
1) Embedding
2) Positional Encoding
3) Multi-head Self-Attention
4) Masked Multi-head Self-Attention
5) Decoder Multi-head Attention
6) Position-wise FFNN
7) Add & Norm
8) Dense & Softmax
2. Embedding
- 주어진 Input Sentence 를 토큰화 한다.
- Vocab 내에서 토큰에 대한 index를 찾는다.
- Index 에 해당하는 Vector를 가져온다.
- 초기에 이 Vector 는 초기화 되어 있으며, 학습된다.
3. Positional Encoding
- 문장 내에서 단어의 위치를 입력시키기 위해 이용한다.
- 다음의 두 문장은 같은 단어들로 구성되어 있지만, 단어의 순서에 의해 다른 의미를 갖는 문장이다.
- Positional Encoding 시에, 중요하게 고려해야할 2가지 사항이 있다.
1) 문장의 길이에 관계없이, 위치에 따른 positional encoding 값이 같아야 한다.
2) 단어 임베딩 값에 큰 영향을 주어서는 안되므로 작은 값을 가져야 한다.
4. Multi-head Self Attention
- Single 이 아닌 Multi-head Attention을 이용하는 이유는, 여러 관점에서 attention을 하기 위해서이다.
5. Masked Multi-head Self Attention
6. Decoder Multi-head Attention ( Multi-head Cross Attention)
7. Position-wise FFNN
8. Dense & Softmax
* reference
https://www.youtube.com/watch?v=AA621UofTUA&t=4262s
https://www.blossominkyung.com/deeplearning/transfomer-positional-encoding