L-01 Document Extractor

87.8% fields right on 500 held-out documents, up from 67.6%
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.
Run it
Section titled “Run it”The weights are a LoRA adapter on top of Qwen/Qwen3.5-0.8B. Load both with transformers and peft.
-
Install
Terminal window pip install -U transformers peft accelerate -
Load and ask
run.py from transformers import AutoModelForCausalLM, AutoTokenizerfrom peft import PeftModelbase = "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 belowmessages = [{"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))
The prompt
Section titled “The prompt”Trained with this exact system prompt. Use it word for word: small models are picky about their instructions.
Extract the data in the user's document into a JSON object that matches this JSON Schema:{your JSON Schema here}निसर्ग फिज़ियोथेरेपी क्लिनिकप्रिय सौम्या बेलवाडेकर,आपका फिज़ियोथेरेपी अपॉईंटमेंट 03/05/2026 को शाम 5:45 (17:45) बजे डॉ. रेवंत कुलकर्णी के साथ निश्चित है। कृपया 15 मिनट पहले पहुंचें। खाली पेट आने की जरूरत नहीं है।पुनर्निर्धारण के लिए 080-4712-8396 पर कॉल करें। फैक्स: 080-4712-8397।रोगी आईडी: NFP-58214। संदेश भेजने की तिथि: 01/05/2026।यह संदेश केवल निर्धारित रोगी के लिए है। इसमें दी गई चिकित्सकीय जानकारी गोपनीय है; बिना अनुमति साझा या प्रतिलिपि न करें। यदि संदेश गलत नंबर पर पहुंचा है तो कृपया तुरंत क्लिनिक को सूचित करें और इसे हटा दें। अपॉइंटमेंट में बदलाव केवल क्लिनिक की पुष्टि के बाद मान्य होगा। अधिक जानकारी के लिए www.nisargphysio.example देखें। सदस्यता हटाने के लिए STOP लिखकर 560070 पWhat it answers with
Section titled “What it answers with”{"invoice_number": "INV-2041", "date": "2026-03-14", "total": 412.5, ...}Before and after
Section titled “Before and after”Real cases from the held-out set, never seen in training.
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.
"category": "technical", "issue_start_date": "2026-11-02"
Uses the date of the email, and files a cracked sofa as a technical fault.
"category": "product_defect", "issue_start_date": "2026-10-31"
The day the sofa arrived, filed as a damaged product.
प्रिय सौम्या बेलवाडेकर, आपका फिज़ियोथेरेपी अपॉईंटमेंट 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.
"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.
"patient_name": "सौम्या बेलवाडेकर", "appointment_time": "17:45", "patient_id": "NFP-58214", …
Only the fields the form asks for.
{"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.
{"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.
The recipe
Section titled “The recipe”| 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 |
The data
Section titled “The data”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 reward
Section titled “The reward”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.
Train it yourself
Section titled “Train it yourself”Trained with the open-source Surogate engine (1.5.17 or later), kit extract. Full kit notes: Surogate extract kit.
CUDA_VISIBLE_DEVICES=0 surogate grpo-colocate \ --train examples/kits/extract/train.yaml \ --infer examples/kits/extract/infer.yaml \ --orch examples/kits/extract/orch.yamlThe 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.
The scores
Section titled “The scores”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.
Where it fails
Section titled “Where it fails”- Fourteen test documents do not fit in 2,000 tokens. They count as wrong before and after; none were removed.
Where it fits
Section titled “Where it fits”- 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