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-5.1, LO-5.2, LO-5.3
Prerequisites: the Module 5 reading and Lab 4
Time: about 2.5 hours

In this lab you treat the shop’s 24 labeled tickets as a pool of examples. You put examples in their own tagged section, audit the pool’s labels and lengths, and turn tickets into word sets. Then you rank the pool by Jaccard similarity to a new ticket, and compare the nearest examples with a fixed, balanced set by the labels each covers.

The tickets come from data/tickets.json. No cell sends anything over the network or calls a model.

Use a fresh kernel and run the cells from top to bottom. Fill each answer cell, then run its check, which prints passed or fails with a message that says what is wrong. The checks fail on purpose until their exercises are complete.

Setup

Contrast cases

The same word can appear in tickets for different queues. This cell prints every ticket that contains “brake”, with its label: the word appears in both repair and billing tickets.

Exercise L5.1 (LO-5.1, ★★, about 25 minutes)

Put examples in their own section. Write examples_xml(rows), which returns XML with an examples root element. For each row, add an example element containing an input element, with the ticket’s text, and an output element. The output uses Label: <queue>. Write your own contrast pair in your notes before checking.

Exercise L5.2 (LO-5.2, ★★, about 25 minutes)

Audit labels and lengths. Write coverage(rows), which returns two dictionaries: the count of each label, and the count of "short" and "long" examples. Split each text on whitespace. A short example has at most nine words. Compare the first four rows with the full pool, and identify the missing queues.

Exercise L5.3 (LO-5.3, ★★, about 25 minutes)

Tokenize into word sets. Write words(text), which returns the set of lowercased alphabetic runs matched by the regular expression [a-z]+. Keep unique words only.

Exercise L5.4 (LO-5.3, LO-5.2, ★★, about 25 minutes)

Compare fixed and dynamic selections. Write pick(text, rows, k), which ranks rows by the Jaccard similarity of their word sets to the word set of text, and returns the first k rows. Break ties by ascending ID. If both sets are empty, score zero. Raise ValueError when k is outside the available range. Compare the label counts of the dynamic results with a hand-picked balanced set for three new queries. Hold the prompt template constant when you compare selections.

Summary

You built and inspected a pool of examples. The nearest examples and a balanced set serve different aims: the first finds tickets that look like the input, and the second shows every label.