figures / unit2-rejection-sampling.html
sergiopaniego's picture
sergiopaniego HF Staff
Brand teal accent, readable text colors, U4 nudge redesign, U7 figures
39824c1 verified
Raw History Blame Contribute Delete
6.98 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Collecting traces from a teacher</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: Collecting traces from a teacher -->
<div class="fig-rejection-sampling"></div>
<style>
.fig-rejection-sampling { position: relative; color: var(--text-color); font-size: 14px; }
.fig-rejection-sampling svg { display: block; width: 100%; overflow: visible; }
</style>
<script>
Embed.mount('fig-rejection-sampling', (ctx) => {
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
ctx.root.appendChild(svg);
ctx.describe('Collecting traces from a teacher. The teacher attempts each of the 464 training problems 4 times in the same harness as the agent, giving 1,856 attempts. The hidden tests check every attempt. The 1,380 attempts that pass every test are kept as traces and become the SFT dataset, and 476 are discarded. 385 of the 464 problems end up with at least one trace.');
const FS = 15, LH = FS * 1.25;
function box(h, C, x, y, w, ht, label, tone) {
const fill = tone ? C[tone + 'Soft'] : C.greySoft;
const stroke = tone ? C[tone] : C.grey;
h.rect(x, y, w, ht, { fill, stroke, width: 1.4 });
const lines = label.split('\n');
h.text(x + w / 2, y + ht / 2 - (lines.length - 1) * LH / 2 + FS * 0.35, label, { size: FS, anchor: 'middle', color: C.ink });
}
return ({ width }) => {
const C = Hand.colors(ctx.root);
svg.replaceChildren();
const h = Hand.create(svg, { seed: 2 });
const arrow = (pts, o = {}) => h.arrow(pts, { stroke: C.ink, width: 1.4, ...o });
const B = {
problems: ['464 training\nproblems', null],
teacher: ['Teacher in the\nsame harness\n(4 attempts each)', 'teal'],
attempts: ['1,856\nattempts', null],
tests: ['Hidden tests', null],
kept: ['1,380 traces\nkept', 'green'],
sft: ['SFT dataset\n(messages + tools)', null],
};
let H;
if (width >= 560) {
// Two rows that snake: problems > teacher > attempts, down to the tests, then back left to the dataset.
const gap = 70, bw = (width - 2 * gap) / 3, bh = 80;
const xs = [0, bw + gap, 2 * (bw + gap)], y1 = 4, y2 = y1 + bh + 70;
box(h, C, xs[0], y1, bw, bh, ...B.problems);
box(h, C, xs[1], y1, bw, bh, ...B.teacher);
box(h, C, xs[2], y1, bw, bh, ...B.attempts);
box(h, C, xs[2], y2, bw, bh, ...B.tests);
box(h, C, xs[1], y2, bw, bh, ...B.kept);
box(h, C, xs[0], y2, bw, bh, ...B.sft);
const m1 = y1 + bh / 2, m2 = y2 + bh / 2, cx = xs[2] + bw / 2;
arrow([[xs[0] + bw + 6, m1], [xs[1] - 6, m1]]);
arrow([[xs[1] + bw + 6, m1], [xs[2] - 6, m1]]);
arrow([[cx, y1 + bh + 6], [cx, y2 - 6]]);
arrow([[xs[2] - 6, m2], [xs[1] + bw + 6, m2]], { stroke: C.green });
h.text(xs[2] - gap / 2, m2 - 12, 'all pass', { size: 13, anchor: 'middle', color: C.greenText });
arrow([[xs[1] - 6, m2], [xs[0] + bw + 6, m2]]);
// Failed attempts drop out below the tests.
const yd = y2 + bh + 46;
arrow([[cx, y2 + bh + 6], [cx, yd - 4]], { stroke: C.grey, dashed: true });
h.text(cx, yd + 14, '476 discarded', { size: 14, anchor: 'middle', color: C.muted });
h.text(0, yd + 14, '385 of the 464 problems end up with at least one trace.', { size: 14, color: C.muted });
H = yd + 24;
} else {
// One column, top to bottom, with the discarded attempts branching to the right.
const side = Math.min(130, width * 0.32);
const bw = Math.min(260, width - side - 12), bh = 62, gap = 34, x = 0, cx = bw / 2;
const order = ['problems', 'teacher', 'attempts', 'tests', 'kept', 'sft'];
let y = 4;
order.forEach((k, i) => {
const ht = k === 'teacher' ? 74 : bh;
box(h, C, x, y, bw, ht, ...B[k]);
if (k === 'tests') {
arrow([[bw + 6, y + ht / 2], [bw + 34, y + ht / 2]], { stroke: C.grey, dashed: true });
h.text(bw + 40, y + ht / 2 + 5, '476\ndiscarded', { size: 14, color: C.muted });
}
if (i < order.length - 1) {
const isPass = k === 'tests';
arrow([[cx, y + ht + 4], [cx, y + ht + gap - 4]], isPass ? { stroke: C.green } : {});
if (isPass) h.text(cx + 10, y + ht + gap / 2 + 5, 'all pass', { size: 13, color: C.greenText });
}
y += ht + gap;
});
h.text(0, y + 2, '385 of the 464 problems end up\nwith at least one trace.', { size: 14, color: C.muted });
H = y + 30;
}
svg.setAttribute('viewBox', `0 0 ${width} ${H}`);
svg.setAttribute('height', H);
};
}, { deps: [] });
</script>
</div>
</body>
</html>