--- license: apache-2.0 base_model: Qwen/Qwen3.5-9B base_model_relation: finetune pipeline_tag: image-text-to-text library_name: transformers language: - en - zh - ja tags: - document-extraction - structured-extraction - information-extraction - fdem - qwen3.5 - vllm --- # fdem-9b fdem fills a list of fields from one document: text, a page image or one PDF page. It returns one typed value per field. The model is trained to return null for a field the document does not state, and the response gives the reason. Use it through the [fdem Python package](https://github.com/davidleitw/fdem), which builds the prompt the model was trained on and checks and converts its answers. Video: [43-second introduction](https://github.com/davidleitw/fdem#readme), on the GitHub page. fdem-9b is a fine-tune of [Qwen/Qwen3.5-9B](https://huggingface.co/Qwen/Qwen3.5-9B), merged into bf16 weights (19.3 GB). It reads text and page images. Its prompt version is `general-v7-en` (document, then fields); `fdem.json` in this repository names it, and the fdem package reads it. Other formats: [fdem-9b-FP8](https://huggingface.co/davidleitw/fdem-9b-FP8) (vLLM), [fdem-9b-GGUF](https://huggingface.co/davidleitw/fdem-9b-GGUF) (llama.cpp, Ollama, LM Studio), [fdem-9b-MLX-4bit](https://huggingface.co/davidleitw/fdem-9b-MLX-4bit) (Apple Silicon). Each has its own measured scores. The other size: [fdem-4b](https://huggingface.co/davidleitw/fdem-4b). ## 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: ```bash git clone https://github.com/davidleitw/fdem && cd fdem pip install . vllm==0.33.0 hf download davidleitw/fdem-9b --local-dir fdem-9b MODEL_DIR=fdem-9b ./examples/serve_vllm.sh # vLLM on :8091, the fdem API on :8000 ``` ```bash # 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: ```python from pathlib import Path from fdem import Extractor extractor = Extractor.vllm("fdem-9b") # or Extractor.transformers("fdem-9b") without vLLM result = 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](https://github.com/davidleitw/fdem/blob/master/docs/api.md). Recipes: [docs/cookbook.md](https://github.com/davidleitw/fdem/blob/master/docs/cookbook.md). ## Scores On the [fdem benchmark](https://huggingface.co/datasets/davidleitw/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. | Set | Right | Wrong | Blank | Filled empty fields | Documents fully right | |---|---|---|---|---|---| | Held-back, English (343 documents) | 2,900 | 19 | 38 | 8 / 218 | 302 / 343 | | Held-back, Chinese DRCD (270 passages) | 915 | 23 | 10 | - | 240 / 270 | | Held-back, Japanese JaWildText (320 receipts) | 1,026 | 49 | 2 | 6 / 156 | 267 / 320 | | Real-usage (198 documents) | 1,604 | 114 | 39 | 21 / 389 | 102 / 198 | On the English held-back documents, fdem-9b makes the fewest wrong answers plus fills of empty fields among the 9B-class or smaller open models that were tested: 0.85 per 100 fields, against 1.54 for NuExtract3 and 1.67 for the untrained Qwen3.5-9B. On the real-usage set it makes 6.29 wrong answers plus fills of empty fields per 100 fields, against 7.78 for the untrained Qwen3.5-9B, and fills 21 of 389 empty fields, against 67. All tables, every compared model and how each was run: [docs/results.md](https://github.com/davidleitw/fdem/blob/master/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.557 s per document one request at a time and 5.6 documents per second at 32 requests in flight; how this was measured, and the other formats: [docs/results.md](https://github.com/davidleitw/fdem/blob/master/docs/results.md#speed). ## 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-9B](https://huggingface.co/Qwen/Qwen3.5-9B) (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](https://github.com/davidleitw/fdem/blob/master/benchmark/README.md#sources-and-licences). ## Citation ```bibtex @software{lei2026fdem, author = {Lei, David}, title = {{FDEM}: Field-level Data Extraction Model}, version = {0.1.0}, year = {2026}, url = {https://github.com/davidleitw/fdem} } ```