How to use from the
Use from the
Transformers library
# Use a pipeline as a high-level helper
from transformers import pipeline

pipe = pipeline("image-text-to-text", model="davidleitw/fdem-4b")
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-4b")
model = AutoModelForMultimodalLM.from_pretrained("davidleitw/fdem-4b", 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]:]))
Quick Links

fdem-4b

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-4b is a fine-tune of Qwen/Qwen3.5-4B, merged into bf16 weights (9.3 GB). It reads text and page images. Its prompt version is general-v8-en (fields, then document), with a type contract: every value in its type's standard form; fdem.json in this repository names it, and the fdem package reads it.

Other formats: fdem-4b-FP8 (vLLM), fdem-4b-GGUF (llama.cpp, Ollama, LM Studio), fdem-4b-MLX-4bit, fdem-4b-MLX-8bit (Apple Silicon). Each has its own measured scores. The other size: fdem-9b.

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-4b --local-dir fdem-4b
MODEL_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 Path
from fdem import Extractor

extractor = Extractor.vllm("fdem-4b")                 # or Extractor.transformers("fdem-4b") 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,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}
}
Downloads last month
41
Safetensors
Model size
5B params
Tensor type
BF16
·
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for davidleitw/fdem-4b

Finetuned
Qwen/Qwen3.5-4B
Finetuned
(1,763)
this model
Quantizations
5 models

Collection including davidleitw/fdem-4b