Downloads · 30 days
9
9% of all-time downloads
HasanALhomsi/layoutlmv3-cord-invoice
layoutlmv3-cord-invoice is a token classification model from HasanALhomsi. Use it when you need labels on individual words, such as names. The card lists the license as cc-by-4.0.
This model is a fine-tuned version of microsoft/layoutlmv3-base on the CORD (Consolidated Receipt Dataset) for document field extraction (token classification).
Downloads · 30 days
9
9% of all-time downloads
All-time downloads
104
Public
Parameters
126M
504 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors504 MB · 99%
From the Hugging Face model README
This model is a fine-tuned version of microsoft/layoutlmv3-base on the CORD (Consolidated Receipt Dataset) for document field extraction (token classification).
Instead of just extracting raw text like traditional OCR, this model understands the structure of a receipt/invoice and classifies each word into a specific field (item name, price, quantity, tax, total, etc.), combining text, layout (bounding boxes), and the document image itself.
microsoft/layoutlmv3-baseLayoutLMv3ForTokenClassification)Extracting structured fields from receipt-style documents (item names, prices, quantities, subtotal, tax, total, payment method) as part of a document understanding / data extraction pipeline feeding a database or RAG system.
from transformers import LayoutLMv3ForTokenClassification, LayoutLMv3Processor
from PIL import Image
import torch
model = LayoutLMv3ForTokenClassification.from_pretrained("your-username/layoutlmv3-cord-invoice")
processor = LayoutLMv3Processor.from_pretrained("your-username/layoutlmv3-cord-invoice", apply_ocr=False)
image = Image.open("receipt.jpg").convert("RGB")
# words and boxes must come from your own OCR step (e.g. PaddleOCR),
# with boxes normalized to a 0-1000 scale
words = [...] # list[str]
boxes = [...] # list[[x0, y0, x1, y1]], normalized 0-1000
encoding = processor(
image, words, boxes=boxes,
truncation=True, padding="max_length", max_length=512, return_tensors="pt"
)
with torch.no_grad():
outputs = model(**encoding)
predictions = outputs.logits.argmax(-1).squeeze().tolist()
labels = [model.config.id2label[p] for p in predictions]
⚠️ This model does not include an OCR engine. You must run OCR (e.g. PaddleOCR, Tesseract) first to obtain
wordsandboxes, sinceapply_ocr=False.
The model uses BIO tagging over the following CORD field categories:
MENU.NM, MENU.CNT, MENU.PRICE, MENU.UNITPRICE, MENU.DISCOUNTPRICE,
MENU.SUB_NM, MENU.SUB_CNT, MENU.SUB_PRICE, MENU.SUB_UNITPRICE, MENU.ETC,
MENU.SUB_ETC, MENU.NUM, MENU.VATYN,
SUB_TOTAL.SUBTOTAL_PRICE, SUB_TOTAL.TAX_PRICE, SUB_TOTAL.SERVICE_PRICE,
SUB_TOTAL.DISCOUNT_PRICE, SUB_TOTAL.ETC, SUB_TOTAL.OTHERSVC_PRICE,
TOTAL.TOTAL_PRICE, TOTAL.CASHPRICE, TOTAL.CHANGEPRICE, TOTAL.CREDITCARDPRICE,
TOTAL.EMONEYPRICE, TOTAL.MENUQTY_CNT, TOTAL.MENUTYPE_CNT, TOTAL.TOTAL_ETC,
VOID_MENU.NM, O
(each prefixed with B- / I- per standard BIO tagging — 54 labels total)
valid_line, dontcare) into word-level (text, bbox, label) triples, preserving original word order within each entity for correct BIO sequencing.LayoutLMv3Processor, aligning sub-word tokens to their parent word's label (-100 for non-first sub-tokens, per standard token classification practice).LayoutLMv3ForTokenClassification using the 🤗 Trainer API.2e-5Evaluated using seqeval (entity-level Precision, Recall, F1). See training logs for per-label breakdown.
The CORD dataset used for fine-tuning is licensed under CC BY 4.0.