|
| 1 | +# Prompt for `improve/02-strict-eval-e03-e04-e05` |
| 2 | + |
| 3 | +Copy this into a new chat to re-run E03/E04/E05 against the cleaned dataset |
| 4 | ++ strict evaluator. Measurement-only — no prompt iteration. All three |
| 5 | +experiments go on one branch (`improve/02-...`). |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +Start a new improvement-iteration branch off the current tip of |
| 10 | +`improve/01-strict-eval-and-mistral-tune`. The cross-experiment |
| 11 | +infrastructure landed on `improve/01` is complete: strict evaluator |
| 12 | +(`apps/shared/prisma/seed.ts:2044-2062`), one-of GT array support |
| 13 | +(`apps/temporal/src/evaluators/schema-aware-evaluator.ts`), dataset move |
| 14 | +from `samples-mix/private` → `public`, GT format-variant promotions on |
| 15 | +sin/date/phone, and helper scripts in `apps/temporal/src/scripts/`. E02 |
| 16 | +is at canonical pass_rate 0.925 / f1.median 0.972 / matchedFields.median |
| 17 | +69 of 74 — strongest result on record for E02. |
| 18 | + |
| 19 | +This phase re-runs E03, E04, and E05 against the same cleaned-GT + |
| 20 | +strict-rule state so the cross-experiment table reflects strict |
| 21 | +metrics for all five engines. Measurement-only — no prompt iteration. |
| 22 | + |
| 23 | +BRANCH: create `improve/02-strict-eval-e03-e04-e05` from |
| 24 | +`improve/01-strict-eval-and-mistral-tune` (NOT from main — we want |
| 25 | +every E01-E05 provider + the improve/01 evaluator + dataset changes). |
| 26 | +Naming continues the `improve/<NN>-<short-desc>` convention so future |
| 27 | +improve branches stack. |
| 28 | + |
| 29 | +START BY READING (in this order): |
| 30 | + |
| 31 | +1. `experiments/results/02-mistral-doc-ai-azure/SUMMARY.md` — the |
| 32 | + "## Strict-equality re-evaluation + improvement loop (improve/01)" |
| 33 | + section establishes the methodology and the canonical pre/post |
| 34 | + comparison table. |
| 35 | +2. `experiments/POST_BENCHMARK_FOLLOWUPS.md` item 1 — the cross- |
| 36 | + experiment rollout plan; this branch handles E03/E04/E05. |
| 37 | +3. `experiments/results/05-vlm-ocr-hybrid/SUMMARY.md` cross-experiment |
| 38 | + table — the source of truth for cross-engine numbers. You'll update |
| 39 | + E03/E04/E05 rows here at the end. |
| 40 | +4. `experiments/results/02-mistral-doc-ai-azure/iteration/CHANGELOG.md` |
| 41 | + round-3 and round-5 entries — engine-ceiling diagnosis pattern. E03 |
| 42 | + also uses a Foundry deployment (Azure Content Understanding, not |
| 43 | + Mistral Document AI) — keep an eye on whether CU's annotation pass |
| 44 | + has the same OCR-markdown-only limitation that the Mistral SKU has. |
| 45 | +5. `apps/temporal/src/scripts/` — note the helper scripts available: |
| 46 | + - `trigger-experiment-benchmark.ts <slug>` — POSTs the run, returns |
| 47 | + the run id. Loads `TEST_API_KEY` from env without leaking it. |
| 48 | + - `poll-experiment-run.ts <runId> <slug>` — polls until terminal and |
| 49 | + writes `experiments/results/<slug>/benchmark-run.json`. |
| 50 | + - `dump-errors-for-gt-cleanup.ts <slug>` — generates the per-sample |
| 51 | + mismatch table at `experiments/results/<slug>/iteration/errors-for-gt-cleanup.md`. |
| 52 | + Supports `--known-hard "id1,id2"` (defaults to `"81 blank,81 coffee"`). |
| 53 | + - `promote-gt-format-variants.ts <slug> [--write]` — auto-promotes |
| 54 | + sin/date/phone GT scalars to one-of arrays where the engine reads |
| 55 | + form-as-written. Dry-run by default. |
| 56 | + - `setup-cu-defaults.ts` — one-time CU defaults patch (E03 only). |
| 57 | + - `preflight-vlm.ts <deployment>` — checks env + 1×1 PNG strict-mode |
| 58 | + round-trip (E04). |
| 59 | + - `preflight-hybrid.ts <deployment>` — same plus Azure DI probe (E05). |
| 60 | +6. `apps/temporal/src/evaluators/schema-aware-evaluator.ts` — note the |
| 61 | + evaluator now accepts arrays as GT values (any-match across one-of |
| 62 | + alternates). All five matching rules support it. |
| 63 | +7. `data/datasets/samples-mix/public/` — the cleaned dataset. |
| 64 | + `sin` / `spouse_sin` / `date` / `spouse_date` / `phone` / |
| 65 | + `spouse_phone` GTs for 23 samples are already one-of arrays |
| 66 | + accepting Mistral's form-as-written variants. E03/E04/E05 may |
| 67 | + produce DIFFERENT format variants (CU and gpt-5.4 may normalise |
| 68 | + differently than Mistral); `promote-gt-format-variants.ts` is the |
| 69 | + tool to absorb those too if they show up. |
| 70 | + |
| 71 | +PREREQUISITES (confirm at session start): |
| 72 | + |
| 73 | +- Backend running with the cleaned dataset uploaded to blob storage. |
| 74 | + If the backend has been restarted since `improve/01` landed but |
| 75 | + WITHOUT `FORCE_RESYNC_LOCAL_DATASETS=true`, the |
| 76 | + `samples-mix-public` prefix may not be on blob storage yet — the |
| 77 | + first benchmark trigger will fail at materialization. Recovery: |
| 78 | + restart backend once with `FORCE_RESYNC_LOCAL_DATASETS=true` on |
| 79 | + the env, drop the env var on the next boot. |
| 80 | +- Azure deployments still live from previous work: |
| 81 | + - `gpt-5.2` capacity 100 (E03) |
| 82 | + - `gpt-5.4` capacity 100 (E04 + E05) |
| 83 | + - `text-embedding-3-large` (E03) |
| 84 | + - Azure DI resource (E05) |
| 85 | + - CU defaults patched (E03 — run `setup-cu-defaults.ts` if you've |
| 86 | + rotated the resource) |
| 87 | +- TEST_API_KEY auto-loaded by trigger script from |
| 88 | + `apps/backend-services/.env` (or the override file). Don't read |
| 89 | + the value yourself; the script handles it. |
| 90 | + |
| 91 | +KNOWN-HARD SAMPLES (treat as floor, not signal): |
| 92 | +- `"81 blank"` and `"81 coffee"` are low-resolution / obscured forms. |
| 93 | + Every engine in the stack scores poorly on them. Mistakes are |
| 94 | + EXPECTED. The `dump-errors-for-gt-cleanup.ts` script tags them |
| 95 | + ⚠️ KNOWN-HARD by default. Document any movement on these samples |
| 96 | + but don't iterate against them. |
| 97 | + |
| 98 | +PER-EXPERIMENT FLOW (run independently; each is ~5-30 min wallclock): |
| 99 | + |
| 100 | +### E03 — Azure Content Understanding + gpt-5.2 |
| 101 | + |
| 102 | +```bash |
| 103 | +# Optional pre-flight (only needed if CU resource was rotated since |
| 104 | +# the fuzzy-era canonical run); script is idempotent: |
| 105 | +cd apps/temporal |
| 106 | +npx tsx -r tsconfig-paths/register src/scripts/setup-cu-defaults.ts |
| 107 | + |
| 108 | +# Trigger: |
| 109 | +npx tsx -r tsconfig-paths/register \ |
| 110 | + src/scripts/trigger-experiment-benchmark.ts 03 |
| 111 | +# → captures run id |
| 112 | + |
| 113 | +# Poll (~15-30 min wallclock; gpt-5.2 generative is the bottleneck): |
| 114 | +npx tsx -r tsconfig-paths/register \ |
| 115 | + src/scripts/poll-experiment-run.ts <runId> 03-content-understanding |
| 116 | +# → writes experiments/results/03-content-understanding/benchmark-run.json |
| 117 | + |
| 118 | +# Errors file for GT cleanup review: |
| 119 | +npx tsx -r tsconfig-paths/register \ |
| 120 | + src/scripts/dump-errors-for-gt-cleanup.ts 03-content-understanding |
| 121 | +``` |
| 122 | + |
| 123 | +If the errors file lists ≥ 10 sin/date/phone format-variant mismatches, |
| 124 | +run `promote-gt-format-variants.ts 03-content-understanding` (dry-run |
| 125 | +first). If the proposals look right, apply with `--write` and re-run |
| 126 | +the benchmark — that's one extra paid run but locks in the format |
| 127 | +recovery. Promotions are idempotent + deduped against E02's existing |
| 128 | +one-of arrays. |
| 129 | + |
| 130 | +### E04 — gpt-5.4 VLM-direct |
| 131 | + |
| 132 | +```bash |
| 133 | +# Pre-flight: |
| 134 | +cd apps/temporal |
| 135 | +npx tsx -r tsconfig-paths/register \ |
| 136 | + src/scripts/preflight-vlm.ts gpt-5.4 |
| 137 | + |
| 138 | +# Trigger + poll (~6-10 min wallclock): |
| 139 | +npx tsx -r tsconfig-paths/register \ |
| 140 | + src/scripts/trigger-experiment-benchmark.ts 04 |
| 141 | +npx tsx -r tsconfig-paths/register \ |
| 142 | + src/scripts/poll-experiment-run.ts <runId> 04-vlm-direct |
| 143 | + |
| 144 | +# Errors: |
| 145 | +npx tsx -r tsconfig-paths/register \ |
| 146 | + src/scripts/dump-errors-for-gt-cleanup.ts 04-vlm-direct |
| 147 | +``` |
| 148 | + |
| 149 | +Same conditional promote-GT step as E03. |
| 150 | + |
| 151 | +### E05 — gpt-5.4 VLM + OCR hybrid |
| 152 | + |
| 153 | +```bash |
| 154 | +# Pre-flight: |
| 155 | +cd apps/temporal |
| 156 | +npx tsx -r tsconfig-paths/register \ |
| 157 | + src/scripts/preflight-hybrid.ts gpt-5.4 |
| 158 | + |
| 159 | +# Trigger + poll (~5-10 min wallclock; 4:33 was the fuzzy-era run): |
| 160 | +npx tsx -r tsconfig-paths/register \ |
| 161 | + src/scripts/trigger-experiment-benchmark.ts 05 |
| 162 | +npx tsx -r tsconfig-paths/register \ |
| 163 | + src/scripts/poll-experiment-run.ts <runId> 05-vlm-ocr-hybrid |
| 164 | + |
| 165 | +# Errors: |
| 166 | +npx tsx -r tsconfig-paths/register \ |
| 167 | + src/scripts/dump-errors-for-gt-cleanup.ts 05-vlm-ocr-hybrid |
| 168 | +``` |
| 169 | + |
| 170 | +Same conditional promote-GT step. |
| 171 | + |
| 172 | +WHAT TO UPDATE per experiment: |
| 173 | + |
| 174 | +1. **`experiments/results/<slug>/benchmark-run.json`** — overwritten by |
| 175 | + the poll script. |
| 176 | +2. **`experiments/results/<slug>/iteration/errors-for-gt-cleanup.md`** — |
| 177 | + generated by `dump-errors-for-gt-cleanup.ts`. |
| 178 | +3. **`experiments/results/<slug>/SUMMARY.md`** — add a section |
| 179 | + `## Strict-equality re-evaluation (improve/02)` near the top |
| 180 | + (mirror E02 SUMMARY's structure). Include: |
| 181 | + - Run id of the canonical strict run. |
| 182 | + - The 3-column comparison table: |
| 183 | + `| | Fuzzy@0.85 (historical) | Strict (no GT cleanup) | Strict + GT cleanup (canonical) |` |
| 184 | + ... pass_rate, f1.median, f1.mean, precision.mean, recall.mean, |
| 185 | + matchedFields.median, falsePositives.mean. |
| 186 | + - One-paragraph retrospective: which samples regressed under strict, |
| 187 | + whether GT cleanup absorbed format variants (and how many), any |
| 188 | + engine-specific quirks surfaced. |
| 189 | + - If GT cleanup happened, list the format-variant categories absorbed |
| 190 | + (e.g. "CU normalises SINs with hyphens — 12 sin/spouse_sin |
| 191 | + promotions added"). |
| 192 | +4. **Cross-experiment table in `experiments/results/05-vlm-ocr-hybrid/SUMMARY.md`** |
| 193 | + — once all three are done, replace E03/E04/E05 column metrics with |
| 194 | + the new strict numbers. Drop the per-row `(fuzzy)` tag. Update the |
| 195 | + footnote to reflect that all 5 engines are now strict-evaluated. |
| 196 | + Note which engine benefited most from GT cleanup if there's a |
| 197 | + clear winner. |
| 198 | + |
| 199 | +WHAT NOT TO DO: |
| 200 | + |
| 201 | +- Don't change `apps/shared/prisma/seed.ts` evaluator config (already |
| 202 | + `exact` on improve/01). |
| 203 | +- Don't change the workflow JSONs except for the `targetLocalDataset` |
| 204 | + if it doesn't already point at `samples-mix-public` (it should — the |
| 205 | + `improve/01` rename touched all 5). |
| 206 | +- Don't change the workflow JSONs' `parameters.documentAnnotationPrompt` |
| 207 | + / `parameters.fieldDescriptions` / equivalent CU analyzer config. |
| 208 | + This branch is measurement-only — no prompt iteration. |
| 209 | +- Don't run paid benchmarks on E01 or E02 (out of scope here). |
| 210 | +- Don't run paid benchmarks per format-variant change — measure once, |
| 211 | + promote GT if obvious, re-measure once. Cost-discipline. |
| 212 | + |
| 213 | +COST EXPECTATION: |
| 214 | + |
| 215 | +- E03 (gpt-5.2 generative on 40 samples): ~$3-5 per run |
| 216 | +- E04 (gpt-5.4 vision on 40): ~$1-2 per run |
| 217 | +- E05 (gpt-5.4 vision + DI on 40): ~$1-2 per run |
| 218 | +- Worst case (each engine needs a second post-promotion run): $10-18 |
| 219 | + total. Plan accordingly. |
| 220 | + |
| 221 | +CONVERGENCE (done when): |
| 222 | + |
| 223 | +- `benchmark-run.json` from this branch exists for E03, E04, E05. |
| 224 | +- Each has a "Strict-equality re-evaluation (improve/02)" section in |
| 225 | + its SUMMARY.md with the comparison table + retrospective. |
| 226 | +- Each has `iteration/errors-for-gt-cleanup.md` generated. |
| 227 | +- E05 cross-experiment table is updated for all 5 engines strict. |
| 228 | +- Tests pass (CI=true): `cd apps/temporal && npx jest src/experiment-03 src/experiment-04 src/experiment-05 src/ocr-providers/azure-content-understanding src/ocr-providers/vlm-direct src/ocr-providers/vlm-ocr-hybrid`. |
| 229 | +- Lint + tsc clean (pre-commit hooks gate this). |
| 230 | +- Commits on `improve/02-strict-eval-e03-e04-e05`. One commit per |
| 231 | + experiment is fine, OR a single bundled commit per the |
| 232 | + "all-on-one-branch" framing. Final cross-experiment-table commit |
| 233 | + at the end. |
| 234 | + |
| 235 | +REPORT BACK AT END: |
| 236 | + |
| 237 | +- Per-experiment delta vs fuzzy-era (one line each). |
| 238 | +- Updated cross-experiment table (paste it). |
| 239 | +- Total cost spent (rough). |
| 240 | +- Any engine that hit a similar Foundry-style ceiling to Mistral |
| 241 | + (E03 in particular — CU's annotation pass on Foundry could have |
| 242 | + the same OCR-markdown-only limitation). |
| 243 | +- Whether any of E03/E04/E05 now beat E02 on the cleaned-GT |
| 244 | + strict numbers. |
0 commit comments