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> |