02 · Audit synthetic training data
Check a synthetic invoice against its proposed label, then measure what repairing the training labels changes on held-out invoices.
- Part 1
- Build the data
- Model
Qwen/Qwen2.5-0.5B-Instruct- Data
- Course Invoice v1, visible text with separately stored gold records
- Hardware
- Tesla T4, in Google Colab
Can you approve this label?
You maintain an invoice parser for accounts payable. A proposed training label has passed the schema check and is waiting for your approval. Compare the candidate with the synthetic invoice. If the parser learns to post the payable in GBP, the amount can look right all the way to the ledger while the currency changes.
Synthetic invoice SF-460242
Sample Supplier 6320 billing memo / 2026-03-15 Account invoice SF-460242 [USD] 8 x Door seal @ 232.41 per unit 5 x Grounding clip @ 81.05 per unit 9 x Bench calibration @ 23.19 per unit Total due 2,646.37 including tax 173.13; net amount 2,473.24.
Candidate label · fields shown
{
"currency": "GBP",
"total_minor": 264637
}Would you keep the label, drop the invoice, or correct the label using what the supplier printed?
Check the label against the invoice
Keep the invoice and change the label to USD. Both complete records pass the schema. The raw label stores 264,637 minor units of GBP, while the verified label stores 264,637 cents of USD. The exact record check catches the mismatch by checking the field against the source record.
Synthetic invoice SF-460242
- Printed invoice
- Account invoice SF-460242 [USD]. Total due 2,646.37.
- Raw label
- {"currency":"GBP","total_minor":264637}
- Verified label
- {"currency":"USD","total_minor":264637}
Raw labels · valid schema, wrong currency
{
"invoice_id": "SF-460242",
"issued_on": "2026-03-15",
"supplier": "Sample Supplier 6320",
"currency": "GBP",
"line_items": [
{
"description": "Door seal",
"quantity": 8,
"unit_minor": 23241
},
{
"description": "Grounding clip",
"quantity": 5,
"unit_minor": 8105
},
{
"description": "Bench calibration",
"quantity": 9,
"unit_minor": 2319
}
],
"subtotal_minor": 247324,
"tax_minor": 17313,
"total_minor": 264637
}Verified labels · valid schema, exact record
{
"invoice_id": "SF-460242",
"issued_on": "2026-03-15",
"supplier": "Sample Supplier 6320",
"currency": "USD",
"line_items": [
{
"description": "Door seal",
"quantity": 8,
"unit_minor": 23241
},
{
"description": "Grounding clip",
"quantity": 5,
"unit_minor": 8105
},
{
"description": "Bench calibration",
"quantity": 9,
"unit_minor": 2319
}
],
"subtotal_minor": 247324,
"tax_minor": 17313,
"total_minor": 264637
}The rendered memo and the structured target are two views of one fixture. NVIDIA uses the same kind of pairing for document parsing, where rendered tables and charts carry structured annotations as training targets. NVIDIA reports releasing 1 million synthetic table examples and 9.98 million synthetic chart examples. NVIDIA, company-reported training data
Check target contents even after filtering. Wang et al. report that 58% of 200 sampled Self-Instruct examples had a correct and acceptable output in their expert review after filtering. Here the stored invoice record makes the same kind of check deterministic. Self-Instruct, paper-reported Table 2
Exact scores rose in two slices and fell in one
Complete-record accuracy and paired change in percentage points (pp). Every 95% interval includes zero.
1Score the whole invoice
An exact record has every field and every line item right, in the original line-item order. Parsing the JSON makes whitespace and object key order immaterial. Familiar layouts appeared in training with different suppliers. Novel layouts were held out entirely. Independent invoices use a separate synthetic rendering branch and a different set of suppliers.
Here is novel invoice SF-797533. Register-layout rules returned no record because the source uses the packing layout. FP16 prompted got all seven scalar fields right and returned an empty line-item list. Raw labels recovered two items. Verified labels included the missing packing insert and matched the full record.
Synthetic invoice SF-797533 · Novel
Billing details / SF-797533 Sold by Sample Supplier 3177 Document date 2026-06-15 Invoice currency USD Balance payable 1,877.28 Packing insert: 78.89 each for 8 units Cooling filter: 142.13 each for 7 units Rack inspection: 32.11 each for 4 units Merchandise 1,754.47 Tax 122.81
SF-797533 · held-out record
- Reference
- {"invoice_id":"SF-797533","issued_on":"2026-06-15","supplier":"Sample Supplier 3177","currency":"USD","line_items":[{"description":"Packing insert","quantity":8,"unit_minor":7889},{"description":"Cooling filter","quantity":7,"unit_minor":14213},{"description":"Rack inspection","quantity":4,"unit_minor":3211}],"subtotal_minor":175447,"tax_minor":12281,"total_minor":187728}
- Register-layout rules
- null
- FP16 prompted
- {"invoice_id":"SF-797533","issued_on":"2026-06-15","supplier":"Sample Supplier 3177","currency":"USD","line_items":[],"subtotal_minor":175447,"tax_minor":12281,"total_minor":187728}
- Raw labels
- {"invoice_id":"SF-797533","issued_on":"2026-06-15","supplier":"Sample Supplier 3177","currency":"USD","line_items":[{"description":"Cooling filter","quantity":7,"unit_minor":14213},{"description":"Rack inspection","quantity":4,"unit_minor":3211}],"subtotal_minor":175447,"tax_minor":12281,"total_minor":187728}
- Verified labels
- {"invoice_id":"SF-797533","issued_on":"2026-06-15","supplier":"Sample Supplier 3177","currency":"USD","line_items":[{"description":"Packing insert","quantity":8,"unit_minor":7889},{"description":"Cooling filter","quantity":7,"unit_minor":14213},{"description":"Rack inspection","quantity":4,"unit_minor":3211}],"subtotal_minor":175447,"tax_minor":12281,"total_minor":187728}
Register-layout rules extracted 24 of 96 familiar invoices and none of the novel or independent invoices. On novel invoices FP16 prompted got 1 of 96 complete records right, compared with 47 of 96 for Raw labels and 55 of 96 for Verified labels. All four methods share the same evaluation roster. Per-invoice predictions
Audit the candidate pool first
Synthetic labels are proposed training examples, not evidence of correctness. Check them against the invoice before they teach the model, and count what actually survives the audit.
The generator introduces three known faults in otherwise valid labels. It swaps currency, removes a line item, or changes the total by 101 minor units. A family offset spreads those faults across the training families. The deduplication pass uses the visible document hash to retain one entry per invoice. Both adapters then receive the same retained invoices in the same order.
first = seen.setdefault(digest, position)
if first != position:
detail["disposition"] = "duplicate"
reasons[DUPLICATE] += 1
continueOn the retained document, compare the candidate label with the fixture. Raw labels keeps the candidate as supplied. Verified labels uses the source record when a check fails.
observed = score_record(candidate, row)
exact = observed["exact"]
corrected = candidate if exact else goldOne deduplication pass left 192 invoices for both fits
Document counts before deduplication and target counts after it
2210 visible candidates
- Retained
- 192
- Exact duplicates
- 18
192 retained targets
- Unchanged
- 128
- Wrong currency
- 21
- Dropped row
- 22
- Wrong total
- 21
The ledger records 210 candidates, 18 exact copies, 192 retained inputs and 64 corrected labels. Follow the opening memo through the ledger. Candidates 1 and 2 contain the same visible invoice. Candidate 1 supplies one raw target with the currency fault and one verified target with the correction.
SF-460242 · candidate ledger
- Candidate 1
- kept_candidate: 1 · corrected · visible SHA-256 11773c86b9da4c3b0fbd9c5e6f5553bedba6dad2db9ed247281b9247cdff1210
- Candidate 2
- kept_candidate: 1 · duplicate · visible SHA-256 11773c86b9da4c3b0fbd9c5e6f5553bedba6dad2db9ed247281b9247cdff1210
The two entries hash the same visible invoice. Candidate 2 points to the retained document rather than contributing another update.
In production, record both overlap with held-out data and duplicate frequency inside training. For Tülu 3, Ai2 reports removing 3.5% of Evol CodeAlpaca prompts against HumanEval and 11.3% of NuminaMath-TIR prompts against MATH. Those filters protected evaluation. An internal duplicate check controls repeated training exposure. Tülu 3, paper-reported Table 8
Exact hashes find copies of the same visible text. Meta's Llama 3 recipe also clustered dialogues and used cosine similarity to prune near-duplicates within its curated training data. That provides a route for catching changes in wording or formatting that a document hash misses. Llama 3 report, sections 4.2.2–4.2.3
Every training family contributed eight invoices and at least two corrections
Kept, edited and unchanged training documents by layout and supplier family
3| Family | Kept | Edited | Unchanged |
|---|---|---|---|
| train-00 | 8 | 2 | 6 |
| train-04 | 8 | 3 | 5 |
| train-08 | 8 | 3 | 5 |
| train-12 | 8 | 3 | 5 |
| train-16 | 8 | 2 | 6 |
| train-20 | 8 | 3 | 5 |
| Family | Kept | Edited | Unchanged |
|---|---|---|---|
| train-01 | 8 | 3 | 5 |
| train-05 | 8 | 3 | 5 |
| train-09 | 8 | 3 | 5 |
| train-13 | 8 | 3 | 5 |
| train-17 | 8 | 2 | 6 |
| train-21 | 8 | 2 | 6 |
| Family | Kept | Edited | Unchanged |
|---|---|---|---|
| train-02 | 8 | 2 | 6 |
| train-06 | 8 | 3 | 5 |
| train-10 | 8 | 3 | 5 |
| train-14 | 8 | 3 | 5 |
| train-18 | 8 | 3 | 5 |
| train-22 | 8 | 3 | 5 |
| Family | Kept | Edited | Unchanged |
|---|---|---|---|
| train-03 | 8 | 3 | 5 |
| train-07 | 8 | 3 | 5 |
| train-11 | 8 | 3 | 5 |
| train-15 | 8 | 2 | 6 |
| train-19 | 8 | 2 | 6 |
| train-23 | 8 | 2 | 6 |
- Familiar
- register 24 · memo 24 · checkout 24 · ledger 24
- Novel
- packing 24 · remittance 24 · service 24 · notice 24
- Independent
- separate 48
The notebook asserts unique invoice IDs and visible hashes across the catalogue, with disjoint supplier and family IDs across splits. A training-only exemplar is excluded from both training rosters and reused at prompt time. Only the familiar evaluation slice shares layouts with training. Keeping the release split separate leaves a fresh check for a deployment decision.
Count what the optimiser sees
Both fits start from identical adapter weights and see 79,312 unpadded prompt tokens over 96 updates. When a repair restores a missing row, it adds tokens to the response. On synthetic invoice SF-397858, the raw target leaves out eight Carrier adjustment units. The verified target restores that line. The money totals were already present in both records.
Synthetic invoice SF-397858
Sample Supplier 3103 billing memo / 2026-01-26 Account invoice SF-397858 [EUR] 5 x Cooling filter @ 86,87 per unit 8 x Carrier adjustment @ 11,72 per unit Total due 597,77 including tax 68,65; net amount 528,11.
Raw labels · line_items only
[
{
"description": "Cooling filter",
"quantity": 5,
"unit_minor": 8687
}
]Verified labels · line_items only
[
{
"description": "Cooling filter",
"quantity": 5,
"unit_minor": 8687
},
{
"description": "Carrier adjustment",
"quantity": 8,
"unit_minor": 1172
}
]The notebook checks the completion mask against the separate response tokenisation. Prompt and padding positions are assigned label -100 and ignored by cross-entropy. Response positions, including the end marker, contribute to the average loss over active tokens in each update.
if example.completion_mask != [0] * len(prompt) + [1] * len(response):
raise AssertionError(f"Unexpected response mask for {invoice.key}.")The corrected labels added 402 response tokens to the same update schedule
Tokens presented without padding, training-loop seconds and peak allocated GPU memory
4Raw labels
192 invoices · 96 updates · 100,288 tokens
- Prompt tokens
- 79,312
- Supervised tokens
- 20,976
- Training loop
- 26.89 s
- Peak allocated
- 4.13 GiB
Verified labels
192 invoices · 96 updates · 100,690 tokens
- Prompt tokens
- 79,312
- Supervised tokens
- 21,378
- Training loop
- 31.99 s
- Peak allocated
- 4.13 GiB
Verified labels supervised 21,378 response tokens against 20,976 for Raw labels, an increase of 402 tokens. Correcting targets can change supervision even when documents and updates match. The comparison measures the practical choice to train on corrected targets, including their changed response lengths. Each fit ran once, so the time difference is a single measurement.
Check which invoices switched
Familiar exact increased from 84 of 96 to 95 of 96, a gain of 11.5 points. Novel exact increased from 47 of 96 to 55 of 96, a gain of 8.3 points. Independent exact dropped from 31 of 48 to 26 of 48, a loss of 10.4 points. A fixed invoice is wrong under Raw labels and exact under Verified labels. A regression goes the other way.
Five more invoices regressed than improved on the independent layouts
The same held-out invoices before and after correcting training targets
5Familiar · 96 invoices
- Fixed
- 12
- Regressed
- 1
- Both exact
- 83
- Both wrong
- 0
Novel · 96 invoices
- Fixed
- 15
- Regressed
- 7
- Both exact
- 40
- Both wrong
- 34
Independent · 48 invoices
- Fixed
- 6
- Regressed
- 11
- Both exact
- 20
- Both wrong
- 11
On novel remittance SF-781239, the printed balance is GBP 728.51, net charges are 644.70 and tax is 83.81. Raw labels extracted all three correctly. Verified labels put the balance in the subtotal field and repeated the net charges in both tax and total. Both outputs passed the schema and contained the correct item.
Synthetic invoice SF-781239 · Novel
Remittance advice for SF-781239 (GBP) Sample Supplier 3219 / Document issued 2025-11-12 Pay this amount 728.51 5 x Packing insert @ 128.94 per unit Net charges 644.70 / Tax 83.81
SF-781239 · held-out record
- Reference
- {"invoice_id":"SF-781239","issued_on":"2025-11-12","supplier":"Sample Supplier 3219","currency":"GBP","line_items":[{"description":"Packing insert","quantity":5,"unit_minor":12894}],"subtotal_minor":64470,"tax_minor":8381,"total_minor":72851}
- Raw labels
- {"invoice_id":"SF-781239","issued_on":"2025-11-12","supplier":"Sample Supplier 3219","currency":"GBP","line_items":[{"description":"Packing insert","quantity":5,"unit_minor":12894}],"subtotal_minor":64470,"tax_minor":8381,"total_minor":72851}
- Verified labels
- {"invoice_id":"SF-781239","issued_on":"2025-11-12","supplier":"Sample Supplier 3219","currency":"GBP","line_items":[{"description":"Packing insert","quantity":5,"unit_minor":12894}],"subtotal_minor":72851,"tax_minor":64470,"total_minor":64470}
Estimate uncertainty by resampling whole supplier families within each split. Each draw retains every paired invoice from a sampled family. The 95% intervals in Figure 1 come from 1,000 draws over eight familiar families, eight novel families and four independent families. Each interval crosses zero, so these data leave the direction uncertain for every slice. The intervals reflect the sampled families with a single fitted seed.
Separate item accuracy from record accuracy
Each field rate divides the count of correct values by all invoices in a slice. Invalid records count as incorrect for individual fields. Row F1 separately compares line items by description, quantity and unit price, and is averaged over invoices. A parser can therefore improve line items and still lose complete records on the same documents.
Independent row F1 improved as complete-record accuracy fell
Share of all invoices with each field or valid schema, and mean per-invoice row F1
6On independent invoice SF-826464, both adapters found the mounting plate, quantity nine, at GBP 93.81 per unit. Verified labels moved the printed gross of 954.05 into the subtotal field and returned a null total. Both outputs scored 1.0 on row F1. Only Raw labels matched the complete record. Across the independent slice, mean row F1 moved from 84.7% to 93.8% while exact records moved from 64.6% to 54.2%.
Synthetic invoice SF-826464 · Independent
Document SF-826464 Biller Sample Supplier 2524 / As of 2026-02-07 / GBP 9 x Mounting plate @ 93.81 per unit Gross 954.05 Breakdown: net 844.29 and taxes 109.76.
SF-826464 · held-out record
- Reference
- {"invoice_id":"SF-826464","issued_on":"2026-02-07","supplier":"Sample Supplier 2524","currency":"GBP","line_items":[{"description":"Mounting plate","quantity":9,"unit_minor":9381}],"subtotal_minor":84429,"tax_minor":10976,"total_minor":95405}
- Raw labels
- {"invoice_id":"SF-826464","issued_on":"2026-02-07","supplier":"Sample Supplier 2524","currency":"GBP","line_items":[{"description":"Mounting plate","quantity":9,"unit_minor":9381}],"subtotal_minor":84429,"tax_minor":10976,"total_minor":95405}
- Verified labels
- {"invoice_id":"SF-826464","issued_on":"2026-02-07","supplier":"Sample Supplier 2524","currency":"GBP","line_items":[{"description":"Mounting plate","quantity":9,"unit_minor":9381}],"subtotal_minor":95405,"tax_minor":10976,"total_minor":null}
What to keep
Keep the source-backed currency repair for SF-460242. Audit all proposed labels against the invoice when a reliable reference exists. Preserve the candidate, the hash of the displayed invoice, and the reason for each correction so you can repeat the audit.
| Decision | Evidence to carry forward |
|---|---|
| Retain one row per visible invoice | The same deduplicated roster fed both fits. Keep the pointer from each duplicate to its retained record. |
| Track the amount and the currency separately | The opening label passed the schema with the correct digits and the wrong currency. |
| Score held-out slices and review failures | The directions differed across slices and all paired intervals crossed zero. Inspect another seed and protect the release set before selecting a model. |
- Compare against the visible invoice. Check SF-460242’s currency marker as well as the amount. A label can have the right digits and still send the wrong payment instruction.
- Keep the original beside the repair. Record the exact field you changed and the source that justifies it so the correction is reviewable.
- Deduplicate before sampling. Give both fits the same visible invoice roster and preserve a pointer from each duplicate to the retained example.
- Count the tokens that carry loss. Equal row and update counts describe the fit budget. The exposure table shows how much target text each fit actually learnt from.
- Read paired moves by layout. Check the gained and lost invoices on each slice before choosing an adapter. An average can hide opposing changes.
- Next to try, not tested here: Repeat the matched fits with another seed and compare the raw failures before opening the reserved release set.
How it was built
| Item | Setting |
|---|---|
| Model | Qwen2.5-0.5B-Instruct, revision 7ae557604adf67be50417f59c2c2f167def9a775 |
| Data | course-invoice-v1 synthetic fixtures. Catalogue counts were 576 train, 72 development, 96 familiar, 96 novel, 48 independent and 120 release. The fit selected 192 distinct training invoices. |
| Prompt | One training-only exemplar, SF-898991, and the same prompt format for the prompted baseline and both fits |
| Fits | FP16 base with LoRA rank 8 and alpha 16 on q_proj and v_proj. Dropout 0. Each arm trained 540,672 adapter parameters from the same initial weights with seed 42. |
| Optimiser | AdamW at 0.0002, two invoices per update, 96 attempted and 96 completed updates per arm |
| Decoding | Greedy, one beam, cap 384 new tokens, inference batches of up to 16 |
| Hardware | One Tesla T4. PyTorch 2.14.1+cu130, Transformers 4.51.3, PEFT 0.15.2 and Accelerate 1.6.0. |
The notebook measured 26.89 s for Raw labels and 31.99 s for Verified labels. The timer surrounds the synchronised update loop. It excludes model loading, evaluation and saving. Peak allocated memory includes the model already resident on the GPU and the peak PyTorch allocations during the loop. The notebook runner measured 626.11 s across setup, both fits, evaluation and saving.
The notebook adapts the Apache-2.0 prompt and completion masking approach from the Together Computer Post-Training Cookbook and fits locally with PyTorch. The report records the held-out roster hash and both adapter hashes. Pinned Qwen checkpoint · Pinned cookbook
Executed notebook · Score and budget report · All predictions · Source documents and audit ledger
Run it yourself
Use one Tesla T4 for both fits. Start with Can a valid record still be wrong? to check the opening memo. Why keep two records for one invoice? prints the audits and training plan used in Figures 2 and 3. Which exposure differs between branches? runs the two fits used in Figure 4. Did the corrections transfer? saves the scores, paired outcomes and raw outputs used in Figures 1, 5 and 6.
Change one line at a time and predict the effect before running it. Keep the seed and evaluation roster fixed so you can compare with the supplied result.
- Set
FAULT_PERIOD = 5instead of 3. Predict how many retained targets need correction, then compare the ledger and paired exact counts. - In
corrupt_record, change the wrong-total offset from+= 101to+= 1. Predict how exact checks respond to a one-minor-unit error, then inspect the exact audit and held-out total field scores. - Change the duplicate injection condition from
position % 11 == 0toposition % 7 == 0. Predict which ledger counts move, then check whether the retained roster and token exposure stay the same.
Continue to Lesson 03 · Audit preference pairs to check whether a preference label rewards the right completion.
How is this page?
Last updated on