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,30 @@
|
||||
{
|
||||
"overall_score": 80,
|
||||
"pass": false,
|
||||
"issues": [
|
||||
{
|
||||
"page": 3,
|
||||
"issue_type": "readability",
|
||||
"severity": "low",
|
||||
"suggestion": "将中英文混合的\"辅助\"统一为英文\"aids\"或中文\"辅助\",保持语言一致性"
|
||||
},
|
||||
{
|
||||
"page": 13,
|
||||
"issue_type": "image_size",
|
||||
"severity": "medium",
|
||||
"suggestion": "放大Long-Distance Attention图示,确保文本标签清晰可辨,避免因图片过小影响观众理解注意力模式"
|
||||
},
|
||||
{
|
||||
"page": 14,
|
||||
"issue_type": "image_size",
|
||||
"severity": "medium",
|
||||
"suggestion": "增大Anaphora Attention图示尺寸,确保句子中的单词和连接线清晰可见,提升注意力可视化的可读性"
|
||||
},
|
||||
{
|
||||
"page": 17,
|
||||
"issue_type": "overcrowded",
|
||||
"severity": "medium",
|
||||
"suggestion": "将Future directions拆分为两条独立要点:\"Extend to multi-modal inputs; develop local restricted attention\"和\"Explore non-sequential generation; enhance attention interpretability\",避免单条要点包含过多信息"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
---
|
||||
theme: default
|
||||
---
|
||||
|
||||
# Attention Is All You Need
|
||||
## Ashish Vaswani et al.
|
||||
### NIPS 2017
|
||||
|
||||
---
|
||||
|
||||
## Abstract
|
||||
- First sequence transduction model based solely on attention
|
||||
- Dispenses with recurrence and convolutions entirely
|
||||
- Superior quality with better parallelization and lower training cost
|
||||
- State-of-the-art results: 28.4 BLEU (EN-DE) and 41.8 BLEU (EN-FR)
|
||||
|
||||
---
|
||||
|
||||
## Background & Key Innovation
|
||||
- **Challenges**: RNNs have sequential computation; CNNs need O(log n) layers for long dependencies
|
||||
- **Previous work**: Attention typically辅助 recurrent networks
|
||||
- **Transformer**: Replaces recurrence/conv with self-attention for global dependencies
|
||||
- **Advantages**: Massive parallelization, constant operations for long-range dependencies
|
||||
|
||||
---
|
||||
|
||||
## Model Architecture Overview
|
||||
- Encoder-decoder structure with 6 stacked layers each
|
||||
- Encoder: Multi-Head Self-Attention + Feed-Forward Network
|
||||
- Decoder: Masked Self-Attention + Encoder-Decoder Attention + Feed-Forward
|
||||
- Residual connections and layer normalization; d_model = 512
|
||||
|
||||
---
|
||||
|
||||
# Transformer Architecture (Figure 1)
|
||||
<img src="/paper_figure_1_transformer.png" class="max-h-[500px] w-full object-contain" />
|
||||
Complete Transformer architecture with encoder (left) and decoder (right) stacks.
|
||||
|
||||
---
|
||||
|
||||
## Attention Mechanism & Multi-Head
|
||||
- **Scaled Dot-Product Attention**: Attention(Q,K,V) = softmax((QKᵀ)/√dₖ)V
|
||||
- **Scaling**: Prevents softmax saturation for large dₖ (dₖ=64)
|
||||
- **Multi-Head**: 8 parallel attention heads on projected subspaces
|
||||
- **Concatenation**: Combines heads and applies final linear projection
|
||||
|
||||
---
|
||||
|
||||
## Attention Applications
|
||||
1. **Encoder-decoder attention**: Decoder queries attend to encoder outputs
|
||||
2. **Encoder self-attention**: All positions attend to each other (global context)
|
||||
3. **Decoder self-attention**: Masked to prevent future position access (auto-regressive)
|
||||
|
||||
---
|
||||
|
||||
## Positional Encoding
|
||||
- Injects sequence order information (no recurrence/convolution)
|
||||
- Added to input embeddings (same d_model dimension)
|
||||
- Uses sine/cosine functions: PE(pos,2i)=sin(pos/10000^(2i/d_model))
|
||||
- Alternative: learned embeddings (nearly identical performance)
|
||||
|
||||
---
|
||||
|
||||
## Self-Attention Advantages
|
||||
|
||||
| Aspect | Self-Attention | RNN | CNN |
|
||||
|----------------------|----------------|------------|--------------|
|
||||
| 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(logₖn) |
|
||||
|
||||
- Better parallelization than RNNs; shorter paths than CNNs/RNNs
|
||||
|
||||
---
|
||||
|
||||
## Training Setup
|
||||
- Datasets: WMT 2014 EN-DE (4.5M) and EN-FR (36M sentences)
|
||||
- Vocabulary: Byte-pair encoding (37K for EN-DE, 32K for EN-FR)
|
||||
- Hardware: 8 P100 GPUs; 100K-300K steps (12h-3.5 days)
|
||||
- Optimizer: Adam (β₁=0.9, β₂=0.98); learning rate with warmup
|
||||
|
||||
---
|
||||
|
||||
## Machine Translation Results
|
||||
- EN-DE: 28.4 BLEU (↑2+ over previous best, including ensembles)
|
||||
- EN-FR: 41.8 BLEU (new single-model state-of-the-art)
|
||||
- Training cost: 3.3×10¹⁸ FLOPs (EN-DE base) vs 10¹⁹-10²¹ for competitors
|
||||
- Achieves better quality with significantly lower computational resources
|
||||
|
||||
---
|
||||
|
||||
## Model Variations (Ablation Study)
|
||||
- Single-head attention: 0.9 BLEU worse than 8-head setup
|
||||
- Reducing dₖ (attention key size) degrades performance
|
||||
- Larger models (d_model=1024): +1.1 BLEU over base model
|
||||
- Dropout critical for preventing overfitting (P_drop=0.1)
|
||||
|
||||
---
|
||||
|
||||
# Long-Distance Attention (Figure 3)
|
||||
<img src="/paper_figure_3_long_distance.png" class="max-h-[500px] w-full object-contain" />
|
||||
Encoder self-attention showing "making" attending to distant "more difficult".
|
||||
|
||||
---
|
||||
|
||||
# Anaphora Attention (Figure 4)
|
||||
<img src="/paper_figure_4_anaphora.png" class="max-h-[500px] w-full object-contain" />
|
||||
Attention heads resolving anaphora: "its" attending to "Law" and "application".
|
||||
|
||||
---
|
||||
|
||||
## Generalization to Parsing
|
||||
- Applied Transformer to English constituency parsing
|
||||
- WSJ only (40K sentences): 91.3 F1 (comparable to state-of-the-art)
|
||||
- Semi-supervised (17M sentences): 92.7 F1 (outperforms most prior models)
|
||||
- Demonstrates transferability to structural NLP tasks
|
||||
|
||||
---
|
||||
|
||||
## Limitations
|
||||
- O(n²) self-attention complexity for long sequences
|
||||
- Memory-intensive with extended input lengths
|
||||
- Decoder still generates output sequentially
|
||||
- Attention patterns show interpretability but not fully understood
|
||||
|
||||
---
|
||||
|
||||
## Conclusion & Future Work
|
||||
- **Conclusion**: Establishes new state-of-the-art in translation; replaces recurrence with attention
|
||||
- **Future directions**: Extend to multi-modal inputs; develop local restricted attention
|
||||
- Explore non-sequential generation; enhance attention interpretability
|
||||
- Significantly reduces training time while improving quality
|
||||
|
||||
---
|
||||
|
||||
## References
|
||||
- Vaswani et al. (2017). Attention is all you need. NIPS 2017
|
||||
- Code: https://github.com/tensorflow/tensor2tensor
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"overall_score": 85,
|
||||
"pass": false,
|
||||
"issues": [
|
||||
{
|
||||
"page": 13,
|
||||
"issue_type": "readability",
|
||||
"severity": "medium",
|
||||
"suggestion": "放大图中文字尺寸,确保观众能清晰辨认注意力可视化图中的词语和连接关系"
|
||||
},
|
||||
{
|
||||
"page": 14,
|
||||
"issue_type": "readability",
|
||||
"severity": "medium",
|
||||
"suggestion": "增大指代注意力图中的文本字号,或局部放大关键区域以提升可读性"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
---
|
||||
theme: default
|
||||
---
|
||||
|
||||
# Attention Is All You Need
|
||||
## Ashish Vaswani et al.
|
||||
### NIPS 2017
|
||||
|
||||
---
|
||||
|
||||
## Abstract
|
||||
- First sequence transduction model based solely on attention
|
||||
- Dispenses with recurrence and convolutions entirely
|
||||
- Superior quality with better parallelization and lower training cost
|
||||
- State-of-the-art results: 28.4 BLEU (EN-DE) and 41.8 BLEU (EN-FR)
|
||||
|
||||
---
|
||||
|
||||
## Background & Key Innovation
|
||||
- **Challenges**: RNNs have sequential computation; CNNs need O(log n) layers for long dependencies
|
||||
- **Previous work**: Attention typically aids recurrent networks
|
||||
- **Transformer**: Replaces recurrence/conv with self-attention for global dependencies
|
||||
- **Advantages**: Massive parallelization, constant operations for long-range dependencies
|
||||
|
||||
---
|
||||
|
||||
## Model Architecture Overview
|
||||
- Encoder-decoder structure with 6 stacked layers each
|
||||
- Encoder: Multi-Head Self-Attention + Feed-Forward Network
|
||||
- Decoder: Masked Self-Attention + Encoder-Decoder Attention + Feed-Forward
|
||||
- Residual connections and layer normalization; d_model = 512
|
||||
|
||||
---
|
||||
|
||||
# Transformer Architecture (Figure 1)
|
||||
<img src="/paper_figure_1_transformer.png" class="max-h-[500px] w-full object-contain" />
|
||||
Complete Transformer architecture with encoder (left) and decoder (right) stacks.
|
||||
|
||||
---
|
||||
|
||||
## Attention Mechanism & Multi-Head
|
||||
- **Scaled Dot-Product Attention**: Attention(Q,K,V) = softmax((QKᵀ)/√dₖ)V
|
||||
- **Scaling**: Prevents softmax saturation for large dₖ (dₖ=64)
|
||||
- **Multi-Head**: 8 parallel attention heads on projected subspaces
|
||||
- **Concatenation**: Combines heads and applies final linear projection
|
||||
|
||||
---
|
||||
|
||||
## Attention Applications
|
||||
1. **Encoder-decoder attention**: Decoder queries attend to encoder outputs
|
||||
2. **Encoder self-attention**: All positions attend to each other (global context)
|
||||
3. **Decoder self-attention**: Masked to prevent future position access (auto-regressive)
|
||||
|
||||
---
|
||||
|
||||
## Positional Encoding
|
||||
- Injects sequence order information (no recurrence/convolution)
|
||||
- Added to input embeddings (same d_model dimension)
|
||||
- Uses sine/cosine functions: PE(pos,2i)=sin(pos/10000^(2i/d_model))
|
||||
- Alternative: learned embeddings (nearly identical performance)
|
||||
|
||||
---
|
||||
|
||||
## Self-Attention Advantages
|
||||
|
||||
| Aspect | Self-Attention | RNN | CNN |
|
||||
|----------------------|----------------|------------|--------------|
|
||||
| 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(logₖn) |
|
||||
|
||||
- Better parallelization than RNNs; shorter paths than CNNs/RNNs
|
||||
|
||||
---
|
||||
|
||||
## Training Setup
|
||||
- Datasets: WMT 2014 EN-DE (4.5M) and EN-FR (36M sentences)
|
||||
- Vocabulary: Byte-pair encoding (37K for EN-DE, 32K for EN-FR)
|
||||
- Hardware: 8 P100 GPUs; 100K-300K steps (12h-3.5 days)
|
||||
- Optimizer: Adam (β₁=0.9, β₂=0.98); learning rate with warmup
|
||||
|
||||
---
|
||||
|
||||
## Machine Translation Results
|
||||
- EN-DE: 28.4 BLEU (↑2+ over previous best, including ensembles)
|
||||
- EN-FR: 41.8 BLEU (new single-model state-of-the-art)
|
||||
- Training cost: 3.3×10¹⁸ FLOPs (EN-DE base) vs 10¹⁹-10²¹ for competitors
|
||||
- Achieves better quality with significantly lower computational resources
|
||||
|
||||
---
|
||||
|
||||
## Model Variations (Ablation Study)
|
||||
- Single-head attention: 0.9 BLEU worse than 8-head setup
|
||||
- Reducing dₖ (attention key size) degrades performance
|
||||
- Larger models (d_model=1024): +1.1 BLEU over base model
|
||||
- Dropout critical for preventing overfitting (P_drop=0.1)
|
||||
|
||||
---
|
||||
|
||||
# Long-Distance Attention (Figure 3)
|
||||
<img src="/paper_figure_3_long_distance.png" class="max-h-[500px] w-full object-contain" />
|
||||
Encoder self-attention showing "making" attending to distant "more difficult".
|
||||
|
||||
---
|
||||
|
||||
# Anaphora Attention (Figure 4)
|
||||
<img src="/paper_figure_4_anaphora.png" class="max-h-[500px] w-full object-contain" />
|
||||
Attention heads resolving anaphora: "its" attending to "Law" and "application".
|
||||
|
||||
---
|
||||
|
||||
## Generalization to Parsing
|
||||
- Applied Transformer to English constituency parsing
|
||||
- WSJ only (40K sentences): 91.3 F1 (comparable to state-of-the-art)
|
||||
- Semi-supervised (17M sentences): 92.7 F1 (outperforms most prior models)
|
||||
- Demonstrates transferability to structural NLP tasks
|
||||
|
||||
---
|
||||
|
||||
## Limitations
|
||||
- O(n²) self-attention complexity for long sequences
|
||||
- Memory-intensive with extended input lengths
|
||||
- Decoder still generates output sequentially
|
||||
- Attention patterns show interpretability but not fully understood
|
||||
|
||||
---
|
||||
|
||||
## Conclusion
|
||||
- Establishes new state-of-the-art in machine translation
|
||||
- Replaces recurrence/convolution with attention for better parallelization
|
||||
- Generalizes effectively to other sequence tasks (e.g., parsing)
|
||||
- Significantly reduces training time while improving quality
|
||||
|
||||
---
|
||||
|
||||
## Future Work
|
||||
- Extend to multi-modal inputs; develop local restricted attention
|
||||
- Explore non-sequential generation; enhance attention interpretability
|
||||
- Optimize for longer sequences with improved memory efficiency
|
||||
- Further investigate attention mechanism interpretability
|
||||
|
||||
---
|
||||
|
||||
## References
|
||||
- Vaswani et al. (2017). Attention is all you need. NIPS 2017
|
||||
- Code: https://github.com/tensorflow/tensor2tensor
|
||||
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 202 KiB |
|
After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 87 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 156 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 202 KiB |
|
After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 61 KiB |
|
After Width: | Height: | Size: 61 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 156 KiB |
|
After Width: | Height: | Size: 80 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 68 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-v8/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,
|
||||
60,
|
||||
520,
|
||||
405
|
||||
],
|
||||
"sha256": "09364ee993caf62234733a5aaacc31bc0472b8db4b6107455f898e3a7a020597",
|
||||
"bytes": 94487,
|
||||
"public_copy_sha256": "09364ee993caf62234733a5aaacc31bc0472b8db4b6107455f898e3a7a020597"
|
||||
},
|
||||
{
|
||||
"filename": "paper_figure_3_long_distance.png",
|
||||
"pdf_page": 13,
|
||||
"source_label": "Figure 3 (long-distance dependency focus)",
|
||||
"caption": "Published encoder attention linking 'making' to 'more difficult'.",
|
||||
"rect": [
|
||||
190,
|
||||
88,
|
||||
425,
|
||||
311
|
||||
],
|
||||
"sha256": "611a465fc6ba0f266c0a4743600b26ba861ebee93597e04f7c34067a8ddba296",
|
||||
"bytes": 43326,
|
||||
"public_copy_sha256": "611a465fc6ba0f266c0a4743600b26ba861ebee93597e04f7c34067a8ddba296"
|
||||
},
|
||||
{
|
||||
"filename": "paper_figure_4_anaphora.png",
|
||||
"pdf_page": 14,
|
||||
"source_label": "Figure 4 (lower panel, anaphora focus)",
|
||||
"caption": "Published attention from 'its' to 'Law' and 'application'.",
|
||||
"rect": [
|
||||
92,
|
||||
360,
|
||||
310,
|
||||
610
|
||||
],
|
||||
"sha256": "fdc5b28e860e65ff5922d237d190fa11f5586bfb00894b58d09cf38299bfef67",
|
||||
"bytes": 30161,
|
||||
"public_copy_sha256": "fdc5b28e860e65ff5922d237d190fa11f5586bfb00894b58d09cf38299bfef67"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
After Width: | Height: | Size: 92 KiB |
|
After Width: | Height: | Size: 42 KiB |
|
After Width: | Height: | Size: 30 KiB |