Spaces:
Sleeping
Sleeping
Download web/src/components/evals/TradeoffChart.tsx from TBM99/CoverageCheck: direct link, hf CLI and curl.
- Browser
- Download file 3.3 kB
-
https://huggingface.co/spaces/TBM99/CoverageCheck/resolve/main/web/src/components/evals/TradeoffChart.tsx
- Command line
-
hf download hf://spaces/TBM99/CoverageCheck/web/src/components/evals/TradeoffChart.tsx
-
curl -L -o TradeoffChart.tsx https://huggingface.co/spaces/TBM99/CoverageCheck/resolve/main/web/src/components/evals/TradeoffChart.tsx
3.3 kB
| import { CartesianGrid, ErrorBar, LabelList, ResponsiveContainer, Scatter, ScatterChart, Tooltip, XAxis, YAxis } from 'recharts' | |
| import { INK, ORDER, SERIES } from '@/lib/chart' | |
| import { percent, seconds } from '@/lib/format' | |
| import type { EvalsFile } from '@/lib/types' | |
| /** What accuracy costs in time: each system as one dot at (median seconds, accuracy), | |
| * a whisker out to its 95th-percentile time, labelled directly (three dots: a legend | |
| * would only repeat the labels). */ | |
| export function TradeoffChart({ data }: { data: EvalsFile }) { | |
| const points = ORDER.map((s) => { | |
| const x = data.systems[s] | |
| return { | |
| s, | |
| label: `${s.toUpperCase()} · ${percent(x.accuracy)}`, | |
| seconds: x.latency_p50_ms / 1000, | |
| p95: x.latency_p95_ms / 1000, | |
| err: [0, (x.latency_p95_ms - x.latency_p50_ms) / 1000], | |
| accuracy: x.accuracy, | |
| tokens: x.tokens_mean, | |
| } | |
| }) | |
| return ( | |
| <div className="h-72" role="img" aria-label="Accuracy against median answer time for systems A, B and C; the table below has every value"> | |
| <ResponsiveContainer width="100%" height="100%"> | |
| <ScatterChart margin={{ top: 20, right: 24, bottom: 16, left: -8 }}> | |
| <CartesianGrid stroke={INK.grid} /> | |
| <XAxis | |
| type="number" | |
| dataKey="seconds" | |
| domain={[0, 45]} | |
| ticks={[0, 10, 20, 30, 40]} | |
| tickFormatter={(v: number) => `${v} s`} | |
| tickLine={false} | |
| axisLine={{ stroke: INK.axis }} | |
| tick={{ fill: INK.muted, fontSize: 11 }} | |
| label={{ value: 'Median time per answer (whisker: 95th percentile)', position: 'insideBottom', offset: -10, fill: INK.muted, fontSize: 11 }} | |
| /> | |
| <YAxis | |
| type="number" | |
| dataKey="accuracy" | |
| domain={[0, 1]} | |
| ticks={[0, 0.25, 0.5, 0.75, 1]} | |
| tickFormatter={(v: number) => percent(v)} | |
| tickLine={false} | |
| axisLine={false} | |
| tick={{ fill: INK.muted, fontSize: 11 }} | |
| /> | |
| <Tooltip cursor={false} content={<TradeoffTooltip />} /> | |
| {points.map((p) => ( | |
| <Scatter key={p.s} data={[p]} fill={SERIES[p.s]} stroke="white" strokeWidth={2} isAnimationActive={false}> | |
| <ErrorBar dataKey="err" direction="x" width={0} stroke={SERIES[p.s]} strokeWidth={2} /> | |
| <LabelList dataKey="label" position="top" offset={10} style={{ fill: INK.primary, fontSize: 12, fontWeight: 600 }} /> | |
| </Scatter> | |
| ))} | |
| </ScatterChart> | |
| </ResponsiveContainer> | |
| </div> | |
| ) | |
| } | |
| type Props = { active?: boolean; payload?: { payload: { s: string; seconds: number; p95: number; accuracy: number; tokens: number } }[] } | |
| function TradeoffTooltip({ active, payload }: Props) { | |
| if (!active || !payload?.length) return null | |
| const p = payload[0].payload | |
| return ( | |
| <div className="rounded-lg border bg-background px-3 py-2 text-xs tabular-nums shadow-md"> | |
| <p className="font-medium">System {p.s.toUpperCase()}</p> | |
| <p> | |
| {percent(p.accuracy)} correct · {seconds(p.seconds * 1000)} median, {seconds(p.p95 * 1000)} at the 95th percentile | |
| </p> | |
| <p className="text-muted-foreground">{(p.tokens / 1000).toFixed(1)}k tokens per question</p> | |
| </div> | |
| ) | |
| } | |