Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Objectives: LO-7.1, LO-7.2, LO-7.3, LO-7.4
Prerequisites: the Module 7 reading
Time: about 2.5 hours

In this lab you evaluate two versions of the dispatcher’s prompt, A and B. The data set has 40 hand-written ticket cases. Each case stores its ticket, its expected label, its kind (typical, edge, or adversarial), its split (development or held out), and three responses from each version. A second file holds 30 paired verdicts: a person’s and a model grader’s pass or fail for the same reply. You split the cases, grade the responses, measure the grader’s agreement with the person, compute Wilson’s interval, and compare A with B by a paired bootstrap.

No cell calls a real model. Every response and verdict was written for this course and is labeled as illustrative, so the numbers you compute describe this data set only.

Use a fresh kernel and run the cells from top to bottom. Fill each answer cell, then run its check. The checks raise errors until their exercises are complete. This notebook runs locally.

Setup

Inspect provenance and coverage

Before you look at version B’s responses, predict which kind of error an exact grader catches. Keep the holdout split for the final check.

Exercise L7.1 (LO-7.1, LO-7.4, ★★, about 25 minutes)

Split by case rather than response. Return a pair (dev, holdout) of lists of cases, by each case’s split field, without dropping or duplicating a case. The only split labels are "dev" and "holdout". Raise ValueError if an id repeats or a split label is unfamiliar. In your notes, add one case of each kind with the reason it belongs.

Exercise L7.2 (LO-7.2, ★★, about 25 minutes)

Separate format from correctness. Return a dictionary with two booleans, "format" and "correct". The format passes when the entire text is Label: followed by repair, billing, or account, with nothing before or after. A response is correct when it passes the format and its queue equals expected.

Exercise L7.3 (LO-7.2, ★★, about 25 minutes)

Measure judge agreement. Each row has a "human" and a "judge" boolean: the person’s and the model grader’s verdict on the same reply. Return a pair (observed, kappa): the share of rows on which they agree, and Cohen’s kappa, which corrects that share for chance agreement. Raise ValueError for zero rows, and return None for kappa when chance agreement is 1.

Exercise L7.4 (LO-7.3, ★★, about 25 minutes)

Implement Wilson’s score interval. Return the lower and upper ends of the interval for successes passes in total independent cases, from the reading’s formula, using z. Count one verdict per case: repeated runs of one case aren’t independent trials. Floating-point roundoff can push an end slightly outside the range from 0 to 1, so clamp each end to that range. Raise ValueError for a total that isn’t positive, or a successes count outside the range from 0 to total.

Exercise L7.5 (LO-7.3, LO-7.4, ★★, about 25 minutes)

Bootstrap pairs and read the plot. a[i] and b[i] are prompts A’s and B’s scores for the same case. Return (estimate, lower, upper), where the estimate is the mean of the differences b[i] - a[i]. Create Random(seed) inside the function, so every call gives the same result. For each of repeats resamples, draw len(a) differences with replacement and take their mean. Sort the means, and return the ones at positions int(0.025 * (repeats - 1)) and int(0.975 * (repeats - 1)) as the bounds.

The check cell then compares A and B on the development cases, and inspects the held-out cases once. In its plot, the horizontal axis is B minus A, as a difference in the share of runs passed. Each line is a 95% paired bootstrap interval, and each dot is its estimate. Notice whether each interval crosses the dashed line at 0.

Summary

  • You split the cases by case, so no ticket’s runs land on both sides of the held-out divide.

  • You graded format and correctness separately, and measured a model grader’s agreement with a person by percent agreement and by Cohen’s kappa.

  • You computed Wilson’s interval for one verdict per independent case, and compared A with B by a paired bootstrap that resamples whole cases, on illustrative responses.