ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s

This commit is contained in:
2026-08-20 13:12:50 +00:00
commit b119135836
10275 changed files with 3284984 additions and 0 deletions
@@ -0,0 +1,54 @@
{
"overall_score": 65,
"pass": false,
"issues": [
{
"page": 2,
"issue_type": "overcrowded",
"severity": "medium",
"suggestion": "要点数量达6条,超出建议的5条上限,建议将最后1-2条拆分至下一页或合并相似内容"
},
{
"page": 3,
"issue_type": "overcrowded",
"severity": "medium",
"suggestion": "要点数量达7条(含子要点),内容拥挤,建议将Recurrent models和Convolutional models分拆为两页展示"
},
{
"page": 13,
"issue_type": "readability",
"severity": "high",
"suggestion": "Learning rate公式存在LaTeX渲染错误(显示为“d_{text{model}}^{-0.5} \\cdot \\min(\\text{step_num}^{-0.5}, \\text{step_num} \\cdot \\text{warmup_steps}^{-1.5})”),需修正公式格式确保正确显示"
},
{
"page": 15,
"issue_type": "layout",
"severity": "low",
"suggestion": "底部要点符号不一致(混合使用“-”和“■”),建议统一使用项目符号“■”保持格式统一"
},
{
"page": 17,
"issue_type": "image_size",
"severity": "medium",
"suggestion": "注意力可视化图尺寸过小,文字和连线细节模糊不清,建议放大图片至页面70%以上面积或分拆为多页展示"
},
{
"page": 18,
"issue_type": "image_size",
"severity": "medium",
"suggestion": "指代消解可视化图尺寸不足,紫色线条和文字难以辨认,建议单独放大展示或增加图例说明"
},
{
"page": 19,
"issue_type": "overcrowded",
"severity": "medium",
"suggestion": "Limitations3条)和Future work(4条)共7个要点,内容过于密集,建议分拆为“局限性”和“未来工作”两页分别展示"
},
{
"page": 20,
"issue_type": "overcrowded",
"severity": "medium",
"suggestion": "结论要点达6条,超出建议数量,建议删除“Code available...”等次要信息或拆分至单独的“资源链接”页"
}
]
}
@@ -0,0 +1,251 @@
---
theme: default
---
# Attention Is All You Need
## A Revolutionary Architecture for Sequence Transduction
Ashish Vaswani et al.
NIPS 2017
---
## Abstract
- Proposes Transformer: first model based solely on attention mechanisms
- Dispenses with recurrence and convolutions entirely
- Achieves superior quality while being more parallelizable
- 28.4 BLEU on WMT 2014 English-to-German (↑2+ BLEU)
- 41.8 BLEU on WMT 2014 English-to-French (new state-of-the-art)
- Generalizes well to other tasks like English constituency parsing
---
## Background: The Problem with Traditional Approaches
- **Recurrent models (RNN/LSTM/GRU)**
- Inherently sequential computation
- Limited parallelization
- Difficult to learn long-range dependencies
- **Convolutional models**
- Fixed kernel size limits long-range dependencies
- O(n/k) or O(logk(n)) operations for distant connections
- Less efficient than attention for sequence tasks
---
## Key Innovation: Attention as the Core Mechanism
- **Self-attention** connects all positions with constant operations
- **Parallelization** possible across sequence positions
- **Long-range dependencies** modeled directly
- **Interpretability** through attention distributions
- **Computational efficiency** for typical sequence lengths
---
## Transformer Model Architecture
<img src="/paper_figure_1_transformer.png" class="h-[560px] w-full object-contain" />
The overall encoder-decoder structure with stacked self-attention and feed-forward layers.
---
## Encoder Architecture
- Stack of 6 identical layers
- Each layer has two sub-layers:
1. Multi-head self-attention mechanism
2. Position-wise fully connected feed-forward network
- Residual connections around each sub-layer
- Layer normalization after each sub-layer
- All sub-layers produce outputs of dimension dmodel = 512
---
## Decoder Architecture
- Stack of 6 identical layers
- Three sub-layers per layer:
1. Masked multi-head self-attention
2. Multi-head attention over encoder outputs
3. Position-wise fully connected feed-forward network
- Residual connections and layer normalization
- Masking prevents attending to future positions
- Output embeddings offset by one position
---
## Attention Mechanism
- Maps query and key-value pairs to output
- Output = weighted sum of values
- Weights computed by compatibility function of query and keys
**Scaled Dot-Product Attention:**
$$\text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V$$
- Scaling prevents gradients from becoming too small
- More efficient than additive attention in practice
---
## Multi-Head Attention
- Projects queries, keys, values h times with different linear projections
- Performs attention in parallel on projected subspaces
- Concatenates results and projects again
$$\text{MultiHead}(Q, K, V) = \text{Concat}(\text{head}_1, ..., \text{head}_h)W^O$$
where $\text{head}_i = \text{Attention}(QW_i^Q, KW_i^K, VW_i^V)$
- h = 8 parallel attention heads in base model
- $d_k = d_v = d_{\text{model}}/h = 64$
---
## Three Applications of Attention
1. **Encoder-decoder attention**
- Queries from decoder, keys/values from encoder
- Allows decoder to attend to all input positions
2. **Encoder self-attention**
- All keys, values, queries from previous encoder layer
- Each position attends to all positions in previous layer
3. **Decoder self-attention**
- Each position attends to previous positions in decoder
- Masking prevents attending to future positions
---
## Positional Encoding
- Injects sequence order information since no recurrence/convolution
- Added to input embeddings (same dimension dmodel)
- Uses sine and cosine functions of different frequencies:
$$PE_{(pos,2i)} = \sin(pos/10000^{2i/d_{\text{model}}})$$
$$PE_{(pos,2i+1)} = \cos(pos/10000^{2i/d_{\text{model}}})$$
- Allows model to learn relative position relationships
- Performed as well as learned positional embeddings
---
## Why Self-Attention?
| Aspect | Self-Attention | Recurrent | Convolutional |
|--------|----------------|-----------|---------------|
| Complexity | O(n²·d) | O(n·d²) | O(k·n·d²) |
| Parallelization | O(1) | O(n) | O(1) |
| Long-range paths | O(1) | O(n) | O(logk(n)) |
- More parallelizable than RNNs
- Better at capturing long-range dependencies than CNNs
- More efficient for typical sequence lengths (n < d)
- More interpretable through attention weights
---
## Training Details
- **Datasets**: WMT 2014 EN-DE (4.5M) and EN-FR (36M)
- **Batching**: ~25,000 source and target tokens per batch
- **Hardware**: 8 NVIDIA P100 GPUs
- **Optimizer**: Adam (β1=0.9, β2=0.98, ϵ=10⁻⁹)
- **Learning rate**: $d_{\text{model}}^{-0.5} \cdot \min(\text{step_num}^{-0.5}, \text{step_num} \cdot \text{warmup_steps}^{-1.5})$
- **Regularization**: Residual dropout (Pdrop=0.1), label smoothing (ϵls=0.1)
---
## Machine Translation Results
| Model | EN-DE BLEU | EN-FR BLEU | Training Cost (FLOPs) |
|-------|------------|------------|-----------------------|
| GNMT + RL Ensemble | 26.30 | 41.16 | 1.8×10²⁰ / 1.1×10²¹ |
| ConvS2S Ensemble | 26.36 | 41.29 | 7.7×10¹⁹ / 1.2×10²¹ |
| **Transformer (big)** | **28.4** | **41.8** | **2.3×10¹⁹** |
- Transformer (big) outperforms all previous models
- Achieves new state-of-the-art with significantly lower training cost
- Trained in 3.5 days on 8 GPUs (vs. weeks for competitors)
---
## Model Architecture Ablations
| Variation | Dev PPL | Dev BLEU |
|-----------|---------|----------|
| Base model | 4.92 | 25.8 |
| Single attention head | 5.29 | 24.9 |
| 32 attention heads | 5.01 | 25.4 |
| No dropout | 4.67 | 25.3 |
| Learned positional embeddings | 4.92 | 25.7 |
| Big model | 4.33 | 26.4 |
-多头注意力优于单头注意力
- dropout对防止过拟合至关重要
- 正弦位置编码与学习的位置编码效果相当
- 增大模型尺寸(dmodel=1024, dff=4096)提升性能
---
## Generalization to English Constituency Parsing
| Parser | Training | WSJ 23 F1 |
|--------|----------|-----------|
| Petrov et al. (2006) | WSJ only | 90.4 |
| Dyer et al. (2016) | WSJ only | 91.7 |
| **Transformer (4 layers)** | **WSJ only** | **91.3** |
| Vinyals & Kaiser (2014) | Semi-supervised | 92.1 |
| **Transformer (4 layers)** | **Semi-supervised** | **92.7** |
- Transformer performs well without task-specific modifications
- Outperforms RNN approaches in small-data regimes
- Achieves 92.7 F1 in semi-supervised setting
---
## Attention Visualization: Long-Distance Dependencies
<img src="/paper_figure_3_long_distance.png" class="h-[560px] w-full object-contain" />
Encoder self-attention in layer 5 showing attention to distant dependency of the verb "making".
---
## Attention Visualization: Anaphora Resolution
<img src="/paper_figure_4_anaphora.png" class="h-[560px] w-full object-contain" />
Attention heads involved in resolving the pronoun "its" to its referent "The Law".
---
## Limitations and Future Work
- **Limitations**:
- Quadratic complexity in sequence length
- Less effective for very long sequences
- Still generates output sequentially
- **Future work**:
- Local, restricted attention mechanisms
- Applications to other modalities (images, audio, video)
- Less sequential generation approaches
- Efficient handling of large inputs/outputs
---
## Conclusion
- Transformer achieves state-of-the-art results in machine translation
- Eliminates recurrence and convolution in favor of self-attention
- Significantly faster training through parallelization
- Generalizes well to other sequence tasks like constituency parsing
- Paves the way for modern attention-based models in NLP
- Code available at https://github.com/tensorflow/tensor2tensor
@@ -0,0 +1,48 @@
{
"overall_score": 75,
"pass": false,
"issues": [
{
"page": 3,
"issue_type": "overcrowded",
"severity": "medium",
"suggestion": "将Recurrent Models和Convolutional Models分为两页展示,或每个部分保留2个最关键要点"
},
{
"page": 6,
"issue_type": "overcrowded",
"severity": "high",
"suggestion": "将Encoder和Decoder架构分为两页,每部分控制在4个要点以内,删除重复的\"Residual connections + layer normalization\""
},
{
"page": 10,
"issue_type": "overcrowded",
"severity": "medium",
"suggestion": "将Training Setup拆分为数据/硬件和优化策略两页,或删除学习率公式的数学表达仅保留文字描述"
},
{
"page": 12,
"issue_type": "readability",
"severity": "low",
"suggestion": "将底部总结文字拆分为两个独立项目符号,使用更清晰的分隔符替代当前的黑色方块符号"
},
{
"page": 14,
"issue_type": "image_size",
"severity": "medium",
"suggestion": "放大注意力可视化图表,确保轴标签文字清晰可辨,或裁剪部分padding区域聚焦核心可视化内容"
},
{
"page": 15,
"issue_type": "image_size",
"severity": "medium",
"suggestion": "放大指代消解可视化图表,增加线条对比度,或仅保留最具代表性的1-2个注意力头可视化"
},
{
"page": 16,
"issue_type": "overcrowded",
"severity": "medium",
"suggestion": "将Limitations和Future Work分为两页,或每个部分精简为2-3个核心要点"
}
]
}
@@ -0,0 +1,202 @@
---
theme: default
---
# Attention Is All You Need
## A Revolutionary Architecture for Sequence Transduction
Ashish Vaswani et al.
NIPS 2017
---
## Abstract
- First sequence transduction model based solely on attention
- Dispenses with recurrence and convolutions entirely
- More parallelizable and faster to train than traditional models
- New state-of-the-art: 28.4 BLEU (EN-DE) and 41.8 BLEU (EN-FR)
- Generalizes well to English constituency parsing
---
## Background: Limitations of Traditional Models
### Recurrent Models (RNN/LSTM/GRU)
- Inherently sequential computation
- Limited parallelization capability
- O(n) sequential operations for long sequences
### Convolutional Models
- Fixed kernel size restricts context
- O(k·n·d²) complexity with kernel size k
- Logarithmic path length for distant dependencies
---
## Key Innovation: Self-Attention Mechanism
- Connects all positions with constant operations
- Enables parallel computation across sequence
- Directly models long-range dependencies
- More efficient than RNN/CNN for typical sequence lengths
- Provides interpretable attention distributions
---
## Transformer Model Architecture
<img src="/paper_figure_1_transformer.png" class="h-[560px] w-full object-contain" />
Encoder-decoder structure with stacked self-attention and feed-forward layers.
---
## Encoder & Decoder Architecture
### Encoder (6 identical layers)
- **Sub-layer 1**: Multi-head self-attention
- **Sub-layer 2**: Position-wise feed-forward network
- Residual connections + layer normalization
- Output dimension: dmodel = 512
### Decoder (6 identical layers)
- **Sub-layer 1**: Masked multi-head self-attention
- **Sub-layer 2**: Encoder-decoder attention
- **Sub-layer 3**: Position-wise feed-forward network
- Residual connections + layer normalization
- Masking prevents future position attention
---
## Attention Mechanisms
### Scaled Dot-Product Attention
$$\text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V$$
- Scaling avoids gradient vanishing for large dk
- More efficient than additive attention
### Multi-Head Attention
$$\text{MultiHead}(Q, K, V) = \text{Concat}(\text{head}_1,...,\text{head}_h)W^O$$
- h=8 parallel heads, dk=dv=64
- Captures diverse dependency patterns
---
## Positional Encoding
- Injects sequence order information (no recurrence/convolution)
- Added to input embeddings (same dmodel dimension)
- Uses sine/cosine functions with varying frequencies:
$$PE_{(pos,2i)} = \sin(pos/10000^{2i/d_{\text{model}}})$$
$$PE_{(pos,2i+1)} = \cos(pos/10000^{2i/d_{\text{model}}})$$
- Enables learning of relative position relationships
---
## Why Self-Attention?
| Aspect | Self-Attention | Recurrent | Convolutional |
|----------------------|----------------|-----------|---------------|
| Complexity | O(n²·d) | O(n·d²) | O(k·n·d²) |
| Parallelization | O(1) | O(n) | O(1) |
| Long-range path length | O(1) | O(n) | O(logk(n)) |
- Superior parallelization and dependency modeling
---
## Training Setup
### Data & Hardware
- WMT 2014 EN-DE (4.5M) and EN-FR (36M)
- 8 NVIDIA P100 GPUs, 0.4s/step (base), 1.0s/step (big)
### Optimization
- Adam (β1=0.9, β2=0.98, ϵ=10⁻⁹)
- Learning rate: $d_{\text{model}}^{-0.5} \cdot \min(\text{step\_num}^{-0.5}, \text{step\_num} \cdot \text{warmup\_steps}^{-1.5})$
### Regularization
- Residual dropout (Pdrop=0.1)
- Label smoothing (ϵls=0.1)
---
## Machine Translation Results
| Model | EN-DE BLEU | EN-FR BLEU | Training Cost (FLOPs) |
|-------|------------|------------|-----------------------|
| GNMT + RL Ensemble | 26.30 | 41.16 | 1.8×10²⁰ / 1.1×10²¹ |
| ConvS2S Ensemble | 26.36 | 41.29 | 7.7×10¹⁹ / 1.2×10²¹ |
| **Transformer (big)** | **28.4** | **41.8** | **2.3×10¹⁹** |
- New state-of-the-art with 4× lower training cost
---
## Model Ablations (EN-DE Dev Set)
| Variation | Dev PPL | Dev BLEU |
|-----------|---------|----------|
| Base model | 4.92 | 25.8 |
| Single attention head | 5.29 | 24.9 |
| No dropout | 4.67 | 25.3 |
| Learned positional embeddings | 4.92 | 25.7 |
| Big model | 4.33 | 26.4 |
■ Multi-head attention and dropout critical for performance
■ Sinusoidal positional encoding ≈ learned embeddings
---
## Generalization to Constituency Parsing
| Parser | Training | WSJ 23 F1 |
|--------|----------|-----------|
| Dyer et al. (2016) | WSJ only | 91.7 |
| **Transformer (4 layers)** | **WSJ only** | **91.3** |
| Vinyals & Kaiser (2014) | Semi-supervised | 92.1 |
| **Transformer (4 layers)** | **Semi-supervised** | **92.7** |
- Strong performance without task-specific modifications
---
## Attention Visualization: Long-Distance Dependencies
<img src="/paper_figure_3_long_distance.png" class="h-[580px] w-full object-contain" />
Encoder self-attention (layer 5) tracking "making...more difficult" dependency.
---
## Attention Visualization: Anaphora Resolution
<img src="/paper_figure_4_anaphora.png" class="h-[580px] w-full object-contain" />
Attention heads resolving "its" to referent "The Law".
---
## Limitations & Future Work
### Limitations
- Quadratic complexity in sequence length
- Less efficient for very long sequences
- Still sequential in generation
### Future Work
- Local/restricted attention mechanisms
- Extension to other modalities (images, audio)
- Non-sequential generation approaches
- Efficient handling of large inputs/outputs
---
## Conclusion
- Transformer replaces recurrence/convolution with self-attention
- Sets new state-of-the-art in machine translation
- Faster training via parallelization
- Generalizes well to diverse sequence tasks
- Foundation for modern attention-based NLP models
@@ -0,0 +1,24 @@
{
"overall_score": 85,
"pass": false,
"issues": [
{
"page": 14,
"issue_type": "readability",
"severity": "medium",
"suggestion": "可视化图中的文字字号过小,建议放大文字或调整图表布局以提高可读性"
},
{
"page": 15,
"issue_type": "readability",
"severity": "medium",
"suggestion": "可视化图中的文字字号过小,建议放大文字或调整图表布局以提高可读性"
},
{
"page": 16,
"issue_type": "overcrowded",
"severity": "low",
"suggestion": "当前页面包含6个要点,略超出建议的5个要点限制,可考虑将Limitations和Future Work分为两页展示"
}
]
}
@@ -0,0 +1,184 @@
---
theme: default
---
# Attention Is All You Need
## A Revolutionary Architecture for Sequence Transduction
Ashish Vaswani et al.
NIPS 2017
---
## Abstract
- First sequence transduction model based solely on attention
- Dispenses with recurrence and convolutions entirely
- More parallelizable and faster to train than traditional models
- New state-of-the-art: 28.4 BLEU (EN-DE) and 41.8 BLEU (EN-FR)
- Generalizes well to English constituency parsing
---
## Background: Limitations of Traditional Models
### Recurrent Models (RNN/LSTM/GRU)
- Inherently sequential computation → limited parallelization
- O(n) sequential operations for long-range dependencies
### Convolutional Models
- Fixed kernel size restricts context → requires multiple layers
- Logarithmic path length for distant connections
---
## Key Innovation: Self-Attention Mechanism
- Connects all positions with constant operations
- Enables parallel computation across sequence
- Directly models long-range dependencies
- More efficient than RNN/CNN for typical sequence lengths
---
## Transformer Model Architecture
<img src="/paper_figure_1_transformer.png" class="h-[560px] w-full object-contain" />
Encoder-decoder structure with stacked self-attention and feed-forward layers.
---
## Encoder Architecture
- Stack of 6 identical layers
- Each layer has two sub-layers:
1. Multi-head self-attention mechanism
2. Position-wise feed-forward network
- Residual connections + layer normalization
- Output dimension: dmodel = 512
---
## Decoder Architecture
- Stack of 6 identical layers
- Three sub-layers per layer:
1. Masked multi-head self-attention (prevents future positions)
2. Encoder-decoder attention (queries from decoder, keys/values from encoder)
3. Position-wise feed-forward network
- Residual connections + layer normalization
---
## Attention Mechanisms
### Scaled Dot-Product Attention
$$\text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V$$
- Scaling avoids gradient vanishing for large dk
### Multi-Head Attention
$$\text{MultiHead}(Q, K, V) = \text{Concat}(\text{head}_1,...,\text{head}_h)W^O$$
- h=8 parallel heads, dk=dv=64 → captures diverse patterns
---
## Positional Encoding
- Injects sequence order information (no recurrence/convolution)
- Added to input embeddings (same dmodel dimension)
- Uses sine/cosine functions with varying frequencies:
$$PE_{(pos,2i)} = \sin(pos/10000^{2i/d_{\text{model}}})$$
$$PE_{(pos,2i+1)} = \cos(pos/10000^{2i/d_{\text{model}}})$$
- Enables learning of relative position relationships
---
## Why Self-Attention?
| Aspect | Self-Attention | Recurrent | Convolutional |
|----------------------|----------------|-----------|---------------|
| Complexity | O(n²·d) | O(n·d²) | O(k·n·d²) |
| Parallelization | O(1) | O(n) | O(1) |
| Long-range path length | O(1) | O(n) | O(logk(n)) |
- Superior parallelization and dependency modeling
---
## Training Setup
### Data & Hardware
- WMT 2014 EN-DE (4.5M) and EN-FR (36M) sentence pairs
- 8 NVIDIA P100 GPUs, 12h (base)/3.5d (big model) training
### Optimization
- Adam (β1=0.9, β2=0.98, ϵ=10⁻⁹) with linear warmup (4000 steps) + inverse square root decay
- Regularization: residual dropout (0.1), label smoothing (0.1)
---
## Machine Translation Results
| Model | EN-DE BLEU | EN-FR BLEU | Training Cost (FLOPs) |
|-------|------------|------------|-----------------------|
| GNMT + RL Ensemble | 26.30 | 41.16 | 1.8×10²⁰ / 1.1×10²¹ |
| ConvS2S Ensemble | 26.36 | 41.29 | 7.7×10¹⁹ / 1.2×10²¹ |
| **Transformer (big)** | **28.4** | **41.8** | **2.3×10¹⁹** |
- New state-of-the-art with 4× lower training cost
---
## Model Ablations & Generalization
### Key Ablations (EN-DE Dev Set)
| Variation | Dev BLEU | Insight |
|-----------|----------|---------|
| Single head | 24.9 | Multi-head critical |
| No dropout | 25.3 | Regularization needed |
| Learned pos encoding | 25.7 | Sinusoidal ≈ learned |
### Constituency Parsing
- 91.3 F1 (WSJ only) vs. 91.7 (state-of-the-art)
- 92.7 F1 (semi-supervised) → strong generalization
---
## Attention Visualization: Long-Distance Dependencies
<img src="/paper_figure_3_long_distance.png" class="h-[600px] w-full object-contain" />
Encoder self-attention (layer 5) tracking "making...more difficult" dependency.
---
## Attention Visualization: Anaphora Resolution
<img src="/paper_figure_4_anaphora.png" class="h-[600px] w-full object-contain" />
Attention heads resolving "its" to referent "The Law".
---
## Limitations & Future Work
### Limitations
- Quadratic complexity in sequence length
- Less efficient for very long sequences
- Still sequential in generation
### Future Work
- Local/restricted attention mechanisms
- Extension to other modalities (images, audio)
- Non-sequential generation approaches
---
## Conclusion
- Transformer replaces recurrence/convolution with self-attention
- Sets new state-of-the-art in machine translation
- Faster training via parallelization
- Generalizes well to diverse sequence tasks
- Foundation for modern attention-based NLP models
@@ -0,0 +1,18 @@
{
"overall_score": 90,
"pass": false,
"issues": [
{
"page": 14,
"issue_type": "image_size",
"severity": "medium",
"suggestion": "放大注意力可视化图,确保文字标签清晰可辨,避免因图片过小影响观众理解长距离依赖关系的展示效果"
},
{
"page": 15,
"issue_type": "image_size",
"severity": "medium",
"suggestion": "增大指代消解注意力可视化图的尺寸,确保文本标签和连接线清晰可见,提升观众对注意力模式的识别能力"
}
]
}
@@ -0,0 +1,187 @@
---
theme: default
---
# Attention Is All You Need
## A Revolutionary Architecture for Sequence Transduction
Ashish Vaswani et al.
NIPS 2017
---
## Abstract
- First sequence transduction model based solely on attention
- Dispenses with recurrence and convolutions entirely
- More parallelizable and faster to train than traditional models
- New state-of-the-art: 28.4 BLEU (EN-DE) and 41.8 BLEU (EN-FR)
- Generalizes well to English constituency parsing
---
## Background: Limitations of Traditional Models
### Recurrent Models (RNN/LSTM/GRU)
- Inherently sequential computation → limited parallelization
- O(n) sequential operations for long-range dependencies
### Convolutional Models
- Fixed kernel size restricts context → requires multiple layers
- Logarithmic path length for distant connections
---
## Key Innovation: Self-Attention Mechanism
- Connects all positions with constant operations
- Enables parallel computation across sequence
- Directly models long-range dependencies
- More efficient than RNN/CNN for typical sequence lengths
---
## Transformer Model Architecture
<img src="/paper_figure_1_transformer.png" class="h-[560px] w-full object-contain" />
Encoder-decoder structure with stacked self-attention and feed-forward layers.
---
## Encoder Architecture
- Stack of 6 identical layers
- Each layer has two sub-layers:
1. Multi-head self-attention mechanism
2. Position-wise feed-forward network
- Residual connections + layer normalization
- Output dimension: dmodel = 512
---
## Decoder Architecture
- Stack of 6 identical layers
- Three sub-layers per layer:
1. Masked multi-head self-attention (prevents future positions)
2. Encoder-decoder attention (queries from decoder, keys/values from encoder)
3. Position-wise feed-forward network
- Residual connections + layer normalization
---
## Attention Mechanisms
### Scaled Dot-Product Attention
$$\text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V$$
- Scaling avoids gradient vanishing for large dk
### Multi-Head Attention
$$\text{MultiHead}(Q, K, V) = \text{Concat}(\text{head}_1,...,\text{head}_h)W^O$$
- h=8 parallel heads, dk=dv=64 → captures diverse patterns
---
## Positional Encoding
- Injects sequence order information (no recurrence/convolution)
- Added to input embeddings (same dmodel dimension)
- Uses sine/cosine functions with varying frequencies:
$$PE_{(pos,2i)} = \sin(pos/10000^{2i/d_{\text{model}}})$$
$$PE_{(pos,2i+1)} = \cos(pos/10000^{2i/d_{\text{model}}})$$
- Enables learning of relative position relationships
---
## Why Self-Attention?
| Aspect | Self-Attention | Recurrent | Convolutional |
|----------------------|----------------|-----------|---------------|
| Complexity | O(n²·d) | O(n·d²) | O(k·n·d²) |
| Parallelization | O(1) | O(n) | O(1) |
| Long-range path length | O(1) | O(n) | O(logk(n)) |
- Superior parallelization and dependency modeling
---
## Training Setup
### Data & Hardware
- WMT 2014 EN-DE (4.5M) and EN-FR (36M) sentence pairs
- 8 NVIDIA P100 GPUs, 12h (base)/3.5d (big model) training
### Optimization
- Adam (β1=0.9, β2=0.98, ϵ=10⁻⁹) with linear warmup (4000 steps) + inverse square root decay
- Regularization: residual dropout (0.1), label smoothing (0.1)
---
## Machine Translation Results
| Model | EN-DE BLEU | EN-FR BLEU | Training Cost (FLOPs) |
|-------|------------|------------|-----------------------|
| GNMT + RL Ensemble | 26.30 | 41.16 | 1.8×10²⁰ / 1.1×10²¹ |
| ConvS2S Ensemble | 26.36 | 41.29 | 7.7×10¹⁹ / 1.2×10²¹ |
| **Transformer (big)** | **28.4** | **41.8** | **2.3×10¹⁹** |
- New state-of-the-art with 4× lower training cost
---
## Model Ablations & Generalization
### Key Ablations (EN-DE Dev Set)
| Variation | Dev BLEU | Insight |
|-----------|----------|---------|
| Single head | 24.9 | Multi-head critical |
| No dropout | 25.3 | Regularization needed |
| Learned pos encoding | 25.7 | Sinusoidal ≈ learned |
### Constituency Parsing
- 91.3 F1 (WSJ only) vs. 91.7 (state-of-the-art)
- 92.7 F1 (semi-supervised) → strong generalization
---
## Attention Visualization: Long-Distance Dependencies
<img src="/paper_figure_3_long_distance.png" class="h-[650px] w-full object-contain" />
Encoder self-attention (layer 5) showing how "making" attends to distant words to complete the phrase "making...more difficult".
---
## Attention Visualization: Anaphora Resolution
<img src="/paper_figure_4_anaphora.png" class="h-[650px] w-full object-contain" />
Attention heads resolving the pronoun "its" to its referent "The Law" with sharp attention focusing.
---
## Limitations
- Quadratic complexity in sequence length
- Less efficient for very long sequences
- Still sequential in generation process
---
## Future Work
- Local/restricted attention mechanisms
- Extension to other modalities (images, audio)
- Non-sequential generation approaches
- Efficient handling of large inputs/outputs
---
## Conclusion
- Transformer replaces recurrence/convolution with self-attention
- Sets new state-of-the-art in machine translation
- Faster training via parallelization
- Generalizes well to diverse sequence tasks
- Foundation for modern attention-based NLP models
File diff suppressed because one or more lines are too long
Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 343 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

@@ -0,0 +1,62 @@
{
"paper": {
"title": "Attention Is All You Need",
"authors": "Ashish Vaswani et al.",
"arxiv_id": "1706.03762",
"pdf_url": "https://arxiv.org/pdf/1706.03762",
"pdf_sha256": "bdfaa68d8984f0dc02beaca527b76f207d99b666d31d1da728ee0728182df697",
"observed_pdf_sha256": "bdfaa68d8984f0dc02beaca527b76f207d99b666d31d1da728ee0728182df697"
},
"paper_text": {
"path": "/Users/boj/book/ai-agent-book/chapter5/paper-to-ppt/validation/runs/exp5-4-real-pdf-both-20260730-v5/source/paper_text.md",
"sha256": "4da5f2a1da38bad8149832b5ada3c94f0619188db8fed5cdca8ff63405587eb8",
"characters": 39819
},
"visuals": [
{
"filename": "paper_figure_1_transformer.png",
"pdf_page": 3,
"source_label": "Figure 1",
"caption": "The Transformer model architecture.",
"rect": [
92,
28,
520,
425
],
"sha256": "1729d86922c9f97703af178fb52e4f876cc1fce1f67572730580ef16bd659bd5",
"bytes": 100778,
"public_copy_sha256": "1729d86922c9f97703af178fb52e4f876cc1fce1f67572730580ef16bd659bd5"
},
{
"filename": "paper_figure_3_long_distance.png",
"pdf_page": 13,
"source_label": "Figure 3",
"caption": "Encoder self-attention following long-distance dependencies.",
"rect": [
92,
55,
525,
365
],
"sha256": "da9498d3022d1e0fc4d5da2bf59c10c9dde68dda471586019afa126db5674322",
"bytes": 93837,
"public_copy_sha256": "da9498d3022d1e0fc4d5da2bf59c10c9dde68dda471586019afa126db5674322"
},
{
"filename": "paper_figure_4_anaphora.png",
"pdf_page": 14,
"source_label": "Figure 4",
"caption": "Attention heads involved in anaphora resolution.",
"rect": [
92,
135,
525,
600
],
"sha256": "8dee94773a369dccb1d766c218cc0ac16629a6baf79d15a313d13399d9064407",
"bytes": 242229,
"public_copy_sha256": "8dee94773a369dccb1d766c218cc0ac16629a6baf79d15a313d13399d9064407"
}
]
}