Skip to Content
Recodocs

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.

10 min read
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.

1
Familiar · 96 invoices0%50%100%Register-layout rules25.0%FP16 prompted14.6%Raw labels87.5%Verified labels99.0%+11.5 pp95% interval −2.1 to +37.5 pp-40-2002040
Novel · 96 invoices0%50%100%Register-layout rules0.0%FP16 prompted1.0%Raw labels49.0%Verified labels57.3%+8.3 pp95% interval −8.3 to +27.1 pp-40-2002040
Independent · 48 invoices0%50%100%Register-layout rules0.0%FP16 prompted12.5%Raw labels64.6%Verified labels54.2%−10.4 pp95% interval −29.2 to +14.6 pp-40-2002040
Source · Tesla T4 experiment · 02-report.json. Differences and 95% intervals derive from matched invoices and family resampling.

Score 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.

Exact(y^i,yi)=1{parse(y^i)=yi},p^s=1ns∑i∈sExact(y^i,yi).\begin{aligned} \mathrm{Exact}(\hat y_i,y_i)&=\mathbf{1}\{\mathrm{parse}(\hat y_i)=y_i\},\\ \widehat p_s&=\frac{1}{n_s}\sum_{i\in s}\mathrm{Exact}(\hat y_i,y_i). \end{aligned}

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
    continue

On 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 gold

One deduplication pass left 192 invoices for both fits

Document counts before deduplication and target counts after it

2

210 visible candidates

Retained
192
Exact duplicates
18

192 retained targets

Unchanged
128
Wrong currency
21
Dropped row
22
Wrong total
21
Source · Tesla T4 experiment · 02-report.json and 02-audit.json. Unchanged targets derive from retained invoices minus audited corrections.

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
register
FamilyKeptEditedUnchanged
train-00826
train-04835
train-08835
train-12835
train-16826
train-20835
memo
FamilyKeptEditedUnchanged
train-01835
train-05835
train-09835
train-13835
train-17826
train-21826
checkout
FamilyKeptEditedUnchanged
train-02826
train-06835
train-10835
train-14835
train-18835
train-22835
ledger
FamilyKeptEditedUnchanged
train-03835
train-07835
train-11835
train-15826
train-19826
train-23826
Familiar
register 24 · memo 24 · checkout 24 · ledger 24
Novel
packing 24 · remittance 24 · service 24 · notice 24
Independent
separate 48
Source · Tesla T4 experiment · 02-report.json and retained lineage in 02-audit.json. Layout groups derive from the retained document ledger.

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}.")
Lupdate=−∑i,tmitlog⁡pθ(yit∣xi,yi,<t)∑i,tmit.\mathcal L_{\rm update} = -\frac{\sum_{i,t}m_{it}\log p_{\theta}(y_{it}\mid x_i,y_{i,<t})} {\sum_{i,t}m_{it}}.

The corrected labels added 402 response tokens to the same update schedule

Tokens presented without padding, training-loop seconds and peak allocated GPU memory

4

Raw 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
Source · Tesla T4 experiment · 02-report.json. Token difference derives from the recorded supervised counts.

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.

Δs,pp=100 ns,fixed−ns,regressedns.\Delta_{s,\rm pp} =100\,\frac{n_{s,\rm fixed}-n_{s,\rm regressed}}{n_s}.

Five more invoices regressed than improved on the independent layouts

The same held-out invoices before and after correcting training targets

5

Familiar · 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
Source · Tesla T4 experiment · Paired exact counts in 02-report.json, checked against 02-predictions.json.

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

6
Raw labelsVerified labels
Familiar · 96 invoices0%50%100%Currency87.5% → 100.0%Printed total100.0% → 100.0%Row F1100.0% → 100.0%Valid schema100.0% → 100.0%
Novel · 96 invoices0%50%100%Currency96.9% → 95.8%Printed total74.0% → 80.2%Row F170.6% → 71.9%Valid schema96.9% → 95.8%
Independent · 48 invoices0%50%100%Currency91.7% → 93.8%Printed total77.1% → 68.8%Row F184.7% → 93.8%Valid schema91.7% → 93.8%
Source · Tesla T4 experiment · Row F1 and validity from 02-report.json. Currency and printed-total rates derive from 02-predictions.json.

On 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.

DecisionEvidence to carry forward
Retain one row per visible invoiceThe same deduplicated roster fed both fits. Keep the pointer from each duplicate to its retained record.
Track the amount and the currency separatelyThe opening label passed the schema with the correct digits and the wrong currency.
Score held-out slices and review failuresThe 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

ItemSetting
ModelQwen2.5-0.5B-Instruct, revision 7ae557604adf67be50417f59c2c2f167def9a775
Datacourse-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.
PromptOne training-only exemplar, SF-898991, and the same prompt format for the prompted baseline and both fits
FitsFP16 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.
OptimiserAdamW at 0.0002, two invoices per update, 96 attempted and 96 completed updates per arm
DecodingGreedy, one beam, cap 384 new tokens, inference batches of up to 16
HardwareOne 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.

  1. Set FAULT_PERIOD = 5 instead of 3. Predict how many retained targets need correction, then compare the ledger and paired exact counts.
  2. In corrupt_record, change the wrong-total offset from += 101 to += 1. Predict how exact checks respond to a one-minor-unit error, then inspect the exact audit and held-out total field scores.
  3. Change the duplicate injection condition from position % 11 == 0 to position % 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