InvoiceDesk: Donut fine-tuned to read supplier invoices
Reads a photo of a supplier invoice and returns the fields an accountant types in (supplier, NIF, RC, invoice number, date, client, every line, total HT, TVA, stamp duty, total TTC), or answers a question about it in French or English.
Fine-tuned from naver-clova-ix/donut-base on one Kaggle T4 GPU (3 epochs, 1280×960 input, 135 minutes) for three tasks at once: CORD-v2 receipts, generated Algerian invoices, and questions about those invoices. Code, data generator, training job and evaluation: https://github.com/okba-bouziane/InvoiceDesk
The Algerian invoices used for training and testing are generated (companies, people and numbers are invented). There is no public dataset of Algerian invoices.
Results (unseen test images)
| Test set | This model | Tesseract OCR + rules |
|---|---|---|
| Field F1, invoices in the 6 training layouts (300) | 0.968 | 0.428 |
| Field F1, a layout and font never seen in training (300) | 0.698 | 0.477 |
| Field F1, CORD-v2 test receipts (100) | 0.592 | n/a |
| Questions worded unlike any training question, exact match (300) | 0.777 | n/a |
The NIF is the weakest field (61.7% exactly right, usually one digit off). Full tables, per-field scores and limitations are in the GitHub README.
Use
The first decoder token selects the task:
<s_dzinv>: read an invoice into fields<s_cord-v2>: read a CORD-style receipt<s_docvqa><s_question>{question}</s_question><s_answer>: answer a question
from PIL import Image
from transformers import DonutProcessor, VisionEncoderDecoderModel
repo = "okba-bouziane/invoicedesk-donut"
processor = DonutProcessor.from_pretrained(repo)
model = VisionEncoderDecoderModel.from_pretrained(repo).eval()
image = Image.open("invoice.jpg").convert("RGB")
pixels = processor(image, return_tensors="pt").pixel_values
prompt = processor.tokenizer("<s_dzinv>", add_special_tokens=False, return_tensors="pt").input_ids
out = model.generate(pixels, decoder_input_ids=prompt, max_length=512)
print(processor.tokenizer.batch_decode(out)[0]) # <s_vendor>…</s_vendor><s_items>…
invoicedesk/donut.py in the GitHub repo turns the output sequence back into JSON, and invoicedesk/normalize.py checks the totals.
In the browser (8-bit ONNX)
onnx/encoder_model_quantized.onnx (91 MB) and onnx/decoder_model_merged_quantized.onnx (188 MB, per-channel 8-bit weights) are the copy the browser demo runs with transformers.js (dtype: 'q8'). Scored with ONNX Runtime on CPU on the same test invoices as the full model:
| Field F1 | Full model | 8-bit |
|---|---|---|
| Training layouts (300) | 0.968 | 0.964 |
| Layout never seen in training (300) | 0.700 | 0.620 |
Question exact match: 0.747 (training layouts) and 0.707 (unseen layout), against 0.777 and 0.737. onnx/encoder_model.onnx and onnx/decoder_model_merged.onnx are the full-precision exports.
License
MIT. Base model: Donut (MIT). Training data: CORD-v2 (CC BY 4.0) and data generated by the project.