How to Build a Ground-Truth Set for Japanese Invoice OCR
TUTORIAL 4 min read 7 views

How to Build a Ground-Truth Set for Japanese Invoice OCR

Label three Japanese invoice samples, catch missing tax rows with a runnable Python check, and decide which documents require human review.

K

KizunaX

Author

Share:

An invoice OCR result can get the ¥16,400 grand total right and still drop the 8% tax line. A pipeline that checks the total alone gives that document a pass. Before choosing a Japanese OCR API or changing the model, build a reference set that makes this failure visible.

This is the first part of a series on bringing Japanese invoice OCR into production. It gives you three synthetic cases, a labeling contract and a Python check that runs locally. The next part will turn these checks into field-level evaluation metrics.

Pick three inputs with different failure modes

Build each sample with fictional data. Keep the exact files that will go to the OCR service, including the cropped version. Give each input a stable case ID.

Case What the input contains What the check should catch
A · Clean PDF Invoice 0007, issue date 2026年11月25日, total ¥11,000 and a 10% tax line of ¥1,000 A leading zero lost during conversion
B · Tilted scan Invoice 0008, issue date 2026年11月27日, total ¥16,400, tax ¥400 at 8% and ¥1,000 at 10% A tax line dropped even though the total is correct
C · Cropped image Invoice 0009, total ¥11,000 and a 10% tax line of ¥1,000. The issue date is cropped out and the payment deadline 2026年12月25日 is still visible. A payment deadline incorrectly copied into the issue-date field

Case B stores a tax amount against each rate. This mirrors the distinction between consideration grouped by rate and consumption-tax amounts grouped by rate in Japan's invoice guidance. Keep the role of each value clear when creating test labels. Japan National Tax Agency, qualified invoice fields

Label the values that can be read from the input

  • Use a string for invoice_no so 0007 survives. Keep the raw transcription beside the normalized value, including any full-width digits.
  • Use YYYY-MM-DD for issued_on and label the issue date separately from the payment deadline. Record null for the cropped field in C and mark the reason as unreadable.
  • Use integer yen for total_jpy and a map from rate to tax amount for tax_jpy_by_rate. Check the printed labels to identify the grand total, taxable base and tax amount.
  • For every expected value, record the page and source region such as the header, total box or tax breakdown. Have a second reader verify ambiguous labels. Freeze the labels and the input versions before comparing systems.

Compare normalized values in Python

Copy the block into invoice_check.py and run python invoice_check.py. The simulated OCR outputs include the two mistakes described above. When you try a real API, use the same files and map its saved response into the four fields in predicted. Check the field types in this mapping step and record the model, prompt and normalization version.

gold = {
    "A": {"invoice_no": "0007", "issued_on": "2026-11-25",
          "total_jpy": 11000, "tax_jpy_by_rate": {"10": 1000}},
    "B": {"invoice_no": "0008", "issued_on": "2026-11-27",
          "total_jpy": 16400, "tax_jpy_by_rate": {"8": 400, "10": 1000}},
    "C": {"invoice_no": "0009", "issued_on": None,
          "total_jpy": 11000, "tax_jpy_by_rate": {"10": 1000}},
}

predicted = {
    "A": dict(gold["A"]),
    "B": {**gold["B"], "tax_jpy_by_rate": {"10": 1000}},
    "C": {**gold["C"], "issued_on": "2026-12-25"},
}

def review_reasons(expected, actual):
    reasons = []
    for field, value in expected.items():
        if value is None:
            reasons.append(f"{field}: unreadable")
        if field not in actual or actual[field] != value:
            reasons.append(f"{field}: mismatch")
    return reasons

for document, expected in gold.items():
    reasons = review_reasons(expected, predicted[document])
    result = "REVIEW | " + ", ".join(reasons) if reasons else "PASS"
    print(document, result)

The local run gives these results.

A PASS
B REVIEW | tax_jpy_by_rate: mismatch
C REVIEW | issued_on: unreadable, issued_on: mismatch

B goes to review because the rate map is incomplete. C goes to review because the input lacks a readable issue date and the extracted date has a different meaning. If the API leaves that field blank, the missing required value still calls for review.

Use the result to decide what to measure next

Add unseen supplier layouts, scans at different resolutions and multi-page invoices to a separate, manually labeled set. Report exact match per field using readable labels as the denominator. Track the documents the production rules would import automatically and the incorrect records within that group. Use the three cases above as repeatable checks for known failures when you change the OCR model, prompt or parser. Google Cloud Document AI, evaluation metrics

To try your own files with KizunaX, start with the Japanese product and API overview, then run the same comparison against your normalized extraction results. KizunaX Japanese homepage and API overview

Tags

#OCR#Japanese Invoices#Evaluation

Enjoyed this article?

Share it with your network