Files
maths-cs-ai-compendium-zh/images/textcnn_architecture.svg
T

116 lines
8.2 KiB
XML

<svg width="720" height="310" xmlns="http://www.w3.org/2000/svg">
<defs>
<marker id="tcnn-arrow" markerWidth="7" markerHeight="5" refX="7" refY="2.5" orient="auto">
<polygon points="0 0, 7 2.5, 0 5" fill="#555"/>
</marker>
</defs>
<text x="360" y="22" fill="#333" font-size="14" font-weight="bold" text-anchor="middle">TextCNN Architecture</text>
<!-- Input embedding matrix -->
<text x="55" y="48" fill="#333" font-size="11" text-anchor="middle" font-weight="bold">Input</text>
<text x="55" y="62" fill="#666" font-size="9" text-anchor="middle">Embeddings</text>
<!-- Embedding rows (7 tokens) -->
<rect x="20" y="75" width="70" height="18" rx="2" fill="#95a5a6" opacity="0.2" stroke="#95a5a6" stroke-width="1"/>
<text x="10" y="89" fill="#666" font-size="8" text-anchor="end">the</text>
<rect x="20" y="95" width="70" height="18" rx="2" fill="#95a5a6" opacity="0.2" stroke="#95a5a6" stroke-width="1"/>
<text x="10" y="109" fill="#666" font-size="8" text-anchor="end">cat</text>
<rect x="20" y="115" width="70" height="18" rx="2" fill="#95a5a6" opacity="0.2" stroke="#95a5a6" stroke-width="1"/>
<text x="10" y="129" fill="#666" font-size="8" text-anchor="end">sat</text>
<rect x="20" y="135" width="70" height="18" rx="2" fill="#95a5a6" opacity="0.2" stroke="#95a5a6" stroke-width="1"/>
<text x="10" y="149" fill="#666" font-size="8" text-anchor="end">on</text>
<rect x="20" y="155" width="70" height="18" rx="2" fill="#95a5a6" opacity="0.2" stroke="#95a5a6" stroke-width="1"/>
<text x="10" y="169" fill="#666" font-size="8" text-anchor="end">the</text>
<rect x="20" y="175" width="70" height="18" rx="2" fill="#95a5a6" opacity="0.2" stroke="#95a5a6" stroke-width="1"/>
<text x="10" y="189" fill="#666" font-size="8" text-anchor="end">mat</text>
<!-- Arrows to conv filters -->
<line x1="90" y1="130" x2="120" y2="95" stroke="#555" stroke-width="1" marker-end="url(#tcnn-arrow)"/>
<line x1="90" y1="130" x2="120" y2="140" stroke="#555" stroke-width="1" marker-end="url(#tcnn-arrow)"/>
<line x1="90" y1="130" x2="120" y2="195" stroke="#555" stroke-width="1" marker-end="url(#tcnn-arrow)"/>
<!-- Conv filter width=3 (red) -->
<text x="165" y="60" fill="#e74c3c" font-size="10" text-anchor="middle" font-weight="bold">Filter w=3</text>
<rect x="125" y="70" width="80" height="54" rx="4" fill="#e74c3c" opacity="0.12" stroke="#e74c3c" stroke-width="1.5"/>
<rect x="130" y="75" width="70" height="14" rx="2" fill="#e74c3c" opacity="0.3"/>
<rect x="130" y="91" width="70" height="14" rx="2" fill="#e74c3c" opacity="0.3"/>
<rect x="130" y="107" width="70" height="14" rx="2" fill="#e74c3c" opacity="0.3"/>
<!-- Conv filter width=4 (blue) -->
<text x="165" y="138" fill="#3498db" font-size="10" text-anchor="middle" font-weight="bold">Filter w=4</text>
<rect x="125" y="143" width="80" height="72" rx="4" fill="#3498db" opacity="0.12" stroke="#3498db" stroke-width="1.5"/>
<rect x="130" y="148" width="70" height="14" rx="2" fill="#3498db" opacity="0.3"/>
<rect x="130" y="164" width="70" height="14" rx="2" fill="#3498db" opacity="0.3"/>
<rect x="130" y="180" width="70" height="14" rx="2" fill="#3498db" opacity="0.3"/>
<rect x="130" y="196" width="70" height="14" rx="2" fill="#3498db" opacity="0.3"/>
<!-- Conv filter width=5 (green) -->
<text x="165" y="225" fill="#27ae60" font-size="10" text-anchor="middle" font-weight="bold">Filter w=5</text>
<rect x="125" y="230" width="80" height="52" rx="4" fill="#27ae60" opacity="0.12" stroke="#27ae60" stroke-width="1.5"/>
<rect x="130" y="235" width="70" height="8" rx="2" fill="#27ae60" opacity="0.3"/>
<rect x="130" y="245" width="70" height="8" rx="2" fill="#27ae60" opacity="0.3"/>
<rect x="130" y="255" width="70" height="8" rx="2" fill="#27ae60" opacity="0.3"/>
<rect x="130" y="265" width="70" height="8" rx="2" fill="#27ae60" opacity="0.3"/>
<rect x="130" y="275" width="70" height="8" rx="2" fill="#27ae60" opacity="0.3"/>
<!-- Feature maps -->
<text x="290" y="48" fill="#333" font-size="10" text-anchor="middle" font-weight="bold">Feature Maps</text>
<line x1="205" y1="97" x2="250" y2="85" stroke="#e74c3c" stroke-width="1" marker-end="url(#tcnn-arrow)"/>
<rect x="255" y="65" width="18" height="60" rx="3" fill="#e74c3c" opacity="0.25" stroke="#e74c3c" stroke-width="1"/>
<rect x="278" y="65" width="18" height="60" rx="3" fill="#e74c3c" opacity="0.25" stroke="#e74c3c" stroke-width="1"/>
<line x1="205" y1="179" x2="250" y2="160" stroke="#3498db" stroke-width="1" marker-end="url(#tcnn-arrow)"/>
<rect x="255" y="140" width="18" height="50" rx="3" fill="#3498db" opacity="0.25" stroke="#3498db" stroke-width="1"/>
<rect x="278" y="140" width="18" height="50" rx="3" fill="#3498db" opacity="0.25" stroke="#3498db" stroke-width="1"/>
<line x1="205" y1="256" x2="250" y2="225" stroke="#27ae60" stroke-width="1" marker-end="url(#tcnn-arrow)"/>
<rect x="255" y="210" width="18" height="40" rx="3" fill="#27ae60" opacity="0.25" stroke="#27ae60" stroke-width="1"/>
<rect x="278" y="210" width="18" height="40" rx="3" fill="#27ae60" opacity="0.25" stroke="#27ae60" stroke-width="1"/>
<!-- Max-over-time pooling -->
<text x="380" y="48" fill="#333" font-size="10" text-anchor="middle" font-weight="bold">Max Pool</text>
<line x1="296" y1="95" x2="355" y2="85" stroke="#555" stroke-width="1" marker-end="url(#tcnn-arrow)"/>
<rect x="360" y="75" width="40" height="24" rx="4" fill="#e74c3c" opacity="0.3" stroke="#e74c3c" stroke-width="1.5"/>
<text x="380" y="92" fill="#e74c3c" font-size="9" text-anchor="middle">max</text>
<line x1="296" y1="165" x2="355" y2="130" stroke="#555" stroke-width="1" marker-end="url(#tcnn-arrow)"/>
<rect x="360" y="120" width="40" height="24" rx="4" fill="#3498db" opacity="0.3" stroke="#3498db" stroke-width="1.5"/>
<text x="380" y="137" fill="#3498db" font-size="9" text-anchor="middle">max</text>
<line x1="296" y1="230" x2="355" y2="170" stroke="#555" stroke-width="1" marker-end="url(#tcnn-arrow)"/>
<rect x="360" y="160" width="40" height="24" rx="4" fill="#27ae60" opacity="0.3" stroke="#27ae60" stroke-width="1.5"/>
<text x="380" y="177" fill="#27ae60" font-size="9" text-anchor="middle">max</text>
<!-- Concatenation -->
<text x="470" y="48" fill="#333" font-size="10" text-anchor="middle" font-weight="bold">Concat</text>
<line x1="400" y1="87" x2="447" y2="105" stroke="#555" stroke-width="1" marker-end="url(#tcnn-arrow)"/>
<line x1="400" y1="132" x2="447" y2="120" stroke="#555" stroke-width="1" marker-end="url(#tcnn-arrow)"/>
<line x1="400" y1="172" x2="447" y2="138" stroke="#555" stroke-width="1" marker-end="url(#tcnn-arrow)"/>
<rect x="450" y="60" width="40" height="100" rx="5" fill="#f39c12" opacity="0.15" stroke="#f39c12" stroke-width="1.5"/>
<rect x="455" y="70" width="30" height="12" rx="2" fill="#e74c3c" opacity="0.4"/>
<rect x="455" y="88" width="30" height="12" rx="2" fill="#e74c3c" opacity="0.4"/>
<rect x="455" y="106" width="30" height="12" rx="2" fill="#3498db" opacity="0.4"/>
<rect x="455" y="124" width="30" height="12" rx="2" fill="#27ae60" opacity="0.4"/>
<rect x="455" y="142" width="30" height="12" rx="2" fill="#27ae60" opacity="0.4"/>
<!-- Classifier -->
<text x="570" y="48" fill="#333" font-size="10" text-anchor="middle" font-weight="bold">Classifier</text>
<line x1="490" y1="110" x2="530" y2="110" stroke="#555" stroke-width="1.2" marker-end="url(#tcnn-arrow)"/>
<rect x="535" y="80" width="70" height="60" rx="8" fill="#9b59b6" opacity="0.12" stroke="#9b59b6" stroke-width="2"/>
<text x="570" y="106" fill="#9b59b6" font-size="10" text-anchor="middle" font-weight="bold">Dense</text>
<text x="570" y="120" fill="#9b59b6" font-size="10" text-anchor="middle" font-weight="bold">+ Softmax</text>
<!-- Output -->
<line x1="605" y1="110" x2="640" y2="110" stroke="#555" stroke-width="1.2" marker-end="url(#tcnn-arrow)"/>
<text x="680" y="105" fill="#333" font-size="11" text-anchor="middle" font-weight="bold">pos</text>
<text x="680" y="120" fill="#333" font-size="11" text-anchor="middle" font-weight="bold">neg</text>
<!-- Legend -->
<text x="360" y="300" fill="#666" font-size="10" text-anchor="middle">Parallel filters of different widths capture n-gram patterns; max pooling extracts the strongest signal.</text>
</svg>