From 82bd829db5a7ff9abd2b8504c17b872cacf0d472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Hadry=C5=9B?= Date: Fri, 16 Oct 2026 02:52:34 +0200 Subject: [PATCH 1/2] feat(cleanup): let the S1-mini prompt ask for the email context The prompt pinned [Context: general]. Calibration needs to request the model's trained email layout. An optional context field on the S1 style does that; every app caller omits it and still sends general with the same prompt bytes. Part of #281 --- packages/cleanup/src/prompt.test.ts | 11 +++++++++++ packages/cleanup/src/prompt.ts | 11 ++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/cleanup/src/prompt.test.ts b/packages/cleanup/src/prompt.test.ts index 3ce629f5..7dbc357c 100644 --- a/packages/cleanup/src/prompt.test.ts +++ b/packages/cleanup/src/prompt.test.ts @@ -18,3 +18,14 @@ test("builds the exact S1-mini Qwen3 template from the model card", () => { "\n", ); }); + +test("asks for email layout only when the style names it", () => { + const prompt = buildS1MiniPrompt("hi maria best tom", { + styling: "semi-formal", + context: "email", + }); + + expect(prompt).toContain( + "<|im_start|>user\n[Styling: semi-formal] [Structure: prose] [Context: email]\nhi maria best tom<|im_end|>", + ); +}); diff --git a/packages/cleanup/src/prompt.ts b/packages/cleanup/src/prompt.ts index 080d708e..b991dc7d 100644 --- a/packages/cleanup/src/prompt.ts +++ b/packages/cleanup/src/prompt.ts @@ -1,16 +1,21 @@ export const STYLINGS = ["casual", "semi-casual", "semi-formal", "formal"] as const; -export type CleanupStyle = { styling: (typeof STYLINGS)[number] }; +export const CONTEXTS = ["general", "email"] as const; + +export type CleanupStyle = { + styling: (typeof STYLINGS)[number]; + context?: (typeof CONTEXTS)[number]; +}; const SYSTEM_PROMPT = "You are a text normalizer for speech-to-text transcripts. The input begins with a control line specifying the styling, structure, and context settings; clean the transcript to match those settings and output only the cleaned text."; // S1-mini is trained on this exact Qwen3 chat template, including the empty think block that opens the assistant turn. -// The model requires all three control fields; Voice only exposes styling, so structure and context stay pinned. +// The model requires all three control fields. export function buildS1MiniPrompt(raw: string, style: CleanupStyle): string { return ( `<|im_start|>system\n${SYSTEM_PROMPT}<|im_end|>\n` + - `<|im_start|>user\n[Styling: ${style.styling}] [Structure: prose] [Context: general]\n${raw}<|im_end|>\n` + + `<|im_start|>user\n[Styling: ${style.styling}] [Structure: prose] [Context: ${style.context ?? "general"}]\n${raw}<|im_end|>\n` + `<|im_start|>assistant\n\n\n\n\n` ); } From d28525c5e09baac21cc5985db318467fa7433b6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Hadry=C5=9B?= Date: Fri, 16 Oct 2026 02:52:35 +0200 Subject: [PATCH 2/2] test(cleanup): calibrate S1-mini stylings across general and email layouts The sweep now runs every fixture under each Styling tag and both Context values, and records one row per fixture, styling and context with its latency. New synthetic fixtures cover chat lines, a work message, emails with greeting and sign-off, one-line email replies, endings that stress a final-period rule, and a long email that spans two cleanup chunks. Part of #281 --- packages/cleanup/fixtures/dictations.json | 80 +++++++++++++++++++++++ packages/cleanup/scripts/calibrate.mts | 54 ++++++++------- 2 files changed, 112 insertions(+), 22 deletions(-) diff --git a/packages/cleanup/fixtures/dictations.json b/packages/cleanup/fixtures/dictations.json index 907ea2d5..d04faf78 100644 --- a/packages/cleanup/fixtures/dictations.json +++ b/packages/cleanup/fixtures/dictations.json @@ -395,6 +395,82 @@ "name": "long-natural", "text": "okay so for the quarterly planning doc i want to start with the goals section we have three goals this quarter the first one is to reduce onboarding time from twelve minutes to under five minutes and the way we plan to do that is by cutting the permissions screen in half and moving the microphone test later in the flow the second goal is to ship windows support by the end of november which means we need to finish the insertion adapter and the shortcut handling and get at least twenty beta testers on it before we call it done the third goal is reliability we had about four hundred crash reports last month most of them from the audio device switching path so priya is going to own that and lukas will help her with the test fixtures then in the risks section mention that the cleanup model might be too slow on older intel macs and that we have not tested it on machines with eight gigabytes of memory also mention that the legal review for the new privacy policy is still pending and could slip into december finally in the next steps section say that we will meet again on the fourteenth to review progress and that everyone should update their tickets before then" }, + { + "name": "chat-coming-tonight", + "text": "hey are you coming tonight um i was thinking we could grab pizza first let me know" + }, + { + "name": "chat-lunch", + "text": "hey are you free for lunch tomorrow lets do twelve if that works for you" + }, + { + "name": "chat-running-late", + "text": "omg im so sorry im running like ten minutes late save me a seat" + }, + { + "name": "work-status-update", + "text": "hey team quick update um the api migration is done and i deployed it to staging this morning can someone review the pr before friday" + }, + { + "name": "work-ask", + "text": "hi tom do you have a few minutes today to go over the q four roadmap i want to make sure we are aligned before the all hands" + }, + { + "name": "email-deck", + "text": "hi maria thanks for sending the deck um i went through it last night and the pricing section looks great i have a couple of small notes on the timeline which i will send over tomorrow best mateusz" + }, + { + "name": "email-intro", + "text": "hello priya i hope you are doing well i wanted to introduce you to lukas who leads our design team he has some great ideas for the onboarding flow and i think you two should talk thanks again kind regards mateusz" + }, + { + "name": "email-reply-see-you", + "text": "sounds good see you then" + }, + { + "name": "email-reply-works", + "text": "thanks that works for me" + }, + { + "name": "email-reply-attached", + "text": "sure i attached the updated contract let me know if you have any questions" + }, + { + "name": "ending-pm-dotted", + "text": "can we move the call to tomorrow at 3 p.m." + }, + { + "name": "ending-pm-spoken", + "text": "ill be home around five pm" + }, + { + "name": "ending-url-spoken", + "text": "the new build is up check voice dot app" + }, + { + "name": "ending-url-written", + "text": "for the docs go to example.com" + }, + { + "name": "ending-trailing-off", + "text": "i was going to say something but um i dont know..." + }, + { + "name": "ending-question", + "text": "did you get a chance to look at the proposal" + }, + { + "name": "names-github-api", + "text": "can you ask kenji to push the fix to github before the api review with nasa" + }, + { + "name": "note-reminder", + "text": "remember to um buy milk and call the dentist on thursday about the appointment" + }, + { + "name": "note-idea", + "text": "idea for the blog post we could write about how we cut startup time in half and what we learned" + }, { "name": "long-varied-50", "generate": "varied" @@ -402,5 +478,9 @@ { "name": "long-repetitive-50", "generate": "repetitive" + }, + { + "name": "long-email", + "generate": "email" } ] diff --git a/packages/cleanup/scripts/calibrate.mts b/packages/cleanup/scripts/calibrate.mts index 99789fad..a91a0bfb 100644 --- a/packages/cleanup/scripts/calibrate.mts +++ b/packages/cleanup/scripts/calibrate.mts @@ -1,5 +1,3 @@ -// Runs the synthetic dictation fixtures through the real S1-mini model once, records what the -// model returned for every chunk as JSONL, and replays the plausibility guard over the recording. // The guard runs only in the replay, so rerunning with an existing recording re-checks a changed // guard without touching the model, and a rerun of the model re-checks a changed model or prompt. // @@ -10,7 +8,7 @@ import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { assertPlausibleCleanup, wordSurvival } from "../src/plausibility.ts"; -import { STYLINGS, type CleanupStyle } from "../src/prompt.ts"; +import { CONTEXTS, STYLINGS, type CleanupStyle } from "../src/prompt.ts"; import { createS1Mini, type Generation } from "../src/s1mini.ts"; const [modelPath, recordingPath] = process.argv.slice(2); @@ -31,13 +29,16 @@ const tasks = [ const days = ["monday", "tuesday", "wednesday", "thursday", "friday"]; const line = (i: number, task: string, day: string) => `${people[i % 6]} will ${task} by ${day} and send a short update to ${people[(i + 1) % 6]} before ${(i % 5) + 1} pm`; +const lines = (count: number) => + Array.from({ length: count }, (_, i) => line(i, tasks[i % 7]!, days[i % 5]!)).join(". "); const generated = { - varied: `${Array.from({ length: 50 }, (_, i) => line(i, tasks[i % 7]!, days[i % 5]!)).join(". ")}. and finally call ada on monday.`, + varied: `${lines(50)}. and finally call ada on monday.`, repetitive: `${Array.from({ length: 50 }, (_, i) => line(i, tasks[0]!, days[0]!)).join(". ")}.`, + email: `hi team um quick update on the plan for the next two weeks. ${lines(22)}. let me know if any of this does not work for you thanks so much best mateusz`, }; type Fixture = { name: string } & ({ text: string } | { generate: keyof typeof generated }); -type Row = Generation & { name: string; styling: CleanupStyle["styling"] }; +type Row = Required & { name: string; ms: number; generations: Generation[] }; const fixtures: Fixture[] = JSON.parse( readFileSync(join(here, "../fixtures/dictations.json"), "utf8"), @@ -55,12 +56,14 @@ const record = async (): Promise => { await s1.load(); const rows: Row[] = []; for (const fixture of fixtures) { - for (const styling of STYLINGS) { - const t = performance.now(); - const generations = await s1.generate(inputOf(fixture), { styling }); - console.error(`${fixture.name} ${styling} ${Math.round(performance.now() - t)} ms`); - for (const generation of generations) - rows.push({ name: fixture.name, styling, ...generation }); + for (const context of CONTEXTS) { + for (const styling of STYLINGS) { + const t = performance.now(); + const generations = await s1.generate(inputOf(fixture), { styling, context }); + const ms = Math.round(performance.now() - t); + console.error(`${fixture.name} ${styling} ${context} ${ms} ms`); + rows.push({ name: fixture.name, styling, context, ms, generations }); + } } } await s1.dispose(); @@ -68,18 +71,25 @@ const record = async (): Promise => { return rows; }; +let chunks = 0; let rejected = 0; const rows = await record(); -for (const { name, styling, chunk, output, truncated } of rows) { - let verdict = "accept"; - try { - assertPlausibleCleanup(chunk, output, truncated); - } catch (e) { - verdict = `REJECT ${(e as Error).message}`; - rejected++; +for (const { name, styling, context, ms, generations } of rows) { + for (const [i, { chunk, output, truncated }] of generations.entries()) { + let verdict = "accept"; + try { + assertPlausibleCleanup(chunk, output, truncated); + } catch (e) { + verdict = `REJECT ${(e as Error).message}`; + rejected++; + } + chunks++; + const { recall, head, tail } = wordSurvival(chunk, output); + const scores = [recall, head, tail].map((n) => n.toFixed(2)).join("/"); + const part = generations.length > 1 ? ` ${i + 1}/${generations.length}` : ""; + console.log( + `${scores}\t${name}${part}\t${styling}\t${context}\t${ms} ms\t${verdict}\n\t${JSON.stringify(output)}`, + ); } - const { recall, head, tail } = wordSurvival(chunk, output); - const scores = [recall, head, tail].map((n) => n.toFixed(2)).join("/"); - console.log(`${scores}\t${name}\t${styling}\t${verdict}\n\t${JSON.stringify(output)}`); } -console.log(`${rows.length} rows, ${rejected} rejected`); +console.log(`${rows.length} rows, ${chunks} chunks, ${rejected} rejected`);