T4-L04 — Transformer & Attention

Self-attention · Multi-head · Positional encoding · Transformer architecture

1. Self-Attention — Attention heatmap tương tác

Thử: click một token — heatmap cho thấy nó "nhìn" những token nào để hiểu nghĩa: attention là bảng tra ngữ cảnh học được.

Câu ví dụ

Click token để xem attention từ token đó:

Attention matrix A[i,j]

Attention từ token đã chọn

2. Multi-Head Attention — 8 heads khác nhau

3. Positional Encoding — Sinusoidal

Bảng giá trị PE (d=4, pos=0..4)

4. Transformer Architecture

5. RNN vs Transformer — Complexity so sánh