03 · Audit preference pairs
Check which invoice record the source supports, then see whether a preference-trained parser can write that record from scratch.
- Part 2
- Compare training stages
- Model
Qwen/Qwen2.5-0.5B-Instruct- Data
- Course Invoice v1, visible text with separately stored gold records
- Hardware
- Tesla T4, in Google Colab
You review examples that teach an accounts-payable parser. Both candidates below pass the JSON schema and differ by one penny. Your extraction contract says to record the printed payable amount. Which candidate should the parser learn to prefer?
Course Invoice v1 · Synthetic document
Remittance advice for SF-235300 (GBP) Sample Supplier 3219 / Document issued 2025-02-20 Pay this amount 1,243.11 8 x Rack inspection @ 137.40 per unit Net charges 1,099.20 / Tax 142.90
Two candidates for the same printed remittance
- Candidate A
- {"currency":"GBP","total_minor":124311}
- Candidate B
- {"currency":"GBP","total_minor":124310}
Excerpt. Both full candidates carry the same supplier, date, invoice ID, lines, subtotal and tax.
Check the label against the document
Choose A. The remittance prints GBP 1,243.11, so the total field holds 124,311 pence. The net and tax add to GBP 1,242.10. A separate reconciliation step would flag the GBP 1.01 gap. The extraction score checks the printed amount.
Complete candidates for SF-235300
- A · Verified
- {"invoice_id":"SF-235300","issued_on":"2025-02-20","supplier":"Sample Supplier 3219","currency":"GBP","line_items":[{"description":"Rack inspection","quantity":8,"unit_minor":13740}],"subtotal_minor":109920,"tax_minor":14290,"total_minor":124311}
- B · Counterexample
- {"invoice_id":"SF-235300","issued_on":"2025-02-20","supplier":"Sample Supplier 3219","currency":"GBP","line_items":[{"description":"Rack inspection","quantity":8,"unit_minor":13740}],"subtotal_minor":109920,"tax_minor":14290,"total_minor":124310}
All three arms rank every pair correctly. Their generated records differ.
Two tests on the same 240 held-out invoices. Higher is better.
1Verified candidate ranked first
Checked − flipped: 0.0 pp · 95% interval 0.0 to 0.0 pp
Exact greedy invoice record
Checked − flipped: −6.3 pp · 95% interval −11.3 to −2.1 pp
How to construct the pair
A preference example is a comparison under one shared input. The label should turn on a defensible difference in task quality, not superficial differences in style or formatting.
The remittance pair is held out. Its two candidates share a 396-token prompt and both have 94 response positions, including the end-of-sequence token (EOS). The notebook builds a verified record from each fixture, tries a single scalar change and takes the first candidate that passes its checks. It tries the total first, then tax, subtotal and currency. Equal prompt tokens, response lengths and response masks keep the comparison focused on the content. The scorer checks that the altered scalar is the only wrong field and that every line item stays intact.
# The candidate must be well formed and wrong in exactly one scalar field.
check = score_record(corrupted_text, invoice)
wrong_fields = {key for key, correct in check["field_correct"].items() if not correct}
if not check["valid"] or wrong_fields != {field} or check["row_f1"] != 1:
raise ValueError("A rejected candidate must change exactly one verified scalar.")Course Invoice v1 · Synthetic document
SF-720523 / supplier Sample Supplier 6653 Date of issue 2026-01-30 / All amounts USD Cable sleeve: 37.14 each for 7 units Bench calibration: 150.25 each for 7 units Mounting plate: 59.62 each for 2 units Net 1,430.97 Sales tax 100.17 Payable 1,531.14
The same two candidates receive opposite labels
- Checked DPO
- Chosen total_minor 153114 · Rejected total_minor 153110
- Flipped-label DPO
- Chosen total_minor 153110 · Rejected total_minor 153114
Each completion has 130 tokens including EOS, following the same 429-token prompt.
This training example appears in both branches. The verifier supports 153,114 cents. The flipped branch assigns the chosen label to 153,110 cents. The held-out verifier keeps its original labels for both branches.
Every training counterexample changes the payable total
Accepted candidates by changed field, label flips in the noisy branch, and exclusions
2SF-235300 · 396 prompt tokens, 94 verified response tokens, 94 counterexample response tokens.
All 192 training pairs fit the total-first rule, so the intervention tests labelling a narrow set of monetary errors. For subtotal mutations, inspect the novel and independent slices of the pair audit. The training data contains no currency or line-item preference contrasts.
Zephyr-7B used a different pair design for chat. The H4 team took the highest-rated answer and a randomly selected alternative after having four completions per prompt rated. Its single-epoch supervised baseline scored 6.64/10 on MT-Bench, rising to 7.00 with DPO. That design taught broad answer preferences. Here a deterministic invoice check supplies the individual error. Zephyr, paper-reported ablation, Table 3
What reversing the label changes
First train the SFT anchor on 192 verified invoice records. Save the adapter and freeze it to score each candidate under the reference. Reload the same adapter for both DPO fits, with a fresh optimiser for each. The one prompt exemplar, 192 SFT invoices and 192 DPO invoices are distinct. The two training cohorts can share supplier families. Held-out families and suppliers are separate from all three training sources.
Both DPO branches start from one checkpoint and consume the same tokens
Fit seconds and peak PyTorch allocation on one Tesla T4
3SFT anchor → frozen reference sums → two DPO fits
Common SHA-256 prefixes · adapter dee36879595a · reference 98f30f5944ef · update schedule 5f667dff4213
SFT anchor
23.56 s · 4.13 GiB
- 96/96 updates
- 21,378 response tokens
- 100,690 unpadded input tokens
Checked DPO
36.92 s · 4.61 GiB
- 96/96 updates
- 42,384 response tokens
- 200,696 unpadded input tokens
Flipped-label DPO
35.43 s · 4.61 GiB
- 96/96 updates
- 42,384 response tokens
- 200,696 unpadded input tokens
Frozen reference scoring took 33.90 s. Evaluation took 100.98 s for the anchor and 117.96 s and 114.83 s for the branches. The branch timers include held-out pair scoring.
For prompt x, call the labelled candidates y+ and y−. Sum the policy log probabilities over the supervised response targets. The mask includes the response and its EOS.
The function sigma is the logistic sigmoid. Beta scales the margin difference. Reversing the two labels negates both the policy margin and the reference margin. Both branches start with a measured first-batch loss of 0.693147, consistent with log(2) when the policy and reference margins match. The local implementation adapts the cookbook loss from preselected response log probabilities. DPO equation 7 · Together Post-Training Cookbook, pinned implementation
if pair.key in flipped_keys:
left, right = right, left
ref_chosen, ref_rejected = ref_rejected, ref_chosenMicrosoft Research tested a different kind of label flip. It constructed preference pairs from a sentiment classifier for GPT-2-large on IMDb, then flipped labels independently with probability 0.4. At 1,000 updates, the classifier reward for standard DPO fell from 0.99 ± 0.02 with clean labels to 0.88 ± 0.32 with flips. That experiment used a sentiment score. The invoice comparison reverses a fixed 48-pair subset and scores the complete generated record. Provably Robust DPO, paper-reported experiment, Table 1
Align the target with the predicting logit
The last prompt position predicts the first response token. The notebook starts vocabulary projection at the earliest such position in the batch, shifts the labels by one and gathers the active response scores. Prompt-side targets and padding use the ignore value −100. The prompt still conditions the response and can influence the loss through that context.
# Align target positions with the logit that predicts the next input token.
keep = torch.arange(start, last, device=device)
outputs = model(input_ids=batch["input_ids"], attention_mask=batch["attention_mask"],
logits_to_keep=keep, use_cache=False)
slots = response_logprobs(outputs.logits, batch["labels"][:, start + 1:])The final prompt logit predicts the first response token
Seven-position backward check. Token labels and logits use different rows.
4The Llama 3 post-training recipe masks formatting tokens including termination and adds a chosen-response negative-log-likelihood term. That is a different loss design. Here EOS stays in both candidate scores and natural termination is measured after greedy decoding. Llama 3, paper-reported method, §4.1.4
Which records changed
Ranking supplies both complete candidates and asks which the model gives a higher sum of response log probabilities. Generation supplies the invoice prompt alone and checks the entire greedy record against the verifier. The decoder can produce a third answer that never appeared among the supplied candidates.
On the opening remittance, all three tuned arms generated the correct record. Checked DPO gave it a larger ranking margin than the SFT anchor, 23.12 versus 12.70 nats. The prompted base returned 115,363 pence with an empty item list. The register-layout rule returned no record. Across the same 240 invoices these two controls generated 21 and 24 exact records respectively.
Open every raw output and pair score for the remittance
Expected record and recorded outputs for SF-235300
- Expected
- {"invoice_id":"SF-235300","issued_on":"2025-02-20","supplier":"Sample Supplier 3219","currency":"GBP","line_items":[{"description":"Rack inspection","quantity":8,"unit_minor":13740}],"subtotal_minor":109920,"tax_minor":14290,"total_minor":124311}
- Register-layout rules
- null
- FP16 prompted
- {"invoice_id":"SF-235300","issued_on":"2025-02-20","supplier":"Sample Supplier 3219","currency":"GBP","line_items":[],"subtotal_minor":124311,"tax_minor":109920,"total_minor":115363}
- SFT anchor
- {"invoice_id":"SF-235300","issued_on":"2025-02-20","supplier":"Sample Supplier 3219","currency":"GBP","line_items":[{"description":"Rack inspection","quantity":8,"unit_minor":13740}],"subtotal_minor":109920,"tax_minor":14290,"total_minor":124311}
- Checked DPO
- {"invoice_id":"SF-235300","issued_on":"2025-02-20","supplier":"Sample Supplier 3219","currency":"GBP","line_items":[{"description":"Rack inspection","quantity":8,"unit_minor":13740}],"subtotal_minor":109920,"tax_minor":14290,"total_minor":124311}
- Flipped-label DPO
- {"invoice_id":"SF-235300","issued_on":"2025-02-20","supplier":"Sample Supplier 3219","currency":"GBP","line_items":[{"description":"Rack inspection","quantity":8,"unit_minor":13740}],"subtotal_minor":109920,"tax_minor":14290,"total_minor":124311}
Outputs are stored as emitted. Null indicates no record from the register-layout rules.
| Arm | Verified | Counterexample | Margin |
|---|---|---|---|
| SFT anchor | -0.80 | -13.51 | 12.70 |
| Checked DPO | -0.60 | -23.73 | 23.12 |
| Flipped-label DPO | -0.60 | -18.35 | 17.75 |
For the familiar slice, all but one or two records were exact. The novel slice scored 54/96 for the SFT anchor, 50/96 for Checked DPO and 55/96 for Flipped-label DPO. On the independent layouts the anchor scored 29/48 (60.4%) and Checked DPO fell to 12/48 (25.0%), a drop of 35.4 percentage points (95% paired interval −52.1 to −16.7). Flipped-label DPO reached 22/48 (45.8%), still 14.6 points below the anchor (interval −20.8 to −8.3).
The biggest exact-record drop is on the independent layout
Exact greedy records by slice, with paired 95% family-resampled intervals
5Exact records by arm
Checked DPO minus flipped-label DPO
Difference, percentage points
Inspect invoice SF-467138 in the independent slice. The source prints Gross 388.85, and its breakdown prints net 363.41 and taxes 25.44. The checked branch emitted subtotal_minor: 38885 and total_minor: 36341, swapping gross and net. The anchor and flipped branch copied both correctly. Checked DPO still preferred the verified candidate over the supplied counterexample, which changed the payable amount to 388.80. The swapped record was a third possibility.
Course Invoice v1 · Synthetic document
Document SF-467138 Biller Sample Supplier 8052 / As of 2026-04-22 / USD 1 x Cable sleeve @ 230.21 per unit 8 x Carrier adjustment @ 16.65 per unit Gross 388.85 Breakdown: net 363.41 and taxes 25.44.
Expected record and recorded outputs for SF-467138
- Expected
- {"invoice_id":"SF-467138","issued_on":"2026-04-22","supplier":"Sample Supplier 8052","currency":"USD","line_items":[{"description":"Cable sleeve","quantity":1,"unit_minor":23021},{"description":"Carrier adjustment","quantity":8,"unit_minor":1665}],"subtotal_minor":36341,"tax_minor":2544,"total_minor":38885}
- Register-layout rules
- null
- FP16 prompted
- {"invoice_id":"SF-467138","issued_on":"2026-04-22","supplier":"Sample Supplier 8052","currency":"USD","line_items":[{"description":"Cable sleeve","quantity":1,"unit_minor":23021},{"description":"Carrier adjustment","quantity":8,"unit_minor":1665}],"subtotal_minor":38885,"tax_minor":2544,"total_minor":36341}
- SFT anchor
- {"invoice_id":"SF-467138","issued_on":"2026-04-22","supplier":"Sample Supplier 8052","currency":"USD","line_items":[{"description":"Cable sleeve","quantity":1,"unit_minor":23021},{"description":"Carrier adjustment","quantity":8,"unit_minor":1665}],"subtotal_minor":36341,"tax_minor":2544,"total_minor":38885}
- Checked DPO
- {"invoice_id":"SF-467138","issued_on":"2026-04-22","supplier":"Sample Supplier 8052","currency":"USD","line_items":[{"description":"Cable sleeve","quantity":1,"unit_minor":23021},{"description":"Carrier adjustment","quantity":8,"unit_minor":1665}],"subtotal_minor":38885,"tax_minor":2544,"total_minor":36341}
- Flipped-label DPO
- {"invoice_id":"SF-467138","issued_on":"2026-04-22","supplier":"Sample Supplier 8052","currency":"USD","line_items":[{"description":"Cable sleeve","quantity":1,"unit_minor":23021},{"description":"Carrier adjustment","quantity":8,"unit_minor":1665}],"subtotal_minor":36341,"tax_minor":2544,"total_minor":38885}
Outputs are stored as emitted. Null indicates no record from the register-layout rules.
| Arm | Verified | Counterexample | Margin |
|---|---|---|---|
| SFT anchor | -0.19 | -18.07 | 17.89 |
| Checked DPO | -0.76 | -34.93 | 34.17 |
| Flipped-label DPO | -0.26 | -22.94 | 22.68 |
Inspect both candidates used for ranking
Supplied candidates for SF-467138
- Verified
- {"invoice_id":"SF-467138","issued_on":"2026-04-22","supplier":"Sample Supplier 8052","currency":"USD","line_items":[{"description":"Cable sleeve","quantity":1,"unit_minor":23021},{"description":"Carrier adjustment","quantity":8,"unit_minor":1665}],"subtotal_minor":36341,"tax_minor":2544,"total_minor":38885}
- Counterexample
- {"invoice_id":"SF-467138","issued_on":"2026-04-22","supplier":"Sample Supplier 8052","currency":"USD","line_items":[{"description":"Cable sleeve","quantity":1,"unit_minor":23021},{"description":"Carrier adjustment","quantity":8,"unit_minor":1665}],"subtotal_minor":36341,"tax_minor":2544,"total_minor":38880}
All three tuned arms reached EOS on all 240 invoices. Among valid records from the independent slice, the anchor missed the printed total on 9/45, Checked DPO on 30/43, and Flipped-label DPO on 21/45. The scored currency was correct in every valid tuned record. The diagnostic localises the drop to record content, with payable totals a particular problem.
Checked DPO ends every response but more often gives the wrong total
Generation outcomes and field errors by slice. Field-error denominators count valid records only.
6Familiar · n = 96
SFT anchor
95 eos, exact · 1 eos, valid error · 0 eos, invalid · 0 cap reached
Wrong total 0/96 · Wrong currency 0/96
Checked DPO
94 eos, exact · 1 eos, valid error · 1 eos, invalid · 0 cap reached
Wrong total 0/95 · Wrong currency 0/95
Flipped-label DPO
94 eos, exact · 1 eos, valid error · 1 eos, invalid · 0 cap reached
Wrong total 0/95 · Wrong currency 0/95
Novel · n = 96
SFT anchor
54 eos, exact · 38 eos, valid error · 4 eos, invalid · 0 cap reached
Wrong total 16/92 · Wrong currency 0/92
Checked DPO
50 eos, exact · 41 eos, valid error · 5 eos, invalid · 0 cap reached
Wrong total 17/91 · Wrong currency 0/91
Flipped-label DPO
55 eos, exact · 37 eos, valid error · 4 eos, invalid · 0 cap reached
Wrong total 16/92 · Wrong currency 0/92
Independent · n = 48
SFT anchor
29 eos, exact · 16 eos, valid error · 3 eos, invalid · 0 cap reached
Wrong total 9/45 · Wrong currency 0/45
Checked DPO
12 eos, exact · 31 eos, valid error · 5 eos, invalid · 0 cap reached
Wrong total 30/43 · Wrong currency 0/43
Flipped-label DPO
22 eos, exact · 23 eos, valid error · 3 eos, invalid · 0 cap reached
Wrong total 21/45 · Wrong currency 0/45
Ai2's Tülu 3 research reports an aggregate score rising from 60.6 to 64.7 after DPO on its 8B model, alongside HumanEval pass@10 falling from 86.2% to 83.9% at that stage. The invoice task has its own definition of exactness. The Tülu example shows why a benchmark average needs a readout for each task that matters. Tülu 3, paper-reported stage comparison, Table 6
Both DPO arms mostly widen the margin by lowering the counterexample’s score
Change from the SFT anchor in summed log probability, nats. One point per held-out invoice.
7Checked DPO
183/240 margins widen while the verified score falls
Flipped-label DPO
126/240 margins widen while the verified score falls
Checked DPO widened the supplied-pair margin on all 240 invoices. On 183/240, the verified record's score fell at the same time. For SF-467138 the checked branch lowered the verified score from −0.19 to −0.76 nats, and lowered the counterexample score from −18.07 to −34.93 nats. Its margin rose from 17.89 to 34.17 nats as greedy extraction produced the swapped totals. Abacus.AI's Smaug study identifies this distinction between a relative preference and the absolute chosen score. Its DPO-Positive variant adds pressure when the preferred response's likelihood falls. Smaug, paper-reported method
What to keep
| Decision | Evidence |
|---|---|
| Keep the SFT anchor for extraction | The checked branch lost 22 exact records after adding DPO. The flipped branch lost seven, a paired change of −2.9 points with a 95% interval of −6.7 to 0.0. |
| Preserve the printed payable amount in labels | The matched DPO fit with flipped labels scored higher on generation in this benchmark. For SF-235300, the extraction target remains the printed GBP 1,243.11. Route the arithmetic discrepancy to reconciliation. |
| Gate preference-trained replacements on exact generated records | Both candidates can be scored correctly even when a third, incorrect record is generated. Keep the raw candidate scores and include independent layouts. |
The contrast describes one fit seed and synthetic supplier families. Its 95% intervals pair invoices and resample whole families for each comparison. The 0.0-point interval for ranking reflects identical wins across the sampled families. It says little about ranking harder candidates. The flipped branch's better generation score shows that a more reliable label and a better generated record can come apart under this recipe. The production release set remains reserved.
- Verify the same visible input for both answers. A preference pair should isolate a change in the response. Preserve the source invoice alongside both candidates.
- Check the deciding field. For SF-235300, the payable label comes from the printed amount. Keep the arithmetic discrepancy available for review.
- Inspect the pair after tokenisation. Check which completion tokens receive scores and confirm that the end token contributes to each comparison.
- Retain the SFT anchor. Score preference checkpoints against it on the same invoices and count gains and losses before interpreting the net change.
- Check generated records separately. A model can prefer the intended record between supplied options and still generate a third record that fails the contract.
- Next to try, not tested here: Build harder pairs around errors seen in generated independent layouts and evaluate the replacement against the same anchor with the release set reserved.
How it was built
| Item | Setting |
|---|---|
| Base | Qwen2.5-0.5B-Instruct at revision 7ae557604adf67be50417f59c2c2f167def9a775, FP16 on a Tesla T4 |
| Software | PyTorch 2.14.1+cu130, Transformers 4.51.3, PEFT 0.15.2, Accelerate 1.6.0 |
| Data | Course Invoice v1. Prompt exemplar SF-898991. 192 SFT examples, 192 training pairs and 240 separate teaching invoices (96 familiar, 96 novel, 48 independent) |
| Fit | Seed 42, LoRA rank 8 and alpha 16 on q_proj and v_proj, AdamW, batch size 2 and 96 successful updates per fit. Learning rates 2e−4 for SFT and 1e−5 for each DPO branch, beta 0.1 |
| Evaluation | Greedy decoding, one beam and a 384-token cap. Maximum encoded length 1,536. Exact-match intervals use 1,000 paired family resamples |
| Boundaries | 652.98 s end to end. The CUDA-synchronised fit timer covers the updates. The peak reports PyTorch-allocated memory. Reference scoring took 33.90 s, including anchor ranking on the held-out pairs. DPO evaluation times include generation and held-out ranking |
| Provenance | Split manifest, pair audit, reference sums, raw rankings, raw predictions, run report with full roster, pair, schedule and adapter hashes |
Run it yourself
Download the executed notebook and open it on a Tesla T4 in Colab. Reproduce the label audit under What makes a valid counterexample? and the seven-token proof under Which positions receive a direct loss?. In Does a better ranking produce a better invoice?, find SF-235300 and SF-467138 in the saved rows. For each exercise, predict the effect before changing one setting.
- Set
NOISE_FRACTIONto 0.10 and keep the pair roster and seed. Will fewer reversed labels close the gap in exact records? Inspect the new flip count and Checked-minus-Flipped intervals in the report. - Double
BETAfrom 0.1 to 0.2 and keep both branches on the original pair roster. Predict the first-batch loss, then compare the verified and counterexample score changes with the original held-out rankings. - In
shifted_gradient_evidence, change the EOS target from1to-100. Predict which logit loses a direct gradient before running the miniature. To pass the same change to both fits, replace EOS targets with-100inpolicy_slotsjust beforeresponse_logprobsand recalculate the reference sums. Keep the input sequence and decoding settings fixed. Compare EOS completion and exact records.
Next, return to the course outline for the lesson on verifiable rewards.
How is this page?
Last updated on