Skip to content

L-01 Document Extractor

Open source, Apache-2.0

87.8% fields right on 500 held-out documents, up from 67.6%

extractionJSON output16 languagesforms and documentsruns on a laptop

Emails, receipts, badge scans and school notices in 16 languages, each paired with a JSON schema. The job is to fill the schema exactly, on a laptop, without the document leaving the machine.

Sixty steps of reinforcement learning took field accuracy from 67.6% to 87.8% on 500 held-out documents. Most of the gain came from one fix: the base model kept returning the schema instead of filling it in.

The weights are a LoRA adapter on top of Qwen/Qwen3.5-0.8B. Load both with transformers and peft.

  1. Install

    Terminal window
    pip install -U transformers peft accelerate
  2. Load and ask

    run.py
    from transformers import AutoModelForCausalLM, AutoTokenizer
    from peft import PeftModel
    base = "Qwen/Qwen3.5-0.8B"
    tok = AutoTokenizer.from_pretrained(base)
    model = AutoModelForCausalLM.from_pretrained(base, torch_dtype="auto", device_map="auto")
    model = PeftModel.from_pretrained(model, "superbird-labs/l-01-document-extractor")
    SYSTEM = open("system_prompt.txt").read() # the prompt below
    messages = [{"role": "system", "content": SYSTEM},
    {"role": "user", "content": "your input here"}]
    ids = tok.apply_chat_template(messages, add_generation_prompt=True,
    enable_thinking=False, return_tensors="pt").to(model.device)
    out = model.generate(ids, max_new_tokens=512, do_sample=False)
    print(tok.decode(out[0][ids.shape[-1]:], skip_special_tokens=True))

Trained with this exact system prompt. Use it word for word: small models are picky about their instructions.

system prompt
Extract the data in the user's document into a JSON object that matches this JSON Schema:
{your JSON Schema here}
a real test input
निसर्ग फिज़ियोथेरेपी क्लिनिक
प्रिय सौम्या बेलवाडेकर,
आपका फिज़ियोथेरेपी अपॉईंटमेंट 03/05/2026 को शाम 5:45 (17:45) बजे डॉ. रेवंत कुलकर्णी के साथ निश्चित है। कृपया 15 मिनट पहले पहुंचें। खाली पेट आने की जरूरत नहीं है।
पुनर्निर्धारण के लिए 080-4712-8396 पर कॉल करें। फैक्स: 080-4712-8397।
रोगी आईडी: NFP-58214। संदेश भेजने की तिथि: 01/05/2026।
यह संदेश केवल निर्धारित रोगी के लिए है। इसमें दी गई चिकित्सकीय जानकारी गोपनीय है; बिना अनुमति साझा या प्रतिलिपि न करें। यदि संदेश गलत नंबर पर पहुंचा है तो कृपया तुरंत क्लिनिक को सूचित करें और इसे हटा दें। अपॉइंटमेंट में बदलाव केवल क्लिनिक की पुष्टि के बाद मान्य होगा। अधिक जानकारी के लिए www.nisargphysio.example देखें। सदस्यता हटाने के लिए STOP लिखकर 560070 प
shape of the answer
{"invoice_number": "INV-2041", "date": "2026-03-14", "total": 412.5, ...}

Real cases from the held-out set, never seen in training.

A Japanese support chat becomes a ticket
Date: 2026年11月2日 10:14

三宅 千尋: 昨日ソファが届いたのですが、背もたれの右側面にヒビが入っていて...
…
三宅 千尋: 商品は リバーサイド 3人掛けソファ(モスグリーン)です。到着日は2026年10月31日。

In English: The email is from 2 November. The customer says the sofa arrived on 31 October with a crack in the backrest.

✕ Before training
"category": "technical",
"issue_start_date": "2026-11-02"

Uses the date of the email, and files a cracked sofa as a technical fault.

✓ After training, L-01
"category": "product_defect",
"issue_start_date": "2026-10-31"

The day the sofa arrived, filed as a damaged product.

A Hindi clinic text becomes an appointment
प्रिय सौम्या बेलवाडेकर,
आपका फिज़ियोथेरेपी अपॉईंटमेंट 03/05/2026 को शाम 5:45 (17:45) बजे डॉ. रेवंत कुलकर्णी के साथ निश्चित है।
…
रोगी आईडी: NFP-58214

In English: Dear Saumya Belwadekar, your physiotherapy appointment is on 3 May 2026 at 17:45 with Dr Revant Kulkarni. Patient ID NFP-58214.

✕ Before training
"title": "Medical appointment reminder",
"patient_name": "सौम्या बेलवाडेकर",
"appointment_time": "17:45",
…
"additionalProperties": false

Fills the form, then adds two fields copied from its instructions. The form does not allow them.

✓ After training, L-01
"patient_name": "सौम्या बेलवाडेकर",
"appointment_time": "17:45",
"patient_id": "NFP-58214",
…

Only the fields the form asks for.

A German badge scan becomes a contact
✕ Before training
{"title": "Contact card / email signature",
 "type": "object",
 "properties": {"full_name": "Nadja Wüthrich", …}}

Sends back the empty form with the answers stuffed inside it. Scores zero.

✓ After training, L-01
{"full_name": "Nadja Wüthrich",
 "job_title": "Senior Immobilienberaterin",
 "company": "Limmatblick Immobilien AG",
 "address": "Sihlblickstrasse 14, 8004 Zürich", …}

A filled-in contact, ready to save.

Base model Qwen/Qwen3.5-0.8B
Method GRPO with LoRA on the Surogate engine
Steps 60
Batch 16 documents × 8 tries each
Answer length up to 512 tokens, context 2,048
Hardware one 48 GB L40S
Time 27 minutes

LiquidAI/structured-extraction (Apache-2.0): 5,888 documents to train on, all 500 test documents held out. 30 document types, 16 languages, 6 to 13 fields each.

The share of top-level fields that come out right after normalising (dates YYYY-MM-DD, times HH:MM, amounts as numbers). Broken JSON scores 0. A missing field scores 0.

Trained with the open-source Surogate engine (1.5.17 or later), kit extract. Full kit notes: Surogate extract kit.

Terminal window
CUDA_VISIBLE_DEVICES=0 surogate grpo-colocate \
--train examples/kits/extract/train.yaml \
--infer examples/kits/extract/infer.yaml \
--orch examples/kits/extract/orch.yaml

The held-out score shows in the log as Avg@1= and the adapter lands in outputs/kits/extract/. To point it at your data, read Retrain on your data.

67.6%base
84.5%step 20
86.4%step 40
87.8%step 60

Top-level fields right on 500 held-out documents. The 14 documents longer than the context count as wrong before and after. One run, one seed.

  • Fourteen test documents do not fit in 2,000 tokens. They count as wrong before and after; none were removed.
  • Inbox to CRM. Signatures, badge scans and contact emails into clean contact records.
  • Receipts and invoices to rows. Dates, totals and currencies normalised the way your schema asks.
  • Private documents, offline. It runs on a laptop, so contracts and patient letters never leave the machine.

Open small models for every industry, free to run offline. Custom ones for companies.

superbirdlabs.com Custom models Hugging Face hello@superbirdlabs.com