2026-01-15 20:10:19 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="linear-projection-demo">
|
|
|
|
|
|
<div class="demo-container">
|
|
|
|
|
|
<!-- Step 1: Patch -->
|
|
|
|
|
|
<div class="step-box">
|
2026-01-18 10:24:35 +08:00
|
|
|
|
<div class="label">1. Patch (16×16×3) (示意 / Toy)</div>
|
2026-01-15 20:10:19 +08:00
|
|
|
|
<div class="grid-patch">
|
2026-01-16 19:10:21 +08:00
|
|
|
|
<div
|
2026-01-18 10:24:35 +08:00
|
|
|
|
v-for="n in patchCellCount"
|
2026-01-16 19:10:21 +08:00
|
|
|
|
:key="n"
|
|
|
|
|
|
class="pixel"
|
|
|
|
|
|
:style="{ backgroundColor: getPixelColor(n) }"
|
|
|
|
|
|
></div>
|
2026-01-15 20:10:19 +08:00
|
|
|
|
</div>
|
2026-01-18 10:24:35 +08:00
|
|
|
|
<div class="desc">16×16 像素 × 3 通道 = 768 标量值</div>
|
2026-01-15 20:10:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="arrow">➜</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Step 2: Flattened -->
|
|
|
|
|
|
<div class="step-box">
|
|
|
|
|
|
<div class="label">2. Flatten</div>
|
|
|
|
|
|
<div class="vector-container">
|
2026-01-16 19:10:21 +08:00
|
|
|
|
<div
|
2026-01-18 10:24:35 +08:00
|
|
|
|
v-for="n in flattenSampleCount"
|
2026-01-16 19:10:21 +08:00
|
|
|
|
:key="n"
|
|
|
|
|
|
class="vector-cell"
|
|
|
|
|
|
:style="{ backgroundColor: getPixelColor(n) }"
|
|
|
|
|
|
></div>
|
2026-01-18 10:24:35 +08:00
|
|
|
|
<div class="vector-ellipsis">…</div>
|
2026-01-15 20:10:19 +08:00
|
|
|
|
</div>
|
2026-01-18 10:24:35 +08:00
|
|
|
|
<div class="desc">得到 1×768 向量 (Vector)</div>
|
2026-01-15 20:10:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="arrow">× W</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Step 3: Projected -->
|
|
|
|
|
|
<div class="step-box">
|
|
|
|
|
|
<div class="label">3. Embedding</div>
|
|
|
|
|
|
<div class="embedding-container">
|
|
|
|
|
|
<div v-for="n in 8" :key="n" class="embed-cell"></div>
|
|
|
|
|
|
</div>
|
2026-01-18 10:24:35 +08:00
|
|
|
|
<div class="desc">映射到 D 维 (示意 D=8;常见 D=768)</div>
|
2026-01-15 20:10:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-01-18 10:24:35 +08:00
|
|
|
|
const patchCellCount = 16 * 16
|
|
|
|
|
|
const flattenSampleCount = 32
|
|
|
|
|
|
|
2026-01-15 20:10:19 +08:00
|
|
|
|
const getPixelColor = (n) => {
|
|
|
|
|
|
// Generate a gradient of colors
|
2026-01-16 19:10:21 +08:00
|
|
|
|
const hue = (n * 20) % 360
|
|
|
|
|
|
return `hsl(${hue}, 70%, 60%)`
|
2026-01-15 20:10:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.linear-projection-demo {
|
|
|
|
|
|
padding: 20px;
|
|
|
|
|
|
background: var(--vp-c-bg-soft);
|
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
|
margin: 20px 0;
|
|
|
|
|
|
overflow-x: auto;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.demo-container {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: space-around;
|
|
|
|
|
|
min-width: 600px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.step-box {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 10px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.label {
|
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
font-size: 0.9em;
|
|
|
|
|
|
color: var(--vp-c-text-2);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.desc {
|
|
|
|
|
|
font-size: 0.8em;
|
|
|
|
|
|
color: var(--vp-c-text-3);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.grid-patch {
|
|
|
|
|
|
display: grid;
|
2026-01-18 10:24:35 +08:00
|
|
|
|
grid-template-columns: repeat(16, 1fr);
|
|
|
|
|
|
gap: 1px;
|
2026-01-15 20:10:19 +08:00
|
|
|
|
width: 80px;
|
|
|
|
|
|
height: 80px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.pixel {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
border-radius: 2px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.vector-container {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
gap: 1px;
|
2026-01-18 10:24:35 +08:00
|
|
|
|
height: 140px;
|
2026-01-15 20:10:19 +08:00
|
|
|
|
width: 20px;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.vector-cell {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-18 10:24:35 +08:00
|
|
|
|
.vector-ellipsis {
|
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
|
line-height: 1;
|
|
|
|
|
|
color: var(--vp-c-text-3);
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
padding-top: 4px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-15 20:10:19 +08:00
|
|
|
|
.embedding-container {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
gap: 2px;
|
|
|
|
|
|
height: 80px;
|
|
|
|
|
|
width: 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.embed-cell {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
|
background-color: var(--vp-c-brand);
|
|
|
|
|
|
opacity: 0.8;
|
|
|
|
|
|
border-radius: 2px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.arrow {
|
|
|
|
|
|
font-size: 1.5em;
|
|
|
|
|
|
color: var(--vp-c-text-3);
|
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|