Instructions to use davidleitw/fdem-9b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use davidleitw/fdem-9b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="davidleitw/fdem-9b") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("davidleitw/fdem-9b") model = AutoModelForMultimodalLM.from_pretrained("davidleitw/fdem-9b", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use davidleitw/fdem-9b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "davidleitw/fdem-9b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "davidleitw/fdem-9b", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/davidleitw/fdem-9b
- SGLang
How to use davidleitw/fdem-9b with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "davidleitw/fdem-9b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "davidleitw/fdem-9b", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "davidleitw/fdem-9b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "davidleitw/fdem-9b", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use davidleitw/fdem-9b with Docker Model Runner:
docker model run hf.co/davidleitw/fdem-9b
# pip install -U transformers accelerate
# Load model directly
from transformers import AutoProcessor, AutoModelForMultimodalLM
processor = AutoProcessor.from_pretrained("davidleitw/fdem-9b")
model = AutoModelForMultimodalLM.from_pretrained("davidleitw/fdem-9b", device_map="auto")
messages = [
{
"role": "user",
"content": [
{"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
{"type": "text", "text": "What animal is on the candy?"}
]
},
]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=256)
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))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, which builds the prompt the model was trained on and checks and converts its answers.
Video: 43-second introduction, on the GitHub page.
fdem-9b is a fine-tune of 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 (vLLM), fdem-9b-GGUF (llama.cpp, Ollama, LM Studio), fdem-9b-MLX-4bit (Apple Silicon). Each has its own measured scores. The other size: 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:
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
# 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 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. 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.
| 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. 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.
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.
confidencecomes 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 (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}
}
- Downloads last month
- 40
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="davidleitw/fdem-9b") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)