Run this model with HF Jobs
Run pcteja/InvoiceLine-135M on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/pcteja/InvoiceLine-135M. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/pcteja/InvoiceLine-135M on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use pcteja/InvoiceLine-135M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use pcteja/InvoiceLine-135M with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("HuggingFaceTB/SmolLM2-135M-Instruct") model = PeftModel.from_pretrained(base_model, "pcteja/InvoiceLine-135M") - Notebooks
- Google Colab
- Kaggle
InvoiceLine · 135M
Draft purchase rows from supplier invoices, on a CPU. Baidu's PP-OCRv6 reads the page. A fine-tuned 135M model proposes what unfamiliar columns mean. Ordinary code copies the printed numbers, checks the math, and keeps the original line visible for review.
Status: experimental adapter and reference pipeline. This release does not post inventory, set Selling Price, pay invoices, or send documents to a cloud API.
What it reads
| Supported in this prototype | Left out of scope |
|---|---|
| One printed, single-page English PDF or image | Multi-page tables, handwriting, and wrapped or merged table rows |
| One table with description, quantity, unit cost, and line total | Optional discount/tax columns, inclusive tax arithmetic, and credit notes |
| Known column names use a fast deterministic path; unusual names can be suggested by the model | No automatic acceptance of model suggestions or accounting decisions |
The extractor returns review_required even when all arithmetic matches. An arithmetic check cannot distinguish every wrong mapping: swapped quantity and unit cost can multiply to the same total. When a row fails a check, the numeric fields stay blank and the original line is preserved. Purchase unit cost is taken from the invoice; retail Selling Price remains the operator’s decision.
How it works
| Step | Component | Responsibility |
|---|---|---|
| 1 | PP-OCRv6 Tiny | Read text and group detected boxes into rows |
| 2 | SmolLM2 + LoRA | Propose a mapping for unfamiliar headers; abstain on unsupported or uncertain layouts |
| 3 | Decimal checks | Copy numbers verbatim in value, with no generated amounts, and flag mismatches |
| 4 | Human review | Confirm the source, quantities and purchase prices before any downstream use |
Unlimited-OCR is a separate Baidu model. This build uses the smaller CPU-oriented PP-OCRv6 Tiny. The small and medium tiers are available in the integration but were not evaluated here.
Measured results
Synthetic header challenge · 140 examples
| Approach | Correct layouts out of 120 supported | Wrong layout proposals | Ambiguous examples rejected |
|---|---|---|---|
| Exact-phrase rules | 0 | 0 | 20/20 |
| Untuned SmolLM2, factorized decoder | 0 | 0 | 20/20 |
| InvoiceLine adapter, review gate on | 23 | 0 | 20/20 |
| InvoiceLine adapter, review gate off | 31 | 0 | 20/20 |
| Alternative whole-header adapter, raw decoder | 32 | 86 | 9/20 |
The release gate proposed a correct mapping on 23/120 supported layouts (19.2% coverage) and deferred the other 97. The untuned factorized baseline deferred all 120. Zero wrong proposals in 23 attempts is an encouraging pilot result, not proof of safety. The narrow exact-phrase baseline is expected to abstain because the challenge deliberately holds its phrases out. In the alternative whole-header run, the untuned model got 24/140 overall decisions right; the whole-header adapter got 41/140, with substantially more incorrect proposals than the release adapter. We chose the conservative decoder.
Training: 864 sampled synthetic column-header instances, 72 CPU updates, 737,280 trainable parameters, 97.56 seconds of optimizer steps on four threads of an Intel Xeon Platinum 8573C cloud CPU. This excludes load and evaluation time. The release ranks four label tokens per column and requires a unique assignment and a minimum 0.65 probability gap between each column's top two labels. The gap is a heuristic, not a calibrated confidence score.
The fixed header challenge contains synthetic examples from all six column orders and ambiguous examples. Training and evaluation use disjoint header phrases, but they share a generator and some vocabulary. It is not a test of real supplier diversity or end-to-end document extraction. In local CPU smoke tests, the complete pipeline extracted all three rows from a sample with known headers and all three rows from a sample routed through the adapter. A deliberately crowded header and an uncertain alternate layout were deferred without guessing. The model-assisted example was chosen to illustrate a successful route, not as independent evaluation evidence. These smoke tests do not establish production reliability or a hardware speed guarantee.
Quick start
No account token is needed. The first setup downloads public model weights. For fully offline use, put the Paddle models and the original SmolLM2 checkpoint on disk first and pass both local paths as shown below.
Try the deterministic path with stock Python:
python extract.py examples/known.txt
python -m unittest discover -s tests -v
Install the OCR and model components in separate Python 3.12 environments:
python -m venv .venv-ocr
.venv-ocr/bin/python -m pip install -r requirements-ocr.txt
python -m venv .venv-model
.venv-model/bin/python -m pip install 'torch==2.8.0+cpu' --index-url https://download.pytorch.org/whl/cpu
.venv-model/bin/python -m pip install -r requirements-model.txt
The commands above are for Linux x86-64. On Windows, use your environment’s Scripts\python.exe and the PyTorch installer for your OS. Only Linux CPU was tested in this build.
.venv-ocr/bin/python ocr.py examples/blue-reef-synthetic.pdf \
--model-dir /path/to/ocr-models --out /tmp/invoice-ocr.json
.venv-model/bin/python extract.py /tmp/invoice-ocr.json \
--base /path/to/SmolLM2-135M-Instruct --adapter . --out /tmp/invoice-review.json
The OCR folder must contain PP-OCRv6_tiny_det/ and PP-OCRv6_tiny_rec/, populated from the detector and the recognizer. Omit --model-dir if network downloads are available. Omit --base to use the public base model from the Hub. For an offline run, set HF_HUB_OFFLINE=1 when loading the local model checkpoint.
Reproduce and extend
evaluation/contains measured results and the raw experiment summaries.- Re-run the release experiment with
python factor.py --steps 72 --batch 12 --threads 4 --out adapter-factor. Usepython benchmark.py --adapter .to compare the distributed weights with the base. Both commands accept--basefor a local checkpoint.train.pyreproduces the alternative whole-header strategy with--steps 140 --batch 8. examples/contains fabricated invoices, OCR evidence, and review output. No customer invoices or private identifiers were used.- A next evaluation should score exact line items, wrong values that passed arithmetic, how often review is needed, and end-to-end latency on previously unseen supplier layouts. The Hyperbots synthetic invoice set is a candidate external benchmark, not part of these results.
Credits and license: The base is SmolLM2-135M-Instruct from HuggingFaceTB. OCR is from the PaddleOCR project. Apache-2.0 applies to this repository and adapter. The base model and OCR weights are downloaded separately under their upstream terms.
- Downloads last month
- 6
Model tree for pcteja/InvoiceLine-135M
Base model
HuggingFaceTB/SmolLM2-135M