File size: 3,304 Bytes
23d418f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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>
  )
}