2536c937e3
翻译自英文原版 maths-cs-ai-compendium,共 20 章全部完成。 第01章 向量 | 第02章 矩阵 | 第03章 微积分 第04章 统计学 | 第05章 概率论 | 第06章 机器学习 第07章 计算语言学 | 第08章 计算机视觉 | 第09章 音频与语音 第10章 多模态学习 | 第11章 自主系统 | 第12章 图神经网络 第13章 计算与操作系统 | 第14章 数据结构与算法 第15章 生产级软件工程 | 第16章 SIMD与GPU编程 第17章 AI推理 | 第18章 ML系统设计 第19章 应用人工智能 | 第20章 前沿人工智能 翻译说明: - 所有数学公式 $...$ / $$...$$、代码块、图片引用完整保留 - mkdocs.yml 配置中文导航 + language: zh - README.md 已翻译为中文(兼 docs/index.md) - docs/ 目录包含指向各章文件的 symlink - 约 29,000 行中文内容,排除 .cache/ 构建缓存
63 lines
3.7 KiB
XML
63 lines
3.7 KiB
XML
<svg width="600" height="300" xmlns="http://www.w3.org/2000/svg">
|
||
<defs>
|
||
<marker id="rope-arrow" markerWidth="7" markerHeight="5" refX="7" refY="2.5" orient="auto">
|
||
<polygon points="0 0, 7 2.5, 0 5" fill="#555"/>
|
||
</marker>
|
||
<marker id="rope-arrow-blue" markerWidth="7" markerHeight="5" refX="7" refY="2.5" orient="auto">
|
||
<polygon points="0 0, 7 2.5, 0 5" fill="#3498db"/>
|
||
</marker>
|
||
<marker id="rope-arrow-red" markerWidth="7" markerHeight="5" refX="7" refY="2.5" orient="auto">
|
||
<polygon points="0 0, 7 2.5, 0 5" fill="#e74c3c"/>
|
||
</marker>
|
||
</defs>
|
||
<text x="300" y="22" fill="#333" font-size="14" font-weight="bold" text-anchor="middle">Rotary Position Embedding (RoPE)</text>
|
||
|
||
<!-- 2D plane -->
|
||
<text x="170" y="48" fill="#666" font-size="11" text-anchor="middle">Rotation in a 2D subspace of the embedding</text>
|
||
|
||
<!-- Axes -->
|
||
<line x1="40" y1="190" x2="310" y2="190" stroke="#ccc" stroke-width="1"/>
|
||
<line x1="170" y1="60" x2="170" y2="280" stroke="#ccc" stroke-width="1"/>
|
||
<text x="315" y="194" fill="#999" font-size="10">q_{2i}</text>
|
||
<text x="175" y="58" fill="#999" font-size="10">q_{2i+1}</text>
|
||
|
||
<!-- Original vector (position 0) -->
|
||
<line x1="170" y1="190" x2="280" y2="115" stroke="#3498db" stroke-width="2.5" marker-end="url(#rope-arrow-blue)"/>
|
||
<text x="285" y="110" fill="#3498db" font-size="11" font-weight="bold">pos 0</text>
|
||
<text x="285" y="125" fill="#3498db" font-size="9">(unrotated)</text>
|
||
|
||
<!-- Rotated vector (position 3) -->
|
||
<line x1="170" y1="190" x2="240" y2="82" stroke="#e74c3c" stroke-width="2.5" marker-end="url(#rope-arrow-red)"/>
|
||
<text x="245" y="77" fill="#e74c3c" font-size="11" font-weight="bold">pos 3</text>
|
||
<text x="245" y="92" fill="#e74c3c" font-size="9">(rotated by 3θ)</text>
|
||
|
||
<!-- Rotated vector (position 7) -->
|
||
<line x1="170" y1="190" x2="105" y2="95" stroke="#27ae60" stroke-width="2.5" marker-end="url(#rope-arrow)"/>
|
||
<text x="62" y="88" fill="#27ae60" font-size="11" font-weight="bold">pos 7</text>
|
||
<text x="62" y="103" fill="#27ae60" font-size="9">(rotated by 7θ)</text>
|
||
|
||
<!-- Arc showing rotation angle -->
|
||
<path d="M 240,155 A 50,50 0 0,1 260,135" fill="none" stroke="#f39c12" stroke-width="1.5" stroke-dasharray="3,2"/>
|
||
<text x="265" y="150" fill="#f39c12" font-size="10">3θ</text>
|
||
|
||
<!-- Right side explanation -->
|
||
<rect x="340" y="60" width="245" height="220" rx="8" fill="#f5f5f5" stroke="#ddd" stroke-width="1"/>
|
||
|
||
<text x="462" y="85" fill="#333" font-size="11" text-anchor="middle" font-weight="bold">Key Insight</text>
|
||
|
||
<text x="462" y="108" fill="#555" font-size="10" text-anchor="middle">Each position m rotates the</text>
|
||
<text x="462" y="122" fill="#555" font-size="10" text-anchor="middle">query/key by angle mθ.</text>
|
||
|
||
<text x="462" y="148" fill="#555" font-size="10" text-anchor="middle">The dot product q'ᵀk' depends</text>
|
||
<text x="462" y="162" fill="#555" font-size="10" text-anchor="middle">only on the angle difference</text>
|
||
<text x="462" y="176" fill="#e74c3c" font-size="11" text-anchor="middle" font-weight="bold">(m − n)θ = relative position</text>
|
||
|
||
<line x1="370" y1="190" x2="555" y2="190" stroke="#ddd" stroke-width="1"/>
|
||
|
||
<text x="462" y="212" fill="#555" font-size="10" text-anchor="middle">Absolute positions are encoded,</text>
|
||
<text x="462" y="226" fill="#555" font-size="10" text-anchor="middle">but attention scores see only</text>
|
||
<text x="462" y="240" fill="#555" font-size="10" text-anchor="middle">relative distances.</text>
|
||
|
||
<text x="462" y="265" fill="#27ae60" font-size="10" text-anchor="middle" font-weight="bold">Generalises to unseen lengths</text>
|
||
<text x="462" y="278" fill="#666" font-size="9" text-anchor="middle">Used in LLaMA, Mistral, Gemma</text>
|
||
</svg> |