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
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"overall_score": 65,
|
||||
"pass": false,
|
||||
"issues": [
|
||||
{
|
||||
"page": 2,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "medium",
|
||||
"suggestion": "将6个要点拆分为2页,每页不超过3-4个要点,或精简合并相似内容"
|
||||
},
|
||||
{
|
||||
"page": 3,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "medium",
|
||||
"suggestion": "将RNN和卷积方法分两页展示,或每个部分保留2个核心要点"
|
||||
},
|
||||
{
|
||||
"page": 5,
|
||||
"issue_type": "image_size",
|
||||
"severity": "high",
|
||||
"suggestion": "放大架构图至至少占页面60%空间,确保图中文字和模块清晰可见"
|
||||
},
|
||||
{
|
||||
"page": 5,
|
||||
"issue_type": "readability",
|
||||
"severity": "medium",
|
||||
"suggestion": "删除图片下方的小字体说明文字,或单独用一页解释架构细节"
|
||||
},
|
||||
{
|
||||
"page": 7,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "medium",
|
||||
"suggestion": "将3个子要点拆分为独立要点,或移至下一页单独讲解decoder子层结构"
|
||||
},
|
||||
{
|
||||
"page": 9,
|
||||
"issue_type": "image_size",
|
||||
"severity": "high",
|
||||
"suggestion": "放大多头注意力机制图,确保每个头的结构和连接关系清晰可辨"
|
||||
},
|
||||
{
|
||||
"page": 9,
|
||||
"issue_type": "readability",
|
||||
"severity": "medium",
|
||||
"suggestion": "删除图片下方的小字体说明文字,公式保持现有大小即可"
|
||||
},
|
||||
{
|
||||
"page": 13,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "medium",
|
||||
"suggestion": "将Data & Batching和Hardware & Schedule分两页展示,或各保留2个最关键要点"
|
||||
},
|
||||
{
|
||||
"page": 15,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "medium",
|
||||
"suggestion": "表格保留核心对比数据,4个要点精简为2-3个核心结论"
|
||||
},
|
||||
{
|
||||
"page": 18,
|
||||
"issue_type": "image_size",
|
||||
"severity": "high",
|
||||
"suggestion": "单独一页放大展示注意力可视化图,确保能看清词语间的注意力连接关系"
|
||||
},
|
||||
{
|
||||
"page": 18,
|
||||
"issue_type": "readability",
|
||||
"severity": "medium",
|
||||
"suggestion": "删除图片下方的小字体说明文字,用简洁标题概括可视化内容"
|
||||
},
|
||||
{
|
||||
"page": 19,
|
||||
"issue_type": "image_size",
|
||||
"severity": "high",
|
||||
"suggestion": "单独一页放大展示指代消解可视化图,确保紫色连接线和词语清晰可见"
|
||||
},
|
||||
{
|
||||
"page": 19,
|
||||
"issue_type": "readability",
|
||||
"severity": "medium",
|
||||
"suggestion": "删除图片下方的小字体说明文字,直接在标题中说明可视化内容"
|
||||
},
|
||||
{
|
||||
"page": 21,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "medium",
|
||||
"suggestion": "将Key Contributions和Future Directions分两页展示,每部分保留3-4个要点"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
---
|
||||
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
|
||||
- Superior quality while being more parallelizable and requiring less training time
|
||||
- Achieves 28.4 BLEU on WMT 2014 English-to-German (↑2 BLEU over previous best)
|
||||
- Achieves 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 Existing Approaches
|
||||
|
||||
### Recurrent Neural Networks (RNNs/LSTMs/GRUs)
|
||||
- Inherently sequential computation
|
||||
- Cannot parallelize within training examples
|
||||
- Difficult to learn long-range dependencies
|
||||
|
||||
### Convolutional Approaches
|
||||
- ByteNet, ConvS2S use CNNs for parallelization
|
||||
- Number of operations grows with distance between positions
|
||||
- Linear (ConvS2S) or logarithmic (ByteNet) path lengths
|
||||
|
||||
---
|
||||
|
||||
## Key Insight: Attention is Sufficient
|
||||
|
||||
Attention mechanisms allow modeling dependencies without regard to distance, but were previously used with RNNs.
|
||||
|
||||
**Transformer**: First transduction model relying entirely on self-attention to compute representations without:
|
||||
- Sequence-aligned RNNs
|
||||
- Convolutions
|
||||
|
||||
---
|
||||
|
||||
## Transformer Architecture Overview
|
||||
|
||||
<img src="/paper_figure_1_transformer.png" class="h-80 mx-auto" />
|
||||
|
||||
*Encoder-decoder structure with stacked self-attention and feed-forward layers*
|
||||
|
||||
---
|
||||
|
||||
## Encoder Structure
|
||||
|
||||
- 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 `d_model = 512`
|
||||
|
||||
---
|
||||
|
||||
## Decoder Structure
|
||||
|
||||
- Stack of **6 identical layers**
|
||||
- Three sub-layers per layer:
|
||||
1. Masked multi-head self-attention (prevents leftward information flow)
|
||||
2. Multi-head attention over encoder output
|
||||
3. Position-wise fully connected feed-forward network
|
||||
- Residual connections and layer normalization
|
||||
- Output embeddings offset by one position (auto-regressive property)
|
||||
|
||||
---
|
||||
|
||||
## Attention Mechanism
|
||||
|
||||
### Scaled Dot-Product Attention
|
||||
$$\text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V$$
|
||||
|
||||
- $Q$ (queries), $K$ (keys), $V$ (values) are matrices
|
||||
- Scaling by $\frac{1}{\sqrt{d_k}}$ prevents gradients from becoming too small
|
||||
- Faster and more space-efficient than additive attention
|
||||
|
||||
---
|
||||
|
||||
## Multi-Head Attention
|
||||
|
||||
<img src="/paper_figure_1_transformer.png" class="h-40 mx-auto" />
|
||||
|
||||
- Projects queries, keys, values $h$ times with different learned projections
|
||||
- Performs attention in parallel on projected versions
|
||||
- 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)$
|
||||
|
||||
---
|
||||
|
||||
## Three Applications of Attention
|
||||
|
||||
1. **Encoder-decoder attention**: Queries from decoder, keys/values from encoder
|
||||
2. **Encoder self-attention**: All keys, values, queries from previous encoder layer
|
||||
3. **Decoder self-attention**: All positions in decoder up to current position (masked)
|
||||
|
||||
---
|
||||
|
||||
## Positional Encoding
|
||||
|
||||
Since model has no recurrence/convolution, we inject positional information:
|
||||
|
||||
$$\text{PE}_{(pos, 2i)} = \sin\left(pos / 10000^{2i/d_{\text{model}}}\right)$$
|
||||
$$\text{PE}_{(pos, 2i+1)} = \cos\left(pos / 10000^{2i/d_{\text{model}}}\right)$$
|
||||
|
||||
- Same dimension as embeddings ($d_{\text{model}}$)
|
||||
- Allows model to learn relative position information
|
||||
- Performed nearly as well as learned positional embeddings
|
||||
|
||||
---
|
||||
|
||||
## Why Self-Attention?
|
||||
|
||||
| Layer Type | Complexity | Sequential Operations | Max Path Length |
|
||||
|------------|------------|-----------------------|-----------------|
|
||||
| Self-Attention | $O(n^2 \cdot d)$ | $O(1)$ | $O(1)$ |
|
||||
| Recurrent | $O(n \cdot d^2)$ | $O(n)$ | $O(n)$ |
|
||||
| Convolutional | $O(k \cdot n \cdot d^2)$ | $O(1)$ | $O(\log_k n)$ |
|
||||
|
||||
- Constant path length between any positions
|
||||
- More parallelizable than RNNs
|
||||
- Better computational efficiency for typical sentence lengths
|
||||
|
||||
---
|
||||
|
||||
## Training Details
|
||||
|
||||
### Data & Batching
|
||||
- WMT 2014 English-German (4.5M sentence pairs)
|
||||
- WMT 2014 English-French (36M sentence pairs)
|
||||
- Byte-pair encoding (37K shared vocab for EN-DE)
|
||||
- Batches with ~25000 source and target tokens
|
||||
|
||||
### Hardware & Schedule
|
||||
- 8 NVIDIA P100 GPUs
|
||||
- Base model: 100,000 steps (12 hours)
|
||||
- Big model: 300,000 steps (3.5 days)
|
||||
|
||||
---
|
||||
|
||||
## Training Details (Cont.)
|
||||
|
||||
### Optimizer
|
||||
- Adam with $\beta_1 = 0.9$, $\beta_2 = 0.98$, $\epsilon = 10^{-9}$
|
||||
- Learning rate schedule:
|
||||
$$\text{lrate} = d_{\text{model}}^{-0.5} \cdot \min(\text{step\_num}^{-0.5}, \text{step\_num} \cdot \text{warmup\_steps}^{-1.5})$$
|
||||
- Warmup steps = 4000
|
||||
|
||||
### Regularization
|
||||
- Residual dropout (P_drop = 0.1)
|
||||
- Label smoothing ($\epsilon_{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 \cdot 10^{20}$ |
|
||||
| ConvS2S Ensemble | 26.36 | 41.29 | $7.7 \cdot 10^{19}$ |
|
||||
| **Transformer (big)** | **28.4** | **41.8** | **$2.3 \cdot 10^{19}$** |
|
||||
|
||||
- Transformer outperforms all previous state-of-the-art models
|
||||
- Achieves better results with significantly lower training cost
|
||||
- 28.4 BLEU on EN-DE (↑2 BLEU over previous best)
|
||||
- 41.8 BLEU on EN-FR (new state-of-the-art)
|
||||
|
||||
---
|
||||
|
||||
## Model Variations Analysis
|
||||
|
||||
| Variation | Dev PPL | Dev BLEU |
|
||||
|-----------|---------|----------|
|
||||
| Base model | 4.92 | 25.8 |
|
||||
| Single attention head | 5.29 | 24.9 |
|
||||
| No dropout | 5.77 | 24.6 |
|
||||
| Learned positional embeddings | 4.92 | 25.7 |
|
||||
| Big model | 4.33 | 26.4 |
|
||||
|
||||
- Multiple attention heads improve performance
|
||||
- Dropout is crucial for avoiding overfitting
|
||||
- Sinusoidal and learned positional encodings perform similarly
|
||||
- Larger models (more dimensions, more heads) improve performance
|
||||
|
||||
---
|
||||
|
||||
## Generalization to Other Tasks: 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 et al. | Semi-supervised | 92.1 |
|
||||
| **Transformer (4 layers)** | **Semi-supervised** | **92.7** |
|
||||
|
||||
- Transformer performs well despite no task-specific tuning
|
||||
- Outperforms previous models in semi-supervised setting
|
||||
- Shows generalization ability beyond machine translation
|
||||
|
||||
---
|
||||
|
||||
## Attention Visualization: Long-Distance Dependencies
|
||||
|
||||
<img src="/paper_figure_3_long_distance.png" class="h-70 mx-auto" />
|
||||
|
||||
*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-70 mx-auto" />
|
||||
|
||||
*Attention heads involved in resolving "its" reference to "The Law"*
|
||||
|
||||
---
|
||||
|
||||
## Limitations
|
||||
|
||||
- Computational complexity grows quadratically with sequence length
|
||||
- Less effective for very long sequences (e.g., books, articles)
|
||||
- Still requires sequential generation in decoder
|
||||
- Limited ability to model hierarchical structure compared to some syntactic models
|
||||
|
||||
---
|
||||
|
||||
## Conclusion and Future Work
|
||||
|
||||
### Key Contributions
|
||||
- Introduced Transformer architecture based solely on attention
|
||||
- Achieved new state-of-the-art results in machine translation
|
||||
- Demonstrated improved parallelization and reduced training time
|
||||
- Showed generalization to other tasks like constituency parsing
|
||||
|
||||
### Future Directions
|
||||
- Apply to other modalities (images, audio, video)
|
||||
- Investigate local, restricted attention for large inputs
|
||||
- Make generation less sequential
|
||||
- Explore interpretability of attention mechanisms
|
||||
|
||||
---
|
||||
|
||||
## Thank You
|
||||
|
||||
Code available at: https://github.com/tensorflow/tensor2tensor
|
||||
|
||||
arXiv:1706.03762v7 [cs.CL]
|
||||
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"overall_score": 65,
|
||||
"pass": false,
|
||||
"issues": [
|
||||
{
|
||||
"page": 7,
|
||||
"issue_type": "image_size",
|
||||
"severity": "medium",
|
||||
"suggestion": "缩小架构图尺寸,确保下方说明文字有足够空间,避免图片挤压文字区域"
|
||||
},
|
||||
{
|
||||
"page": 8,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "medium",
|
||||
"suggestion": "将5个要点拆分为两页,建议将\"每个层包含两个子层\"及其子要点单独成页"
|
||||
},
|
||||
{
|
||||
"page": 12,
|
||||
"issue_type": "image_size",
|
||||
"severity": "medium",
|
||||
"suggestion": "调整多头注意力架构图大小,确保图片下方的文字说明完整可见且易于阅读"
|
||||
},
|
||||
{
|
||||
"page": 13,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "low",
|
||||
"suggestion": "将三个注意力应用拆分为单独页面,或简化每个应用的子要点描述"
|
||||
},
|
||||
{
|
||||
"page": 21,
|
||||
"issue_type": "image_size",
|
||||
"severity": "high",
|
||||
"suggestion": "大幅放大注意力可视化图,确保图中文字和颜色编码清晰可辨,必要时单独成页展示"
|
||||
},
|
||||
{
|
||||
"page": 22,
|
||||
"issue_type": "image_size",
|
||||
"severity": "high",
|
||||
"suggestion": "放大指代消解可视化图,增加图片分辨率,确保线条和文字清晰可读"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
---
|
||||
theme: default
|
||||
---
|
||||
|
||||
# Attention Is All You Need
|
||||
## A Revolutionary Architecture for Sequence Transduction
|
||||
|
||||
Ashish Vaswani et al.
|
||||
NIPS 2017
|
||||
|
||||
---
|
||||
|
||||
## Abstract: Key Innovation
|
||||
|
||||
- Proposes **Transformer** - first model based solely on attention mechanisms
|
||||
- Dispenses with recurrence and convolutions entirely
|
||||
- More parallelizable and requires significantly less training time
|
||||
|
||||
---
|
||||
|
||||
## Abstract: Performance Highlights
|
||||
|
||||
- Achieves 28.4 BLEU on WMT 2014 English-to-German
|
||||
- Improves over existing best results by over 2 BLEU
|
||||
- Establishes new state-of-the-art 41.8 BLEU on WMT 2014 English-to-French
|
||||
- Generalizes well to other tasks like English constituency parsing
|
||||
|
||||
---
|
||||
|
||||
## Background: Limitations of RNNs
|
||||
|
||||
### Recurrent Neural Networks (RNNs/LSTMs/GRUs)
|
||||
- Inherently sequential computation
|
||||
- Cannot parallelize within training examples
|
||||
- Difficult to learn long-range dependencies
|
||||
- Memory constraints limit batching for long sequences
|
||||
|
||||
---
|
||||
|
||||
## Background: Limitations of Convolutional Approaches
|
||||
|
||||
### CNN-based Models (ByteNet, ConvS2S)
|
||||
- Use convolutions for parallelization
|
||||
- Number of operations grows with distance between positions
|
||||
- Linear growth for ConvS2S
|
||||
- Logarithmic growth for ByteNet
|
||||
- Longer path lengths between distant positions
|
||||
|
||||
---
|
||||
|
||||
## Key Insight: Attention is Sufficient
|
||||
|
||||
Attention mechanisms allow modeling dependencies without regard to distance, but were previously used with RNNs.
|
||||
|
||||
**Transformer**: First transduction model relying entirely on self-attention to compute representations without:
|
||||
- Sequence-aligned RNNs
|
||||
- Convolutions
|
||||
|
||||
---
|
||||
|
||||
## Transformer Architecture Overview
|
||||
|
||||
<img src="/paper_figure_1_transformer.png" class="h-96 mx-auto" />
|
||||
|
||||
---
|
||||
|
||||
## Encoder Structure
|
||||
|
||||
- Stack of **6 identical layers**
|
||||
- Each layer contains 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
|
||||
|
||||
---
|
||||
|
||||
## Decoder Structure
|
||||
|
||||
- Stack of **6 identical layers**
|
||||
- Three sub-layers per layer:
|
||||
1. Masked multi-head self-attention
|
||||
2. Multi-head attention over encoder output
|
||||
3. Position-wise fully connected feed-forward network
|
||||
- Residual connections and layer normalization
|
||||
|
||||
---
|
||||
|
||||
## Decoder: Masking Mechanism
|
||||
|
||||
- Prevents positions from attending to subsequent positions
|
||||
- Ensures predictions for position i depend only on:
|
||||
- Known outputs at positions < i
|
||||
- Output embeddings offset by one position
|
||||
- Preserves auto-regressive property
|
||||
|
||||
---
|
||||
|
||||
## Attention Mechanism
|
||||
|
||||
### Scaled Dot-Product Attention
|
||||
$$\text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V$$
|
||||
|
||||
- $Q$ (queries), $K$ (keys), $V$ (values) are matrices
|
||||
- Scaling by $\frac{1}{\sqrt{d_k}}$ prevents gradients from becoming too small
|
||||
- Faster and more space-efficient than additive attention
|
||||
|
||||
---
|
||||
|
||||
## Multi-Head Attention
|
||||
|
||||
<img src="/paper_figure_1_transformer.png" class="h-80 mx-auto" />
|
||||
|
||||
- Projects queries, keys, values $h$ times with different learned projections
|
||||
- Performs attention in parallel on projected versions
|
||||
- Concatenates results and projects again
|
||||
|
||||
---
|
||||
|
||||
## Three Applications of Attention
|
||||
|
||||
1. **Encoder-decoder attention**:
|
||||
- Queries from decoder
|
||||
- Keys/values from encoder output
|
||||
|
||||
2. **Encoder self-attention**:
|
||||
- All keys, values, queries from previous encoder layer
|
||||
- Each position attends to all positions
|
||||
|
||||
3. **Decoder self-attention**:
|
||||
- All positions in decoder up to current position
|
||||
- Masked to prevent future information flow
|
||||
|
||||
---
|
||||
|
||||
## Positional Encoding
|
||||
|
||||
Since model has no recurrence/convolution, we inject positional information:
|
||||
|
||||
$$\text{PE}_{(pos, 2i)} = \sin\left(pos / 10000^{2i/d_{\text{model}}}\right)$$
|
||||
$$\text{PE}_{(pos, 2i+1)} = \cos\left(pos / 10000^{2i/d_{\text{model}}}\right)$$
|
||||
|
||||
- Same dimension as embeddings ($d_{\text{model}}$)
|
||||
- Allows model to learn relative position information
|
||||
- Performed nearly as well as learned positional embeddings
|
||||
|
||||
---
|
||||
|
||||
## Why Self-Attention?
|
||||
|
||||
| Layer Type | Complexity | Sequential Operations | Max Path Length |
|
||||
|------------|------------|-----------------------|-----------------|
|
||||
| Self-Attention | $O(n^2 \cdot d)$ | $O(1)$ | $O(1)$ |
|
||||
| Recurrent | $O(n \cdot d^2)$ | $O(n)$ | $O(n)$ |
|
||||
| Convolutional | $O(k \cdot n \cdot d^2)$ | $O(1)$ | $O(\log_k n)$ |
|
||||
|
||||
---
|
||||
|
||||
## Training: Data & Batching
|
||||
|
||||
- WMT 2014 English-German (4.5M sentence pairs)
|
||||
- WMT 2014 English-French (36M sentence pairs)
|
||||
- Byte-pair encoding (37K shared vocab for EN-DE)
|
||||
- Batches with ~25000 source and target tokens
|
||||
|
||||
---
|
||||
|
||||
## Training: Hardware & Schedule
|
||||
|
||||
- 8 NVIDIA P100 GPUs
|
||||
- Base model: 100,000 steps (12 hours)
|
||||
- Big model: 300,000 steps (3.5 days)
|
||||
- Adam optimizer with scheduled learning rate
|
||||
|
||||
---
|
||||
|
||||
## Machine Translation Results
|
||||
|
||||
| Model | EN-DE BLEU | EN-FR BLEU | Training Cost (FLOPs) |
|
||||
|-------|------------|------------|-----------------------|
|
||||
| GNMT + RL Ensemble | 26.30 | 41.16 | $1.8 \cdot 10^{20}$ |
|
||||
| ConvS2S Ensemble | 26.36 | 41.29 | $7.7 \cdot 10^{19}$ |
|
||||
| **Transformer (big)** | **28.4** | **41.8** | **$2.3 \cdot 10^{19}$** |
|
||||
|
||||
---
|
||||
|
||||
## Model Variations Analysis
|
||||
|
||||
| Variation | Dev PPL | Dev BLEU |
|
||||
|-----------|---------|----------|
|
||||
| Base model | 4.92 | 25.8 |
|
||||
| Single attention head | 5.29 | 24.9 |
|
||||
| No dropout | 5.77 | 24.6 |
|
||||
| Learned positional embeddings | 4.92 | 25.7 |
|
||||
|
||||
---
|
||||
|
||||
## Generalization to Constituency Parsing
|
||||
|
||||
| Parser | Training | WSJ 23 F1 |
|
||||
|--------|----------|-----------|
|
||||
| Previous state-of-the-art | WSJ only | 91.7 |
|
||||
| **Transformer (4 layers)** | **WSJ only** | **91.3** |
|
||||
| Previous state-of-the-art | Semi-supervised | 92.1 |
|
||||
| **Transformer (4 layers)** | **Semi-supervised** | **92.7** |
|
||||
|
||||
---
|
||||
|
||||
## Attention Visualization: Long-Distance Dependencies
|
||||
|
||||
<img src="/paper_figure_3_long_distance.png" class="h-96 mx-auto" />
|
||||
|
||||
*Encoder self-attention showing long-distance dependency for "making"*
|
||||
|
||||
---
|
||||
|
||||
## Attention Visualization: Anaphora Resolution
|
||||
|
||||
<img src="/paper_figure_4_anaphora.png" class="h-96 mx-auto" />
|
||||
|
||||
*Attention heads resolving "its" reference to "The Law"*
|
||||
|
||||
---
|
||||
|
||||
## Limitations
|
||||
|
||||
- Computational complexity grows quadratically with sequence length
|
||||
- Less effective for very long sequences
|
||||
- Still requires sequential generation in decoder
|
||||
- Limited ability to model hierarchical structure
|
||||
|
||||
---
|
||||
|
||||
## Key Contributions
|
||||
|
||||
- Introduced Transformer architecture based solely on attention
|
||||
- Achieved new state-of-the-art results in machine translation
|
||||
- Demonstrated improved parallelization and reduced training time
|
||||
- Showed generalization to other tasks like constituency parsing
|
||||
|
||||
---
|
||||
|
||||
## Future Work
|
||||
|
||||
- Apply to other modalities (images, audio, video)
|
||||
- Investigate local, restricted attention for large inputs
|
||||
- Make generation less sequential
|
||||
- Explore interpretability of attention mechanisms
|
||||
|
||||
---
|
||||
|
||||
## Thank You
|
||||
|
||||
Code available at: https://github.com/tensorflow/tensor2tensor
|
||||
|
||||
arXiv:1706.03762v7 [cs.CL]
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"overall_score": 85,
|
||||
"pass": false,
|
||||
"issues": [
|
||||
{
|
||||
"page": 23,
|
||||
"issue_type": "readability",
|
||||
"severity": "medium",
|
||||
"suggestion": "原图彩色注意力可视化转为黑白后对比度差,不同注意力头难以区分。建议添加灰度区分或图案填充来标识不同注意力头,或增加图例说明关键颜色对应的含义。"
|
||||
},
|
||||
{
|
||||
"page": 24,
|
||||
"issue_type": "readability",
|
||||
"severity": "medium",
|
||||
"suggestion": "原图彩色注意力可视化转为黑白后线条区分度低。建议使用不同线型(实线/虚线/点线)或线宽来区分不同注意力头,确保黑白打印下仍能清晰识别关键依赖关系。"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
---
|
||||
theme: default
|
||||
---
|
||||
|
||||
# Attention Is All You Need
|
||||
## A Revolutionary Architecture for Sequence Transduction
|
||||
|
||||
Ashish Vaswani et al.
|
||||
NIPS 2017
|
||||
|
||||
---
|
||||
|
||||
## Abstract: Key Innovation
|
||||
|
||||
- Proposes **Transformer** - first model based solely on attention mechanisms
|
||||
- Dispenses with recurrence and convolutions entirely
|
||||
- More parallelizable and requires significantly less training time
|
||||
|
||||
---
|
||||
|
||||
## Abstract: Performance Highlights
|
||||
|
||||
- Achieves 28.4 BLEU on WMT 2014 English-to-German
|
||||
- Improves over existing best results by over 2 BLEU
|
||||
- Establishes new state-of-the-art 41.8 BLEU on WMT 2014 English-to-French
|
||||
- Generalizes well to other tasks like English constituency parsing
|
||||
|
||||
---
|
||||
|
||||
## Background: Limitations of RNNs
|
||||
|
||||
### Recurrent Neural Networks (RNNs/LSTMs/GRUs)
|
||||
- Inherently sequential computation
|
||||
- Cannot parallelize within training examples
|
||||
- Difficult to learn long-range dependencies
|
||||
- Memory constraints limit batching for long sequences
|
||||
|
||||
---
|
||||
|
||||
## Background: Limitations of Convolutional Approaches
|
||||
|
||||
### CNN-based Models (ByteNet, ConvS2S)
|
||||
- Use convolutions for parallelization
|
||||
- Number of operations grows with distance between positions
|
||||
- Linear growth for ConvS2S
|
||||
- Logarithmic growth for ByteNet
|
||||
- Longer path lengths between distant positions
|
||||
|
||||
---
|
||||
|
||||
## Key Insight: Attention is Sufficient
|
||||
|
||||
Attention mechanisms allow modeling dependencies without regard to distance, but were previously used with RNNs.
|
||||
|
||||
**Transformer**: First transduction model relying entirely on self-attention to compute representations without:
|
||||
- Sequence-aligned RNNs
|
||||
- Convolutions
|
||||
|
||||
---
|
||||
|
||||
## Transformer Architecture Overview
|
||||
|
||||
<img src="/paper_figure_1_transformer.png" class="h-80 mx-auto" />
|
||||
|
||||
*Encoder-decoder structure with stacked self-attention and feed-forward layers*
|
||||
|
||||
---
|
||||
|
||||
## Encoder Structure
|
||||
|
||||
- Stack of **6 identical layers**
|
||||
- Residual connections around each sub-layer
|
||||
- Layer normalization after each sub-layer
|
||||
- All sub-layers produce outputs of dimension `d_model = 512`
|
||||
|
||||
---
|
||||
|
||||
## Encoder: Sub-layer Details
|
||||
|
||||
Each encoder layer contains two sub-layers:
|
||||
|
||||
1. **Multi-head self-attention** mechanism
|
||||
- All positions attend to all positions in previous layer
|
||||
- Enables modeling of dependencies throughout sequence
|
||||
|
||||
2. **Position-wise fully connected feed-forward network**
|
||||
- Applied to each position separately and identically
|
||||
- Two linear transformations with ReLU activation
|
||||
|
||||
---
|
||||
|
||||
## Decoder Structure
|
||||
|
||||
- Stack of **6 identical layers**
|
||||
- Residual connections and layer normalization
|
||||
- Output embeddings offset by one position (auto-regressive property)
|
||||
|
||||
---
|
||||
|
||||
## Decoder: Sub-layer Details
|
||||
|
||||
Each decoder layer contains three sub-layers:
|
||||
|
||||
1. **Masked multi-head self-attention**
|
||||
- Prevents positions from attending to subsequent positions
|
||||
|
||||
2. **Multi-head attention over encoder output**
|
||||
- Queries from decoder, keys/values from encoder
|
||||
|
||||
3. **Position-wise fully connected feed-forward network**
|
||||
- Same structure as encoder's feed-forward network
|
||||
|
||||
---
|
||||
|
||||
## Attention Mechanism
|
||||
|
||||
### Scaled Dot-Product Attention
|
||||
$$\text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V$$
|
||||
|
||||
- $Q$ (queries), $K$ (keys), $V$ (values) are matrices
|
||||
- Scaling by $\frac{1}{\sqrt{d_k}}$ prevents gradients from becoming too small
|
||||
- Faster and more space-efficient than additive attention
|
||||
|
||||
---
|
||||
|
||||
## Multi-Head Attention
|
||||
|
||||
<img src="/paper_figure_1_transformer.png" class="h-60 mx-auto" />
|
||||
|
||||
- Projects queries, keys, values $h$ times with different learned projections
|
||||
- Performs attention in parallel on projected versions
|
||||
- Concatenates results and projects again
|
||||
|
||||
$$\text{MultiHead}(Q, K, V) = \text{Concat}(\text{head}_1, ..., \text{head}_h)W^O$$
|
||||
|
||||
---
|
||||
|
||||
## Attention Application: Encoder-Decoder
|
||||
|
||||
**Encoder-decoder attention**:
|
||||
- Queries come from previous decoder layer
|
||||
- Memory keys and values come from encoder output
|
||||
- Allows every position in decoder to attend over all positions in input sequence
|
||||
- Mimics typical encoder-decoder attention mechanisms
|
||||
|
||||
---
|
||||
|
||||
## Attention Application: Encoder Self-Attention
|
||||
|
||||
**Encoder self-attention**:
|
||||
- Keys, values and queries all come from previous encoder layer
|
||||
- Each position attends to all positions in previous encoder layer
|
||||
- Enables modeling of relationships between all words in input sequence
|
||||
- No regard to distance between positions
|
||||
|
||||
---
|
||||
|
||||
## Attention Application: Decoder Self-Attention
|
||||
|
||||
**Decoder self-attention**:
|
||||
- Keys, values and queries come from previous decoder layer
|
||||
- Each position attends to all positions up to and including itself
|
||||
- Masking prevents attending to subsequent positions
|
||||
- Preserves auto-regressive property (predictions depend only on known outputs)
|
||||
|
||||
---
|
||||
|
||||
## Positional Encoding
|
||||
|
||||
Since model has no recurrence/convolution, we inject positional information:
|
||||
|
||||
$$\text{PE}_{(pos, 2i)} = \sin\left(pos / 10000^{2i/d_{\text{model}}}\right)$$
|
||||
$$\text{PE}_{(pos, 2i+1)} = \cos\left(pos / 10000^{2i/d_{\text{model}}}\right)$$
|
||||
|
||||
- Same dimension as embeddings ($d_{\text{model}}$)
|
||||
- Allows model to learn relative position information
|
||||
- Performed nearly as well as learned positional embeddings
|
||||
|
||||
---
|
||||
|
||||
## Why Self-Attention?
|
||||
|
||||
| Layer Type | Complexity | Sequential Operations | Max Path Length |
|
||||
|------------|------------|-----------------------|-----------------|
|
||||
| Self-Attention | $O(n^2 \cdot d)$ | $O(1)$ | $O(1)$ |
|
||||
| Recurrent | $O(n \cdot d^2)$ | $O(n)$ | $O(n)$ |
|
||||
| Convolutional | $O(k \cdot n \cdot d^2)$ | $O(1)$ | $O(\log_k n)$ |
|
||||
|
||||
---
|
||||
|
||||
## Training: Data & Batching
|
||||
|
||||
- WMT 2014 English-German (4.5M sentence pairs)
|
||||
- WMT 2014 English-French (36M sentence pairs)
|
||||
- Byte-pair encoding (37K shared vocab for EN-DE)
|
||||
- Batches with ~25000 source and target tokens
|
||||
|
||||
---
|
||||
|
||||
## Training: Hardware & Schedule
|
||||
|
||||
- 8 NVIDIA P100 GPUs
|
||||
- Base model: 100,000 steps (12 hours)
|
||||
- Big model: 300,000 steps (3.5 days)
|
||||
- Adam optimizer with scheduled learning rate
|
||||
|
||||
---
|
||||
|
||||
## Machine Translation Results
|
||||
|
||||
| Model | EN-DE BLEU | EN-FR BLEU | Training Cost (FLOPs) |
|
||||
|-------|------------|------------|-----------------------|
|
||||
| GNMT + RL Ensemble | 26.30 | 41.16 | $1.8 \cdot 10^{20}$ |
|
||||
| ConvS2S Ensemble | 26.36 | 41.29 | $7.7 \cdot 10^{19}$ |
|
||||
| **Transformer (big)** | **28.4** | **41.8** | **$2.3 \cdot 10^{19}$** |
|
||||
|
||||
---
|
||||
|
||||
## Generalization to Constituency Parsing
|
||||
|
||||
| Parser | Training | WSJ 23 F1 |
|
||||
|--------|----------|-----------|
|
||||
| Previous state-of-the-art | WSJ only | 91.7 |
|
||||
| **Transformer (4 layers)** | **WSJ only** | **91.3** |
|
||||
| Previous state-of-the-art | Semi-supervised | 92.1 |
|
||||
| **Transformer (4 layers)** | **Semi-supervised** | **92.7** |
|
||||
|
||||
---
|
||||
|
||||
## Attention Visualization: Long-Distance Dependencies
|
||||
|
||||
<img src="/paper_figure_3_long_distance.png" class="h-full w-full object-contain" />
|
||||
|
||||
---
|
||||
|
||||
## Attention Visualization: Anaphora Resolution
|
||||
|
||||
<img src="/paper_figure_4_anaphora.png" class="h-full w-full object-contain" />
|
||||
|
||||
---
|
||||
|
||||
## Limitations
|
||||
|
||||
- Computational complexity grows quadratically with sequence length
|
||||
- Less effective for very long sequences
|
||||
- Still requires sequential generation in decoder
|
||||
- Limited ability to model hierarchical structure
|
||||
|
||||
---
|
||||
|
||||
## Key Contributions
|
||||
|
||||
- Introduced Transformer architecture based solely on attention
|
||||
- Achieved new state-of-the-art results in machine translation
|
||||
- Demonstrated improved parallelization and reduced training time
|
||||
- Showed generalization to other tasks like constituency parsing
|
||||
|
||||
---
|
||||
|
||||
## Future Work
|
||||
|
||||
- Apply to other modalities (images, audio, video)
|
||||
- Investigate local, restricted attention for large inputs
|
||||
- Make generation less sequential
|
||||
- Explore interpretability of attention mechanisms
|
||||
|
||||
---
|
||||
|
||||
## Thank You
|
||||
|
||||
Code available at: https://github.com/tensorflow/tensor2tensor
|
||||
|
||||
arXiv:1706.03762v7 [cs.CL]
|
||||
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 100 KiB |
|
After Width: | Height: | Size: 107 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 110 KiB |
|
After Width: | Height: | Size: 110 KiB |
|
After Width: | Height: | Size: 123 KiB |
|
After Width: | Height: | Size: 119 KiB |
|
After Width: | Height: | Size: 150 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 63 KiB |
|
After Width: | Height: | Size: 119 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 117 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 116 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 88 KiB |
|
After Width: | Height: | Size: 83 KiB |
|
After Width: | Height: | Size: 113 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 83 KiB |
|
After Width: | Height: | Size: 126 KiB |
|
After Width: | Height: | Size: 93 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 164 KiB |
|
After Width: | Height: | Size: 197 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 65 KiB |
|
After Width: | Height: | Size: 55 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 88 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 125 KiB |
|
After Width: | Height: | Size: 70 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 49 KiB |
|
After Width: | Height: | Size: 89 KiB |
|
After Width: | Height: | Size: 83 KiB |
|
After Width: | Height: | Size: 124 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 57 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 74 KiB |
|
After Width: | Height: | Size: 192 KiB |
|
After Width: | Height: | Size: 241 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 65 KiB |
|
After Width: | Height: | Size: 55 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 88 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 116 KiB |
|
After Width: | Height: | Size: 55 KiB |
|
After Width: | Height: | Size: 93 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-20260730-v2/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,
|
||||
535
|
||||
],
|
||||
"sha256": "48f09e2e2426e8ca76c1e438600438dca2f9e61360e92ae3edbb538a2cc611d2",
|
||||
"bytes": 150087,
|
||||
"public_copy_sha256": "48f09e2e2426e8ca76c1e438600438dca2f9e61360e92ae3edbb538a2cc611d2"
|
||||
},
|
||||
{
|
||||
"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,
|
||||
455
|
||||
],
|
||||
"sha256": "ea456861962564d2ef5a158e4205cfea29b537f4a611df989db5d65471f23d78",
|
||||
"bytes": 96204,
|
||||
"public_copy_sha256": "ea456861962564d2ef5a158e4205cfea29b537f4a611df989db5d65471f23d78"
|
||||
},
|
||||
{
|
||||
"filename": "paper_figure_4_anaphora.png",
|
||||
"pdf_page": 14,
|
||||
"source_label": "Figure 4",
|
||||
"caption": "Attention heads involved in anaphora resolution.",
|
||||
"rect": [
|
||||
92,
|
||||
135,
|
||||
525,
|
||||
665
|
||||
],
|
||||
"sha256": "b1f0c6b0e186acb50cae69c304a9a2a0e1f09fd15f1beb0bba03194528163d7e",
|
||||
"bytes": 264855,
|
||||
"public_copy_sha256": "b1f0c6b0e186acb50cae69c304a9a2a0e1f09fd15f1beb0bba03194528163d7e"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 147 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 259 KiB |
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"overall_score": 55,
|
||||
"pass": false,
|
||||
"issues": [
|
||||
{
|
||||
"page": 2,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "medium",
|
||||
"suggestion": "将6个要点拆分为2页,例如将BLEU分数单独作为一页突出展示关键结果"
|
||||
},
|
||||
{
|
||||
"page": 3,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "medium",
|
||||
"suggestion": "将传统方法的挑战拆分为单独页面,或减少子要点数量至2个以内"
|
||||
},
|
||||
{
|
||||
"page": 4,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "medium",
|
||||
"suggestion": "将现有模型局限性和注意力机制分为2页,每部分保留3个核心要点"
|
||||
},
|
||||
{
|
||||
"page": 5,
|
||||
"issue_type": "image_size",
|
||||
"severity": "high",
|
||||
"suggestion": "增大架构图尺寸并移除图片下方的文字说明,或单独用一页展示清晰的架构图"
|
||||
},
|
||||
{
|
||||
"page": 5,
|
||||
"issue_type": "readability",
|
||||
"severity": "high",
|
||||
"suggestion": "确保架构图中的文字清晰可辨,必要时拆分图表或局部放大关键组件"
|
||||
},
|
||||
{
|
||||
"page": 5,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "medium",
|
||||
"suggestion": "删除图片下方的长段文字说明,仅保留底部的总结句"
|
||||
},
|
||||
{
|
||||
"page": 6,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "medium",
|
||||
"suggestion": "将编码器架构的子层信息拆分为单独页面,或简化为要点列表"
|
||||
},
|
||||
{
|
||||
"page": 7,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "medium",
|
||||
"suggestion": "将解码器的三个子层拆分为单独页面详细说明,主页面仅保留核心结构概述"
|
||||
},
|
||||
{
|
||||
"page": 8,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "low",
|
||||
"suggestion": "缩短定义部分的描述文字,或拆分为单独的'注意力定义'和'注意力类型'两页"
|
||||
},
|
||||
{
|
||||
"page": 10,
|
||||
"issue_type": "layout",
|
||||
"severity": "high",
|
||||
"suggestion": "补充Multi-Head Attention的核心要点(如并行注意力头、拼接输出等),避免空页"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
---
|
||||
theme: default
|
||||
title: "Attention Is All You Need"
|
||||
author: "Ashish Vaswani et al."
|
||||
---
|
||||
|
||||
# Attention Is All You Need
|
||||
|
||||
**Authors:** Ashish Vaswani et al.
|
||||
**Conference:** NIPS 2017
|
||||
|
||||
---
|
||||
|
||||
## Abstract
|
||||
|
||||
- Proposes **Transformer** - a new network architecture based solely on attention
|
||||
- Dispenses with recurrence and convolutions entirely
|
||||
- More parallelizable and requires significantly less training time
|
||||
- Achieves state-of-the-art results on machine translation tasks:
|
||||
- 28.4 BLEU on WMT 2014 English-to-German
|
||||
- 41.8 BLEU on WMT 2014 English-to-French
|
||||
- Generalizes well to other tasks like English constituency parsing
|
||||
|
||||
---
|
||||
|
||||
## Background: Sequence Modeling Challenges
|
||||
|
||||
### Traditional Approaches
|
||||
- **Recurrent models** (LSTM, GRU) process input sequentially
|
||||
- **Convolutional models** have limited receptive fields
|
||||
- Both struggle with:
|
||||
- Long-range dependencies
|
||||
- Parallelization
|
||||
- Computational efficiency for long sequences
|
||||
|
||||
---
|
||||
|
||||
## The Need for a New Architecture
|
||||
|
||||
### Key Limitations of Existing Models
|
||||
- **Recurrent networks**: Inherently sequential computation
|
||||
- **Convolutional networks**: Limited long-range connectivity
|
||||
- **Hybrid models**: Still rely on recurrence/convolution as primary components
|
||||
|
||||
### Attention Mechanisms
|
||||
- Already used as auxiliary component in sequence models
|
||||
- Allows modeling dependencies without regard to position distance
|
||||
- Not yet used as the primary architectural component
|
||||
|
||||
---
|
||||
|
||||
## The Transformer: Model Architecture
|
||||
|
||||
<img src="/paper_figure_1_transformer.png" class="h-76 mx-auto" />
|
||||
|
||||
*Encoder-decoder structure using stacked self-attention and feed-forward layers*
|
||||
|
||||
---
|
||||
|
||||
## Encoder Architecture
|
||||
|
||||
- **Stack of 6 identical layers**
|
||||
- Each layer contains 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: `LayerNorm(x + Sublayer(x))`
|
||||
- Output dimension: `d_model = 512`
|
||||
|
||||
---
|
||||
|
||||
## Decoder Architecture
|
||||
|
||||
- **Stack of 6 identical layers**
|
||||
- Each layer contains three sub-layers:
|
||||
1. Masked multi-head self-attention
|
||||
2. Multi-head attention over encoder output
|
||||
3. Position-wise fully connected feed-forward network
|
||||
- Residual connections and layer normalization
|
||||
- Masking prevents attending to future positions
|
||||
|
||||
---
|
||||
|
||||
## Attention Mechanism Basics
|
||||
|
||||
### Definition
|
||||
An attention function maps a query and key-value pairs to an output:
|
||||
- Query (Q), Keys (K), Values (V) are vectors
|
||||
- Output is weighted sum of values
|
||||
- Weights determined by compatibility of query with corresponding key
|
||||
|
||||
### Two Common Types
|
||||
- Additive attention (feed-forward network)
|
||||
- Dot-product attention (scaled in Transformer)
|
||||
|
||||
---
|
||||
|
||||
## Scaled Dot-Product Attention
|
||||
|
||||
$$\text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V$$
|
||||
|
||||
- Computes dot products of query with all keys
|
||||
- Scales by $\sqrt{d_k}$ to prevent gradient vanishing
|
||||
- Applies softmax to get weights over values
|
||||
- More efficient than additive attention (matrix operations)
|
||||
|
||||
---
|
||||
|
||||
## Multi-Head Attention
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"overall_score": 85,
|
||||
"pass": false,
|
||||
"issues": [
|
||||
{
|
||||
"page": 4,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "medium",
|
||||
"suggestion": "将6个要点拆分为两页,Recurrent Models和Convolutional Models各占一页,或删减次要内容使每页不超过5个要点"
|
||||
},
|
||||
{
|
||||
"page": 6,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "high",
|
||||
"suggestion": "移除图片下方的大段文字说明,仅保留模型图;文字内容应拆分到后续页面详细讲解"
|
||||
},
|
||||
{
|
||||
"page": 7,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "low",
|
||||
"suggestion": "将\"Each layer contains two sub-layers\"的两个子要点合并为一条,或调整字号增大留白"
|
||||
},
|
||||
{
|
||||
"page": 9,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "low",
|
||||
"suggestion": "将三个子要点简化为更简短的表述,或拆分到新页面单独说明Decoder的子层结构"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
---
|
||||
theme: default
|
||||
title: "Attention Is All You Need"
|
||||
author: "Ashish Vaswani et al."
|
||||
---
|
||||
|
||||
# Attention Is All You Need
|
||||
|
||||
**Authors:** Ashish Vaswani et al.
|
||||
**Conference:** NIPS 2017
|
||||
|
||||
---
|
||||
|
||||
## Abstract: Key Innovation
|
||||
|
||||
- Proposes **Transformer** - first architecture based solely on attention
|
||||
- Dispenses with recurrence and convolutions entirely
|
||||
- More parallelizable and requires significantly less training time
|
||||
- Generalizes well to other tasks beyond machine translation
|
||||
|
||||
---
|
||||
|
||||
## Abstract: Performance Highlights
|
||||
|
||||
- **WMT 2014 English-to-German**: 28.4 BLEU
|
||||
- Improves over existing best results by over 2 BLEU
|
||||
- **WMT 2014 English-to-French**: 41.8 BLEU
|
||||
- New single-model state-of-the-art
|
||||
- Trained for 3.5 days on eight GPUs (small fraction of previous costs)
|
||||
|
||||
---
|
||||
|
||||
## Background: Traditional Sequence Modeling
|
||||
|
||||
### Recurrent Models
|
||||
- LSTM and GRU as state-of-the-art approaches
|
||||
- Factor computation along symbol positions
|
||||
- Inherently sequential nature precludes parallelization
|
||||
|
||||
### Convolutional Models
|
||||
- Fixed receptive fields limit long-range dependencies
|
||||
- Computational complexity grows with distance between positions
|
||||
|
||||
---
|
||||
|
||||
## Limitations of Existing Approaches
|
||||
|
||||
- **Recurrent networks**: Sequential computation limits parallelization
|
||||
- **Convolutional networks**: Difficulty modeling long-range dependencies
|
||||
- **Hybrid models**: Still rely on recurrence/convolution as primary components
|
||||
- **Attention mechanisms**: Previously used only as auxiliary component
|
||||
|
||||
---
|
||||
|
||||
## The Transformer: Model Architecture
|
||||
|
||||
<img src="/paper_figure_1_transformer.png" class="h-80 mx-auto" />
|
||||
|
||||
---
|
||||
|
||||
## Encoder Architecture
|
||||
|
||||
- **Stack of 6 identical layers**
|
||||
- Each layer contains 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: `LayerNorm(x + Sublayer(x))`
|
||||
|
||||
---
|
||||
|
||||
## Encoder: Key Details
|
||||
|
||||
- All sub-layers produce outputs of dimension `d_model = 512`
|
||||
- Self-attention allows each position to attend to all positions
|
||||
- Feed-forward network applied to each position separately
|
||||
- Residual connections help with gradient flow in deep networks
|
||||
|
||||
---
|
||||
|
||||
## Decoder Architecture
|
||||
|
||||
- **Stack of 6 identical layers**
|
||||
- Each layer contains three sub-layers:
|
||||
1. Masked multi-head self-attention
|
||||
2. Multi-head attention over encoder output
|
||||
3. Position-wise fully connected feed-forward network
|
||||
- Residual connections and layer normalization
|
||||
|
||||
---
|
||||
|
||||
## Decoder: Masking Mechanism
|
||||
|
||||
- **Masked self-attention** prevents positions from attending to subsequent positions
|
||||
- Ensures predictions for position i depend only on:
|
||||
- Known outputs at positions less than i
|
||||
- Input sequence through encoder-decoder attention
|
||||
- Output embeddings offset by one position to maintain auto-regressive property
|
||||
|
||||
---
|
||||
|
||||
## Attention Mechanism: Definition
|
||||
|
||||
Maps a query and key-value pairs to an output:
|
||||
- Query (Q), Keys (K), Values (V) are vectors
|
||||
- Output is weighted sum of values
|
||||
- Weights determined by query-key compatibility
|
||||
|
||||
---
|
||||
|
||||
## Scaled Dot-Product Attention
|
||||
|
||||
$$\text{Attention}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right)V$$
|
||||
|
||||
- Computes dot products of query with all keys
|
||||
- Scales by $\sqrt{d_k}$ to prevent gradient vanishing
|
||||
- Applies softmax to get weights over values
|
||||
- More efficient than additive attention
|
||||
|
||||
---
|
||||
|
||||
## Multi-Head Attention
|
||||
|
||||
- Projects Q, K, V h times with different learned projections
|
||||
- Performs attention in parallel on each projected version
|
||||
- Concatenates outputs and applies final projection
|
||||
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 85 KiB |
|
After Width: | Height: | Size: 117 KiB |
|
After Width: | Height: | Size: 122 KiB |
|
After Width: | Height: | Size: 81 KiB |