Skip to content
mentoor

Topic 4 of 5 · 4 min read

Ground-truth sets for vision extraction

Goal: Build a small labeled set for a document extraction feature and compare two models on field-level accuracy.

To test document extraction, hand-label a representative set of documents once, then score every model and prompt against those labels field by field. A few dozen well-chosen documents beat a thousand unchecked ones.

Check yourself · 1 of 3

Which pair of metrics describes an extraction field that is right when it answers but often returns nothing?

Choose one answer

Why it matters

Vision models such as Claude, GPT and Gemini read invoices, forms and receipts well on clean samples and badly on a crumpled receipt photographed at an angle. Without labels, "it looks right" is the only test, and a model upgrade can quietly make a field worse. A labeled set turns a model change into a number.

How to do it

  1. Sample from real traffic. Pull documents the way users send them: phone photos, scans, PDFs, different suppliers and layouts. Do not use only the clean ones.
  2. Include the hard cases on purpose. Handwriting, skewed scans, stamps over text, low light, multi-page tables, a second language. Tag each document with its hard case, so you can report on them separately.
  3. Label by field. For each document, write the true value of each field you extract: invoice number, date, total, currency, line items. Have a second person check a sample of labels. Labels written carelessly make a good model look bad.
  4. Define a match. Decide how values compare: exact for invoice numbers, normalised for dates (03/04/2026 is ambiguous, so store ISO), tolerance for amounts. Write the rule down.
  5. Score per field. For each field, precision is the share of extracted values that are right, and recall is the share of true values that were found. A model that returns nothing has perfect precision and zero recall.
  6. Rerun on every change. A new model, a new prompt, a changed image resolution: same set, same scorer.

Before and after

Before: "Model B feels better on the invoices I tried."

After:

Field Model A recall Model B recall Model A precision Model B precision
Invoice number 0.96 0.97 0.98 0.97
Total 0.90 0.93 0.95 0.94
Handwritten notes 0.40 0.62 0.70 0.66

Model B is better where it matters (handwriting), roughly equal elsewhere.

What goes wrong

  • A set of clean samples. Scores look excellent and production fails.
  • Leaking the labeled set into the prompt. If example documents from the test set are used as few-shot examples, the score is inflated.
  • One accuracy number for the whole document. It hides a field that is always wrong.

Examples

Choosing the sample

A team extracts totals from 600 supplier invoices a week. They label 60: 30 clean PDFs, 15 phone photos, 8 skewed scans, 4 with handwriting, 3 in German. Each is tagged, so the report can say "totals on phone photos: recall 0.81" instead of one blended number.

Precision against recall

A model extracts 40 totals from 50 invoices and 38 are correct. Precision is 38 / 40 = 0.95. Recall is 38 / 50 = 0.76. It is accurate when it answers but skips many invoices, so a fallback or human review is needed for the empty ones.

Key points

  • A ground-truth set is a sample of real documents with the true value of each field written by hand.
  • Include hard cases on purpose and tag them so scores can be reported per case.
  • Precision is the share of extracted values that are right; recall is the share of true values that were found.
  • Write the match rule per field, for example exact for ids and normalised for dates.
  • Rerun the same set and scorer on every model, prompt or resolution change.

Common mistakes

  • Building the test set from only clean, easy documents.
  • Reporting one overall accuracy figure and no per-field scores.
  • Using test documents as examples in the prompt.
  • Leaving date and amount formats out of the match rule.

Check yourself · 2 of 3

Why tag hard cases such as handwriting and skewed scans in a labeled set?

Choose one answer

Check yourself · 3 of 3

You want to compare two vision models for invoice extraction. What is the best next step?

Choose one answer

Practice items, not counted towards your mastery.

Start here