File size: 13,008 Bytes
c0eb006
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39824c1
c0eb006
 
 
39824c1
 
c0eb006
 
39824c1
 
c0eb006
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e7f17af
 
c0eb006
 
e7f17af
c0eb006
e7f17af
 
c0eb006
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e7f17af
 
c0eb006
534a10d
e7f17af
 
 
534a10d
c0eb006
e7f17af
39824c1
c0eb006
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e7f17af
c0eb006
39824c1
534a10d
39824c1
 
 
534a10d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c0eb006
 
 
 
39824c1
c0eb006
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
534a10d
c0eb006
 
 
 
534a10d
 
c0eb006
 
 
 
 
 
 
 
 
 
 
 
 
534a10d
c0eb006
 
534a10d
c0eb006
 
 
 
 
534a10d
 
c0eb006
 
 
 
 
 
534a10d
c0eb006
 
 
 
 
 
 
 
 
 
 
 
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tool errors in training and at evaluation</title>
<!-- Generated by build.py from fragments/. Runtime and theme tokens come from the research-article template. -->
<link rel="stylesheet" href="runtime/variables.css">
<script>
  // The iframe can't read the course page's theme, so follow ?theme= if given, else the OS setting.
  (function () {
    const forced = new URLSearchParams(location.search).get('theme');
    const mq = matchMedia('(prefers-color-scheme: dark)');
    const apply = () => document.documentElement.setAttribute('data-theme', forced || (mq.matches ? 'dark' : 'light'));
    apply();
    if (!forced) mq.addEventListener('change', apply);
  })();
</script>
<script src="runtime/color-palettes.js"></script>
<script src="runtime/rough.js"></script>
<script src="runtime/hand.js"></script>
<script src="runtime/embed-runtime.js"></script>
<style>
  html, body { margin: 0; padding: 0; }
  /* An opaque card with its own background, so it stays readable whatever theme the course page uses */
  body { background: transparent; }
  .figure-card { font-family: 'Source Sans 3', var(--default-font-family); color: var(--text-color); background: var(--page-bg);
                 border: 1px solid var(--border-color); border-radius: 10px; padding: 12px 14px 10px; }
</style>
<script>
  // Clean look by default, in Source Sans. ?style=hand brings back the old hand-drawn look for comparison:
  // it loads Excalifont and uses it for the whole card.
  if (new URLSearchParams(location.search).get('style') === 'hand') {
    const st = document.createElement('style');
    st.textContent = "@font-face { font-family: 'Excalifont'; src: url('runtime/fonts/Excalifont-Regular.woff2') format('woff2'); font-display: swap; }" +
      ".figure-card { font-family: 'Excalifont', 'Source Sans 3', var(--default-font-family); }";
    document.head.appendChild(st);
  } else {
    document.documentElement.classList.add('style-clean');
    const l = document.createElement('link'); l.rel = 'stylesheet';
    l.href = 'https://fonts.googleapis.com/css2?family=Source+Sans+3:wght@400;600;700&display=swap';
    document.head.appendChild(l);
  }
</script>
</head>
<body>
<div class="figure-card">
<!-- title: Tool errors in training and at evaluation -->
<div class="fig-u2-errors"></div>
<style>
  .fig-u2-errors { position: relative; color: var(--text-color); font-size: 14px; }
  .fig-u2-errors svg { display: block; width: 100%; overflow: visible; }
  .fig-u2-errors .fig-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
  .fig-u2-errors button { font: inherit; font-size: 14px; height: 30px; padding: 0 12px; border-radius: 6px; cursor: pointer; color: var(--text-color); background: var(--surface-bg); border: 1px solid var(--border-color); }
  .fig-u2-errors button[aria-pressed="true"] { border-color: var(--primary-color); }
  .fig-u2-errors button:focus-visible { outline: 2px solid var(--primary-color); outline-offset: 2px; }
  .fig-u2-errors .fig-note { margin: 6px 0 0; min-height: 2.8em; color: var(--muted-color); }
</style>
<script>
  Embed.mount('fig-u2-errors', (ctx) => {
    const NS = 'http://www.w3.org/2000/svg';
    // Counts from the course pages: 65 of the 1,380 kept traces have a tool error, and every kept trace passed
    // the hidden tests (learning-from-traces). The SFT model's evaluation: 270 of 771 runs hit a tool error and
    // 60 of them still passed every test (unit2/evaluate, Job 4, job 6afef9a1). Each square is 1% of the traces or runs, rounded.
    const PANELS = [
      { title: 'What the student trained on', short: 'Trained on', sub: '1,380 teacher traces', counts: { none: 1315, fixed: 65, failed: 0 }, total: 1380 },
      { title: 'What it meets at evaluation', short: 'Meets at evaluation', sub: '771 runs of the SFT model', subShort: '771 SFT model runs', counts: { none: 501, fixed: 60, failed: 210 }, total: 771 },
    ];
    // The base model in the same evaluation job: 395 of 771 runs hit a tool error, 111 still passed (28.1%).
    const BASE = { title: 'The base model at evaluation', short: 'Base model', sub: '771 runs of Qwen3-1.7B, no training', subShort: '771 base model runs', counts: { none: 376, fixed: 111, failed: 284 }, total: 771 };
    const SFT = PANELS[1];
    const KINDS = [
      { key: 'none', label: 'no tool error' },
      { key: 'fixed', label: 'tool error, then passed every test' },
      { key: 'failed', label: 'tool error, then failed' },
    ];
    // Largest-remainder rounding to 100 squares.
    [...PANELS, BASE].forEach((p) => {
      const raw = KINDS.map((k) => (100 * p.counts[k.key]) / p.total);
      const cells = raw.map(Math.floor);
      let left = 100 - cells.reduce((a, b) => a + b, 0);
      raw.map((r, i) => [r - Math.floor(r), i]).sort((a, b) => b[0] - a[0]).forEach(([, i]) => { if (left > 0) { cells[i]++; left--; } });
      p.cells = cells;
    });
    const NOTES = {
      none: 'Runs where every run_python call worked. 95% of the training traces, 65% of the evaluation runs.',
      fixed: 'A tool error, and the run still passed every test. In training that\'s all 65 error traces, because failed runs were thrown away. At evaluation, 60 of the 270 runs with an error (22%).',
      failed: 'A tool error the agent didn\'t recover from. The student never saw one of these in training, and 210 of its 771 evaluation runs end this way.',
    };
    const NOTES_BASE = {
      none: 'Runs where every run_python call worked. 95% of the training traces, 49% of the base model\'s evaluation runs.',
      fixed: 'A tool error, and the run still passed every test. The base model recovers in 111 of its 395 runs with an error (28%).',
      failed: 'A tool error the agent didn\'t recover from. 284 of the base model\'s 771 evaluation runs end this way.',
    };
    let view = 'sft';
    const DEFAULT_BASE = 'The base model, in the same evaluation job. It hits a tool error more often than the SFT model (51% of runs against 35%), and recovers from more of them (28% against 22%). Switch back to the SFT model to compare.';
    const DEFAULT = 'Each square is 1% of the traces or runs. Errors are rare in what the student trained on and common in what it meets. Hover a square to read about its group.';

    let width = 640, hover = null;
    const svg = document.createElementNS(NS, 'svg');
    const note = document.createElement('p');
    note.className = 'fig-note';
    note.setAttribute('aria-live', 'polite');
    const controls = document.createElement('div');
    controls.className = 'fig-controls';
    const buttons = {};
    [['sft', 'SFT model'], ['base', 'Base model']].forEach(([key, label]) => {
      const b = document.createElement('button');
      b.type = 'button'; b.textContent = label;
      b.addEventListener('click', () => { view = key; PANELS[1] = key === 'base' ? BASE : SFT; draw(); }, { signal: ctx.signal });
      buttons[key] = b; controls.appendChild(b);
    });
    ctx.root.append(svg, controls, note);
    ctx.describe('Two grids of 100 squares, each square 1%. Squares with a tool error are orange, with a check mark if the run still passed every test and a cross if it failed. Left, the 1,380 traces the student trained on, where 65 (5%) contain a tool error and all of them end with the tests passing, because only passing traces were kept. Right, the 771 evaluation runs of the SFT model, where 270 (35%) hit a tool error, 60 of them still passed every test and 210 failed. A button switches the right grid to the base model, where 395 of 771 runs (51%) hit a tool error and 111 of them still passed.');

    // One palette hue (orange) for every run with a tool error. Recovered runs get a tinted fill and a check mark,
    // failed runs a solid fill and a cross, so the two differ in lightness and in shape, not only in color.
    function palette(C) {
      return { err: C.orange, errTint: C.orangeSoft, onErr: C.dark ? '#0f1115' : '#1f2937', check: C.orangeText,
               none: C.dark ? 'rgba(255, 255, 255, 0.28)' : 'rgba(0, 0, 0, 0.26)', noneFill: C.dark ? 'rgba(255, 255, 255, 0.04)' : 'rgba(0, 0, 0, 0.02)' };
    }
    function el(tag, attrs, parent) {
      const n = document.createElementNS(NS, tag);
      Object.entries(attrs).forEach(([a, v]) => n.setAttribute(a, v));
      parent.appendChild(n);
      return n;
    }
    // A square of side s at (x, y), with its mark.
    function square(parent, P, key, x, y, s) {
      const r = Math.min(3, s / 5);
      if (key === 'none') {
        el('rect', { x: x + 0.5, y: y + 0.5, width: s - 1, height: s - 1, rx: r, fill: P.noneFill, stroke: P.none, 'stroke-width': 1 }, parent);
        return;
      }
      const solid = key === 'failed';
      el('rect', { x: x + 0.75, y: y + 0.75, width: s - 1.5, height: s - 1.5, rx: r, fill: solid ? P.err : P.errTint, stroke: P.err, 'stroke-width': 1.5 }, parent);
      const m = s * 0.3, cx = x + s / 2, cy = y + s / 2;
      const d = solid
        ? `M${cx - m * 0.8},${cy - m * 0.8} L${cx + m * 0.8},${cy + m * 0.8} M${cx + m * 0.8},${cy - m * 0.8} L${cx - m * 0.8},${cy + m * 0.8}`
        : `M${cx - m},${cy + m * 0.05} L${cx - m * 0.3},${cy + m * 0.7} L${cx + m},${cy - m * 0.7}`;
      el('path', { d, fill: 'none', stroke: solid ? P.onErr : P.check, 'stroke-width': Math.max(1.6, s / 9), 'stroke-linecap': 'round', 'stroke-linejoin': 'round' }, parent);
    }

    function draw() {
      const C = Hand.colors(ctx.root);
      const P = palette(C);
      svg.replaceChildren();
      const h = Hand.create(svg, { seed: 31 });
      const narrow = width < 700;
      const gap = narrow ? 20 : 36;
      const pw = (width - gap) / 2;
      const cell = Math.min(24, Math.floor((pw - 2) / 10));
      const grid = cell * 10;
      const fs = narrow ? 13 : 14;
      let bottom = 0;
      PANELS.forEach((p, pi) => {
        const x0 = pi * (pw + gap) + (narrow ? 0 : (pw - grid) / 2);
        h.text(x0, 16, narrow ? p.short : p.title, { size: narrow ? 15 : 16, color: C.ink });
        h.text(x0, 35, narrow ? (p.subShort || p.sub) : p.sub, { size: fs, color: C.muted });
        const gy = 46;
        let idx = 0;
        KINDS.forEach((k, ki) => {
          const g = el('g', { opacity: hover && hover !== k.key ? 0.3 : 1 }, svg);
          for (let c = 0; c < p.cells[ki]; c++, idx++) {
            const col = idx % 10, row = Math.floor(idx / 10);
            const x = x0 + col * cell, y = gy + row * cell;
            const pad = cell > 18 ? 2 : 1.5;
            square(g, P, k.key, x + pad, y + pad, cell - 2 * pad);
            const r = el('rect', { x, y, width: cell, height: cell, fill: 'transparent' }, svg);
            r.style.cursor = 'pointer';
            r.addEventListener('pointerenter', () => setHover(k.key));
            r.addEventListener('click', () => setHover(k.key));
          }
        });
        const err = p.counts.fixed + p.counts.failed;
        const pct = Math.round((100 * err) / p.total);
        const rec = Math.round((100 * p.counts.fixed) / err);
        const lines = narrow
          ? [`${err.toLocaleString('en-US')} of ${p.total.toLocaleString('en-US')} (${pct}%)`, 'with a tool error',
             p.counts.failed === 0 ? 'all end with a fix' : `${p.counts.fixed} still passed (${rec}%)`]
          : [`${err.toLocaleString('en-US')} of ${p.total.toLocaleString('en-US')} (${pct}%) with a tool error`,
             p.counts.failed === 0 ? 'all of them end with a fix' : `${p.counts.fixed} of them still passed every test (${rec}%)`];
        lines.forEach((l, li) => h.text(x0, gy + grid + 22 + li * 19, l, { size: fs, color: li === lines.length - 1 ? C.muted : C.ink, weight: li === 0 ? 600 : undefined }));
        bottom = Math.max(bottom, gy + grid + 22 + (lines.length - 1) * 19);
      });
      // Legend, with the same marks as the grids.
      let ly = bottom + 30;
      let lx = 0;
      KINDS.forEach((k) => {
        const w = 22 + k.label.length * (narrow ? 6.6 : 7.2) + 18;
        if (lx + w > width) { lx = 0; ly += 24; }
        square(svg, P, k.key, lx, ly - 13, 16);
        h.text(lx + 22, ly, k.label, { size: fs, color: C.muted });
        lx += w;
      });
      const H = ly + 10;
      svg.setAttribute('viewBox', `0 0 ${width} ${H}`);
      svg.setAttribute('height', H);
      Object.entries(buttons).forEach(([k, b]) => b.setAttribute('aria-pressed', String(k === view)));
      note.textContent = hover ? (view === 'base' ? NOTES_BASE : NOTES)[hover] : (view === 'base' ? DEFAULT_BASE : DEFAULT);
    }
    function setHover(k) { hover = k; draw(); }
    svg.addEventListener('pointerleave', () => { hover = null; draw(); }, { signal: ctx.signal });

    if (document.fonts && document.fonts.ready) document.fonts.ready.then(() => { if (!ctx.signal.aborted) draw(); });
    return ({ width: w }) => { width = w; draw(); };
  }, { deps: [] });
</script>

</div>
</body>
</html>