3 Model Architecture
- Paper: Paper Overview
- PDF: PDF, tr. 2
- Trước: 03 - 2 Background
- Sau: 05 - 4 Why Self-Attention
Bằng chứng cấu trúc
Heading gốc 3 Model Architecture xuất hiện tại trang PDF vật lý 2 (text layer).
Ghi chú kế thừa (nguyên văn)
Nguồn: ghi chú gốc. Chưa tái xác minh từng claim theo PDF.
Kiến trúc Transformer gốc
Transformer gốc là encoder-decoder architecture:
source tokens
-> token embeddings + positional encodings
-> encoder stack N=6
-> decoder stack N=6, dùng shifted target tokens
-> linear + softmax
-> output probabilitiesEncoder layer có hai sublayers:
- multi-head self-attention;
- position-wise feed-forward network.
Decoder layer có ba sublayers:
- masked multi-head self-attention trên output prefix;
- encoder-decoder attention, trong đó decoder attend sang encoder output;
- position-wise feed-forward network.
Mỗi sublayer đều được bọc bằng residual connection và layer normalization:
Paper dùng layers và cho base model. PDF, tr. 3
Scaled dot-product attention
Attention nhận query, keys, values và trả ra weighted sum của values. Công thức lõi:
Chia cho để tránh dot product có magnitude quá lớn khi lớn, khiến softmax đi vào vùng gradient rất nhỏ. PDF, tr. 4
Multi-head attention
Thay vì chạy một attention duy nhất trên toàn bộ , paper project thành nhiều subspace rồi chạy attention song song:
Base model dùng heads, . PDF, tr. 5
Ba nơi dùng attention
Paper dùng multi-head attention theo ba cách:
- encoder self-attention: đều đến từ encoder layer trước;
- decoder masked self-attention: decoder chỉ attend tới các vị trí hiện tại/quá khứ;
- encoder-decoder attention: query từ decoder, key/value từ encoder output. PDF, tr. 5
Feed-forward network
Mỗi layer có position-wise FFN:
Paper dùng và . Đây là cùng một FFN áp dụng độc lập cho từng position, nhưng parameters khác nhau giữa các layer. PDF, tr. 5
Positional encoding
Vì model không có recurrence/convolution, paper cộng positional encodings vào input embeddings ở đáy encoder và decoder. Sinusoidal encoding:
Paper chọn sinusoidal vì hypothesize rằng nó giúp model học relative position dễ hơn và có thể extrapolate sang sequence dài hơn training. Learned positional embeddings cho kết quả gần như tương đương trong Table 3 row E. PDF, tr. 6