Usage
The package is on PyPI as fdem-extract (pip install fdem-extract; you still import fdem). The steps below also use the serving script in the repository, so clone it and install from there. With vLLM 0.33.0 on Linux and an NVIDIA GPU:
git clone https://github.com/davidleitw/fdem && cd fdempip install . vllm==0.33.0hf download davidleitw/fdem-4b --local-dir fdem-4bMODEL_DIR=fdem-4b ./examples/serve_vllm.sh # vLLM on :8091, the fdem API on :8000
# in a second terminal, once serve_vllm.sh prints a line starting with ready:curl -s localhost:8000/v1/extract -H 'Content-Type: application/json' -d '{ "state": "Invoice INV-1042 from Acme Trading Ltd.\nInvoice date: 2026-04-17\nTotal due: NT$3,480", "fields": {"invoice_number": {"type": "text"}, "invoice_date": {"type": "date"}, "total_due": {"type": "number"}, "due_date": {"type": "date"}}}'# "answers": {"invoice_number": "INV-1042", "invoice_date": "2026-04-17", "total_due": 3480, "due_date": null},# "null_reasons": {"due_date": "not_stated"}, plus spans, confidence and checks
From Python:
from pathlib import Pathfrom fdem import Extractor extractor = Extractor.vllm("fdem-4b") # or Extractor.transformers("fdem-4b") without vLLMresult = extractor.extract(fields={"total": {"type": "number"}, "date": {"type": "date"}}, image=Path("receipt.jpg").read_bytes())print(result["answers"], result["null_reasons"])
API reference: docs/api.md. Recipes: docs/cookbook.md.
Scores
On the fdem benchmark. Right, Wrong and Blank count the fields the document states; "Filled empty fields" counts fields the document leaves empty that the model filled anyway. Filled answers on stated fields that matched neither the expected answer nor a listed alternative were judged by reviewers who did not see which model wrote them.
Table with columns: Set, Right, Wrong, Blank, Filled empty fields, Documents fully right| Set | Right | Wrong | Blank | Filled empty fields | Documents fully right |
|---|
| Held-back, English (343 documents) | 2,899 | 30 | 28 | 7 / 218 | 297 / 343 |
| Held-back, Chinese DRCD (270 passages) | 890 | 31 | 27 | - | 221 / 270 |
| Held-back, Japanese JaWildText (320 receipts) | 1,048 | 23 | 6 | 8 / 156 | 285 / 320 |
| Real-usage (198 documents) | 1,570 | 121 | 66 | 21 / 389 | 87 / 198 |
On the English held-back documents, fdem-4b makes 1.17 wrong answers plus fills of empty fields per 100 fields, against 1.54 for NuExtract3, 1.67 for the untrained Qwen3.5-9B and 2.74 for the untrained Qwen3.5-4B. It fills 7 of 218 empty fields there, 8 of 156 on Japanese receipts and 21 of 389 on the real-usage set; the 9B-class or smaller open models that were tested fill 19 to 119, 38 to 107 and 67 to 92 (on the real-usage set only Qwen3.5-9B, NuExtract3 and Qwen3.5-4B were run; on Japanese receipts LFM2 1.2B Extract fills 5, but leaves 1,061 of the 1,077 stated fields blank). On Japanese receipts it makes fewer wrong answers than fdem-9b (23 against 49).
All tables, every compared model and how each was run: docs/results.md. Speed, with hardware and runtime: on one RTX 5090 with vLLM 0.33.0, on 200 benchmark documents sent as text, each with its own field list, a median 0.345 s per document one request at a time and 11.4 documents per second at 32 requests in flight; how this was measured, and the other formats: docs/results.md.
Intended use
Pulling typed fields (names, numbers, dates, times, durations, lists and tables) out of invoices, receipts, forms, contracts, statements, filings, notices and web pages, where an empty answer is better than a guessed one. Check the answers that matter: spans, null_reasons and confidence in each response point to the ones worth a second look.
Out of scope: decisions about people made without human review (credit, hiring, benefits), identifying people in documents, and multi-page reasoning across a whole PDF.
Limitations
- One page per request. Up to 20 fields, 200,000 characters of text and 16,384 tokens per request. Field names must be English.
- Measured on English, Chinese (mostly Traditional) and Japanese (receipts as text). Other languages are untested.
confidence comes from token probabilities; use it to sort answers for review, not as the chance of being right.
- Scores hold only with fdem building the prompt. Calling the weights with your own prompt, directly or through Ollama or llama.cpp, is not measured.
Licence
The weights are released under Apache-2.0, the licence of the base model Qwen3.5-4B (also Apache-2.0). The training data and training code are not part of this release. The benchmark documents keep their sources' licences, listed in the benchmark README.
Citation
@software{lei2026fdem, author = {Lei, David}, title = {{FDEM}: Field-level Data Extraction Model}, version = {0.1.0}, year = {2026}, url = {https://github.com/davidleitw/fdem}}