Skip to content

Commit d2c3c32

Browse files
committed
Show context and top token in Visualizer
- Add optional context prop (default: "The input text is") - Highlight highest-probability candidate with blinking cursor - Update header text; tweak chart height and spacing - Pass context from App
1 parent f54194e commit d2c3c32

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ const App: React.FC = () => {
9595
{/* Right Column: Visualization */}
9696
<div className="lg:col-span-8">
9797
<div className="space-y-6 animate-in fade-in slide-in-from-bottom-4 duration-500">
98-
{/* Header Text removed from here and integrated into Visualizer for better alignment */}
9998
<Visualizer
10099
candidates={MOCK_CANDIDATES}
101100
temperature={temperature}
102101
topK={topK}
103102
topP={topP}
103+
context="The forecast says tomorrow is"
104104
/>
105105
</div>
106106
</div>

components/Visualizer.tsx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ interface VisualizerProps {
99
temperature: number;
1010
topK: number;
1111
topP: number;
12+
context?: string;
1213
}
1314

14-
export const Visualizer: React.FC<VisualizerProps> = ({ candidates, temperature, topK, topP }) => {
15+
export const Visualizer: React.FC<VisualizerProps> = ({ candidates, temperature, topK, topP, context = "The input text is" }) => {
1516

1617
// --- VISUAL CONSTANTS ---
1718
const CHART_HEIGHT = 100; // Use 100% of the allocated svg space
@@ -104,23 +105,51 @@ export const Visualizer: React.FC<VisualizerProps> = ({ candidates, temperature,
104105
return acc + Math.exp(item.baseLogit / temperature);
105106
}, 0);
106107

108+
const topCandidate = data[0];
109+
107110
return (
108111
<div className="w-full space-y-6">
109112

110113
{/* Main Card */}
111114
<div className="bg-gray-900/80 backdrop-blur-md rounded-2xl p-6 shadow-2xl relative">
112115

113116
{/* Header */}
114-
<div className="mb-4 border-b border-gray-800 pb-2">
117+
<div className="mb-2 border-b border-gray-800 pb-3 flex justify-between items-end">
115118
<div>
116119
<p className="text-sm font-bold uppercase tracking-widest text-gray-400">
117-
Visualizing probability distribution and sampling filters
120+
Next Token Prediction
118121
</p>
119122
</div>
120123
</div>
121124

125+
{/* CONTEXT SENTENCE DISPLAY */}
126+
<div className="mb-6 p-4 bg-black/40 rounded-xl border border-gray-800 flex flex-wrap items-baseline justify-center gap-x-3 gap-y-2 shadow-inner">
127+
<span className="text-gray-400 font-mono text-lg tracking-tight">{context}</span>
128+
<div className="relative group">
129+
<div className="relative inline-block">
130+
<span
131+
className="font-bold text-lg font-mono border-b-2 border-dashed px-2 pb-0.5 transition-all duration-300"
132+
style={{
133+
color: topCandidate.color,
134+
borderColor: topCandidate.color,
135+
textShadow: `0 0 20px ${topCandidate.color}40`
136+
}}
137+
>
138+
{topCandidate.word}
139+
</span>
140+
{/* Blinking Cursor */}
141+
<span className="absolute -right-3 top-1 w-2 h-6 bg-indigo-500 animate-pulse rounded-sm"></span>
142+
</div>
143+
144+
{/* Hover Label */}
145+
<div className="absolute left-1/2 -translate-x-1/2 -top-10 opacity-0 group-hover:opacity-100 transition-opacity bg-gray-800 text-[10px] text-white px-2 py-1 rounded whitespace-nowrap border border-gray-700 pointer-events-none">
146+
Highest Probability Candidate
147+
</div>
148+
</div>
149+
</div>
150+
122151
{/* CHART AREA */}
123-
<div className="h-72 relative mt-4 mx-2 select-none group/chart">
152+
<div className="h-64 relative mt-2 mx-2 select-none group/chart">
124153

125154
{/* LAYER 1: Bars Container (Bottom Z-Index, but allow hover popup) */}
126155
<div
@@ -383,4 +412,4 @@ const generateMonotoneCubicPath = (points: {x: number, y: number}[]) => {
383412
}
384413

385414
return d;
386-
};
415+
};

0 commit comments

Comments
 (0)