位置情報の表現:学習可能埋め込み、正弦波埋め込みと回転位置埋め込み(RoPE)
Agent支援工学分析
前提条件
第43日のアテンションと第47日のTransformerブロックの積層。
学習目標
位置情報がない場合に自己注意力が置換同変性を持つ理由を説明し、加算的位置埋め込みとRoPEを比較する。
手順
位置指標のない自己注意機構において、トークン1とトークン2を入れ替えると出力も対応して入れ替わることを示せ。加算的位置埋め込み x = tok_emb + pos_emb と、複素平面上の乗算的な RoPE 回転を定義し、対比せよ。
演習と予測記録
1. 素朴な自己注意力が置換同変性を持つことを示せ。
2. GPT-2はどのように位置情報を埋め込むか?
3. RoPEが絶対位置埋め込みに対して持つ外挿上の優位性は何か?
置換行列 P は (P Q)(P K)^T = P (Q K^T) P^T を満たす。
置換同変性:位置情報がないと注意力は入力の順序変更に追従してそのまま入れ替わり、語順を識別できない。GPT-2は加算的位置埋め込み x_t = C[tok_t] + W_pos[t] を用いる。RoPEはQとKに相対回転を施すことで自然な距離依存性を与え、長文外挿性を高める。
置換同変性を論述し、加算埋め込みとRoPEの幾何学的差異を正確に比較できること。
公式ソースリソースと権利証跡
Attention Is All You Need
該当セクション・タイムスタンプ: Section 3.5 Positional Encoding
検証バージョンと日付: arXiv:1706.03762v7 (Verified: 2026-10-30)
Foundational primary literature defining the Transformer architecture, multi-head attention, and scaled dot-product attention.
Matrix multiplication and basic neural network concepts from Days 22-24 and 34-36.
All mathematical formulas and structural definitions are self-contained in the lesson text.
比較対象候補リソースと選定評価 (2)
High-level visual intuition, but Vaswani et al. provides the primary mathematical specifications needed for implementation.
Co-primary: PyTorch line-by-line implementation alongside the paper equations.
The Annotated Transformer
該当セクション・タイムスタンプ: Positional Encoding (class PositionalEncoding)
検証バージョンと日付: Updated PyTorch 2.0 edition (Verified: 2026-10-30)
Clear reference implementation of Transformer modules, residual connections, and layer normalization.
PyTorch tensor operations and attention theory.
All block assembly and normalization logic are provided in runnable local Python snippets.
比較対象候補リソースと選定評価 (2)
Industrial scale with hundreds of model variations; Annotated Transformer is pedagogically focused on the core architecture.
Standard library implementation, but internal C++ bindings obscure the first-principles data flow.