| 1 | <?xml version='1.0' encoding='UTF-8'?> |
| 2 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 720" width="1280" height="720"> |
| 3 | <defs> |
| 4 | <filter id="cardShadow" x="-10%" y="-10%" width="120%" height="120%"> |
| 5 | <feGaussianBlur in="SourceAlpha" stdDeviation="4" /> |
| 6 | <feOffset dx="0" dy="3" /> |
| 7 | <feFlood flood-color="#1A365D" flood-opacity="0.06" /> |
| 8 | <feComposite in2="SourceAlpha" operator="in" /> |
| 9 | <feMerge><feMergeNode /><feMergeNode in="SourceGraphic" /></feMerge> |
| 10 | </filter> |
| 11 | <clipPath id="sublayerImgClip"> |
| 12 | <rect x="60" y="160" width="340" height="500" rx="14" /> |
| 13 | </clipPath> |
| 14 | </defs> |
| 15 | |
| 16 | <g id="bg"> |
| 17 | <rect width="1280" height="720" fill="#FFFFFF" /> |
| 18 | </g> |
| 19 | |
| 20 | <g id="header"> |
| 21 | <rect x="60" y="56" width="6" height="40" fill="#3182CE" /> |
| 22 | <text x="84" y="88" font-family="Georgia, "Microsoft YaHei", serif" font-size="36" font-weight="700" fill="#1A365D">The supporting cast inside every layer</text> |
| 23 | <text x="84" y="118" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="13" font-weight="700" fill="#4A5568" letter-spacing="1.5">POSITION-WISE FFN · RESIDUAL CONNECTION · LAYERNORM</text> |
| 24 | </g> |
| 25 | |
| 26 | <g id="sublayer-visual"> |
| 27 | <rect x="60" y="160" width="340" height="500" rx="14" fill="#FFFFFF" stroke="#E2E8F0" stroke-width="1.5" filter="url(#cardShadow)" /> |
| 28 | <image href="../images/sublayer_block.png" x="60" y="160" width="340" height="500" preserveAspectRatio="xMidYMid slice" clip-path="url(#sublayerImgClip)" /> |
| 29 | <text x="230" y="690" text-anchor="middle" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="12" font-style="italic" fill="#4A5568">One layer block · two sub-layers · residual arcs</text> |
| 30 | </g> |
| 31 | |
| 32 | <g id="parent-frame"> |
| 33 | <rect x="430" y="160" width="790" height="500" rx="12" fill="#F5F7FA" fill-opacity="0.5" stroke="#3182CE" stroke-width="1.5" stroke-dasharray="6,4" /> |
| 34 | <text x="825" y="184" text-anchor="middle" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="12" font-weight="700" fill="#3182CE" letter-spacing="1.5">ONE TRANSFORMER LAYER · ENCODER OR DECODER</text> |
| 35 | </g> |
| 36 | |
| 37 | <g id="card-ffn"> |
| 38 | <rect x="450" y="208" width="240" height="200" rx="10" fill="#FFFFFF" stroke="#E2E8F0" stroke-width="1.5" filter="url(#cardShadow)" /> |
| 39 | <rect x="450" y="208" width="6" height="200" rx="3" fill="#1A365D" /> |
| 40 | <use data-icon="tabler-outline/stack-2" x="470" y="228" width="28" height="28" fill="#1A365D" /> |
| 41 | <text x="506" y="250" font-family="Georgia, "Microsoft YaHei", serif" font-size="18" font-weight="700" fill="#1A365D">Position-wise FFN</text> |
| 42 | <text x="470" y="284" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="14" fill="#1A202C">Two linear layers with ReLU</text> |
| 43 | <text x="470" y="304" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="14" fill="#1A202C">between, applied identically</text> |
| 44 | <text x="470" y="324" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="14" fill="#1A202C">at every position.</text> |
| 45 | <rect x="470" y="346" width="206" height="48" rx="6" fill="#F5F7FA" /> |
| 46 | <text x="482" y="366" font-family="Consolas, "Courier New", monospace" font-size="11" fill="#1A202C">FFN(x) = max(0, xW₁+b₁) W₂+b₂</text> |
| 47 | <text x="482" y="386" font-family="Consolas, "Courier New", monospace" font-size="11" fill="#3182CE">inner dim = 2048 · outer = 512</text> |
| 48 | </g> |
| 49 | |
| 50 | <g id="card-residual"> |
| 51 | <rect x="710" y="208" width="240" height="200" rx="10" fill="#FFFFFF" stroke="#E2E8F0" stroke-width="1.5" filter="url(#cardShadow)" /> |
| 52 | <rect x="710" y="208" width="6" height="200" rx="3" fill="#3182CE" /> |
| 53 | <use data-icon="tabler-outline/arrow-loop-right" x="730" y="228" width="28" height="28" fill="#3182CE" /> |
| 54 | <text x="766" y="250" font-family="Georgia, "Microsoft YaHei", serif" font-size="18" font-weight="700" fill="#1A365D">Residual</text> |
| 55 | <text x="730" y="284" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="14" fill="#1A202C">Skip the sub-layer, add the</text> |
| 56 | <text x="730" y="304" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="14" fill="#1A202C">input back to the output.</text> |
| 57 | <text x="730" y="324" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="14" fill="#1A202C">Enables deep stacks.</text> |
| 58 | <rect x="730" y="346" width="206" height="48" rx="6" fill="#EBF4FB" /> |
| 59 | <text x="742" y="368" font-family="Consolas, "Courier New", monospace" font-size="13" fill="#1A202C">y = x + Sublayer(x)</text> |
| 60 | <text x="742" y="388" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="12" fill="#3182CE" font-style="italic">straight gradient path top → bottom</text> |
| 61 | </g> |
| 62 | |
| 63 | <g id="card-layernorm"> |
| 64 | <rect x="970" y="208" width="240" height="200" rx="10" fill="#FFFFFF" stroke="#E2E8F0" stroke-width="1.5" filter="url(#cardShadow)" /> |
| 65 | <rect x="970" y="208" width="6" height="200" rx="3" fill="#1A365D" /> |
| 66 | <use data-icon="tabler-outline/wave-square" x="990" y="228" width="28" height="28" fill="#1A365D" /> |
| 67 | <text x="1026" y="250" font-family="Georgia, "Microsoft YaHei", serif" font-size="18" font-weight="700" fill="#1A365D">LayerNorm</text> |
| 68 | <text x="990" y="284" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="14" fill="#1A202C">Normalize across feature</text> |
| 69 | <text x="990" y="304" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="14" fill="#1A202C">dimension after the residual</text> |
| 70 | <text x="990" y="324" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="14" fill="#1A202C">addition.</text> |
| 71 | <rect x="990" y="346" width="206" height="48" rx="6" fill="#F5F7FA" /> |
| 72 | <text x="1002" y="366" font-family="Consolas, "Courier New", monospace" font-size="11" fill="#1A202C">LayerNorm(x + Sublayer(x))</text> |
| 73 | <text x="1002" y="386" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="11" fill="#3182CE" font-style="italic">stabilizes training, scale-invariant</text> |
| 74 | </g> |
| 75 | |
| 76 | <g id="combined-flow"> |
| 77 | <rect x="450" y="436" width="760" height="200" rx="12" fill="#FFFFFF" stroke="#E2E8F0" stroke-width="1.5" /> |
| 78 | <rect x="450" y="436" width="6" height="200" rx="3" fill="#3182CE" /> |
| 79 | <text x="470" y="464" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="12" font-weight="700" fill="#3182CE" letter-spacing="1.5">HOW THEY COMPOSE — APPLIED TO EVERY SUB-LAYER</text> |
| 80 | |
| 81 | <rect x="478" y="494" width="160" height="48" rx="6" fill="#F5F7FA" stroke="#1A365D" stroke-width="1.5" /> |
| 82 | <text x="558" y="524" text-anchor="middle" font-family="Georgia, "Microsoft YaHei", serif" font-size="16" font-weight="700" fill="#1A365D">Sublayer(x)</text> |
| 83 | |
| 84 | <text x="660" y="524" text-anchor="middle" font-family="Consolas, "Courier New", monospace" font-size="20" font-weight="700" fill="#3182CE">+</text> |
| 85 | |
| 86 | <rect x="690" y="494" width="80" height="48" rx="6" fill="#EBF4FB" stroke="#3182CE" stroke-width="1.5" /> |
| 87 | <text x="730" y="524" text-anchor="middle" font-family="Georgia, "Microsoft YaHei", serif" font-size="16" font-weight="700" fill="#3182CE">x</text> |
| 88 | |
| 89 | <text x="800" y="524" text-anchor="middle" font-family="Consolas, "Courier New", monospace" font-size="18" font-weight="700" fill="#1A365D">→</text> |
| 90 | |
| 91 | <rect x="830" y="486" width="220" height="64" rx="6" fill="#1A365D" /> |
| 92 | <text x="940" y="514" text-anchor="middle" font-family="Georgia, "Microsoft YaHei", serif" font-size="16" font-weight="700" fill="#FFFFFF">LayerNorm</text> |
| 93 | <text x="940" y="536" text-anchor="middle" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="12" fill="#FFFFFF" fill-opacity="0.9">final sub-layer output</text> |
| 94 | |
| 95 | <text x="1080" y="524" text-anchor="middle" font-family="Consolas, "Courier New", monospace" font-size="18" font-weight="700" fill="#1A365D">→</text> |
| 96 | <text x="1118" y="528" font-family="Consolas, "Courier New", monospace" font-size="14" font-weight="700" fill="#1A365D">next</text> |
| 97 | |
| 98 | <text x="470" y="586" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="12" font-weight="700" fill="#3182CE" letter-spacing="1.5">SHAPE CONTRACT</text> |
| 99 | <text x="470" y="610" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="14" fill="#1A202C">All sub-layers and embeddings emit dimension <tspan font-family="Consolas, monospace" font-weight="700" fill="#3182CE">d_model = 512</tspan> so the residual addition is well-defined.</text> |
| 100 | </g> |
| 101 | |
| 102 | <g id="footer"> |
| 103 | <text x="60" y="694" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="11" fill="#A0AEC0">Source: Vaswani et al. 2017, §3.1 + §3.3 Position-wise Feed-Forward Networks</text> |
| 104 | <text x="1220" y="694" text-anchor="end" font-family="Arial, "Microsoft YaHei", sans-serif" font-size="11" fill="#A0AEC0">10</text> |
| 105 | </g> |
| 106 | </svg> |