Compare Versions Case by Case

In Rerun the Same Prompt, v1 moved fifteen points over five runs with nothing changed, and v2’s single run landed inside that spread. When each rate varies from run to run, subtracting two of them can’t pick a winner.

In this lesson, you’ll save which cases pass in each run, compare v1 and v2 on the same twenty cases, and measure how much v1 disagrees with itself. You’ll finish with a decision you can defend with the numbers.

Save Each Case’s Pass Share

A pass rate hides which cases passed, but you need that information to compare versions. Over several runs, each case gets a pass share: the fraction of runs in which it passed, such as 3 of 5. The shares say which cases to read, and the answers say why they failed, so keep both.

A pass rate also belongs to the models that produced it, as Measure the Assistant showed. Both answer() and askForJson() return the model that replied. In evals/judge.js, keep it in judgeStatus():

Language: JavaScript Filename: evals/judge.js
  const { data, model } = await askForJson({
    // the same instructions, schema and messages
  });
  return { ...data, model };

Then open evals/rerun.js, add writeFileSync to its first import, and replace everything from runOnce() down with this:

Language: JavaScript Filename: evals/rerun.js
const answers = [];
const models = [];

async function runOnce(run) {
  const failed = [];
  for (const c of graded) {
    const r = latestReport(c.place);
    const report = `${r.date}, ${r.by}: ${r.text}`;
    const { text, model } = await answer(c.question, version);
    const { reason, verdict, model: judge } = await judgeStatus(
      { question: c.question, answer: text, report });
    const used = { answer: model, judge };
    const seen = models.some((m) =>
      m.answer === model && m.judge === judge);
    if (!seen) models.push(used);
    answers.push({ id: c.id, version, run, verdict, reason,
      models: used, answer: text, report });
    if (verdict === "fail") failed.push(c.id);
  }
  return failed;
}

const passes = {};
for (const c of graded) passes[c.id] = 0;
const perRun = [];

for (let run = 1; run <= Number(runs); run++) {
  const failed = await runOnce(run);
  const passed = graded.length - failed.length;
  const rate = (100 * passed / graded.length).toFixed(1);
  console.log(`${version} run ${run}: ${passed} of ${graded.length}`
    + ` (${rate}%) failed: ${failed.join(" ") || "none"}`);
  perRun.push(passed);
  for (const c of graded) {
    if (!failed.includes(c.id)) passes[c.id]++;
  }
}

const file = `evals/results/rerun-${version}.json`;
const result = { version, models, runs: Number(runs),
  cases: graded.length, perRun, passes, answers };
writeFileSync(file, JSON.stringify(result, null, 2));
console.log(`Saved ${file}`);

The results file lists every model pair the batch used, so you can spot a mid-batch change. It also keeps each run’s pass count in perRun, each case’s passes in passes, and every answer with its models, report, verdict, and reason in answers. Run npm run rerun -- v1 5, then npm run rerun -- v2 5. Each takes a few minutes.

Compare the Cases That Changed

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.