arrochi112 commited on
Commit
3d9f5ca
Β·
verified Β·
1 Parent(s): 36dff8b

Add model card, benchmark charts, technical whitepaper

Browse files
.gitattributes CHANGED
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ graphs/accuracy_across_iterations.png filter=lfs diff=lfs merge=lfs -text
37
+ graphs/loss_convergence.png filter=lfs diff=lfs merge=lfs -text
38
+ graphs/throughput_vs_vram.png filter=lfs diff=lfs merge=lfs -text
39
+ SchemaForge_Whitepaper.pdf filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: apache-2.0
5
+ tags:
6
+ - distillation
7
+ - knowledge-distillation
8
+ - json-extraction
9
+ - structured-output
10
+ - information-extraction
11
+ - gemma-4
12
+ - minicpm5
13
+ - edge-ai
14
+ - schemaforge
15
+ pipeline_tag: text-generation
16
+ base_model: openbmb/MiniCPM5-1B
17
+ library_name: transformers
18
+ metrics:
19
+ - accuracy
20
+ - f1
21
+ - throughput
22
+ ---
23
+
24
+ # SchemaForge-1B β€” JSON Extractor
25
+
26
+ **A 1.08B-parameter edge SLM distilled from Gemma-4 for zero-shot enterprise JSON extraction.**
27
+
28
+ SchemaForge-1B converts unstructured business documents β€” invoices, bills of lading, requisitions, receipts β€” into strongly-typed, schema-conformant JSON. It was distilled from **`google/gemma-4-31B`** and **`google/gemma-4-E4B-it`** into **`openbmb/MiniCPM5-1B`** using a multi-task objective combining hard cross-entropy with temperature-scaled, log-space soft-logit KL divergence ($\alpha = 0.5$, $\tau = 2.0$), trained on an NVIDIA RTX PRO 6000 Blackwell Edition (96 GB).
29
+
30
+ | | 31B Teacher | **SchemaForge-1B** |
31
+ |---|---|---|
32
+ | In-domain JSON syntax error rate *(n = 5 docs)* | 0.0 % | **0.0 %** |
33
+ | In-domain extraction F1 *(n = 5 docs)* | 1.000 | **1.000** |
34
+ | Zero-shot validity (`suneeldk/text-json`) | β€” | **70.0 %** |
35
+ | Throughput | 12.40 tok/s | **61.91 – 76.27 tok/s** |
36
+ | Peak VRAM | β‰ˆ38.5 GB | **β‰ˆ2.4 GB** |
37
+ | Workers per 96 GB GPU | 2 | **36** |
38
+
39
+ **16.0Γ— smaller Β· 5.0Γ— faster Β· ~110Γ— aggregate system throughput**
40
+
41
+ ---
42
+
43
+ ## ⚠️ Read This First: The Prompt Template Is Not Optional
44
+
45
+ This model was distilled on **one exact prompt template**. Because it is a 1.08B student trained on a narrow task, it binds its behavior to the **literal surface form** of that prefix. In our experiments, changing only the instruction header dropped zero-shot validity from **70.0 % to 0.0 %** β€” worse than the *untrained* base model.
46
+
47
+ Use this string, byte for byte:
48
+
49
+ ```python
50
+ TEMPLATE = "Extract structured JSON from the text:\n{doc}\nJSON Output:"
51
+ ```
52
+
53
+ Do not wrap it in chat tokens. Do not prepend a system persona. Do not add a trailing newline. Treat it as a versioned API contract.
54
+
55
+ ---
56
+
57
+ ## πŸ“Š Benchmark Evidence
58
+
59
+ ### 1. Throughput and VRAM
60
+
61
+ ![Figure 1: Inference throughput vs VRAM footprint](https://huggingface.co/arrochi112/SchemaForge-1B-JSON-Extractor/resolve/main/graphs/throughput_vs_vram.png)
62
+
63
+ *Figure 1: **5.0Γ— throughput speedup** (61.91 vs. 12.40 tok/s, matched harness) and **16.0Γ— VRAM reduction** (β‰ˆ2.4 GB vs. β‰ˆ38.5 GB), measured on identical hardware.*
64
+
65
+ ### 2. Zero-shot accuracy across distillation iterations
66
+
67
+ ![Figure 2: Zero-shot JSON accuracy across iterations](https://huggingface.co/arrochi112/SchemaForge-1B-JSON-Extractor/resolve/main/graphs/accuracy_across_iterations.png)
68
+
69
+ *Figure 2: Validity on `suneeldk/text-json`. Iterations 1 and 3 differ from the winning Iteration 2 **only in prompt header** β€” and both collapse to 0.0 %.*
70
+
71
+ ### 3. Training convergence
72
+
73
+ ![Figure 3: Training loss convergence](https://huggingface.co/arrochi112/SchemaForge-1B-JSON-Extractor/resolve/main/graphs/loss_convergence.png)
74
+
75
+ *Figure 3: Loss over 3 epochs, Gemma-4-31B teacher. Iteration 2 (released): 9,132.9 β†’ 6,962.3 β†’ 6,612.7 (βˆ’27.6 %). Summed losses β€” comparable within a run, not across runs.*
76
+
77
+ ---
78
+
79
+ ## Quickstart
80
+
81
+ ```python
82
+ import torch
83
+ from transformers import AutoTokenizer, AutoModelForCausalLM
84
+
85
+ model_id = "arrochi112/SchemaForge-1B-JSON-Extractor"
86
+
87
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
88
+ model = AutoModelForCausalLM.from_pretrained(
89
+ model_id,
90
+ dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
91
+ ).to("cuda" if torch.cuda.is_available() else "cpu")
92
+ # No trust_remote_code needed β€” MiniCPM5-1B is a stock LlamaForCausalLM.
93
+
94
+ # CANONICAL TEMPLATE β€” do not modify
95
+ prompt = (
96
+ "Extract structured JSON from the text:\n"
97
+ "INVOICE #INV-1001. Vendor: Acme Supply Co. Date: 2026-04-10. "
98
+ "Subtotal: $480.00. Tax (8%): $38.40. Total: $518.40.\n"
99
+ "JSON Output:"
100
+ )
101
+
102
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
103
+ with torch.no_grad():
104
+ outputs = model.generate(**inputs, max_new_tokens=128, do_sample=False)
105
+
106
+ print(tokenizer.decode(outputs[0][inputs["input_ids"].size(1):],
107
+ skip_special_tokens=True))
108
+ ```
109
+
110
+ Expected:
111
+
112
+ ```json
113
+ {
114
+ "invoice_number": "INV-1001",
115
+ "vendor_name": "Acme Supply Co",
116
+ "invoice_date": "2026-04-10",
117
+ "subtotal": 480.00,
118
+ "tax": 38.40,
119
+ "grand_total": 518.40
120
+ }
121
+ ```
122
+
123
+ ---
124
+
125
+ ## Production Serving (vLLM)
126
+
127
+ ```python
128
+ from vllm import LLM, SamplingParams
129
+
130
+ llm = LLM(
131
+ model="arrochi112/SchemaForge-1B-JSON-Extractor",
132
+ dtype="bfloat16",
133
+ gpu_memory_utilization=0.90,
134
+ max_model_len=2048,
135
+ max_num_seqs=36, # 36 workers fit in 96 GB at 2.4 GB each
136
+ )
137
+
138
+ sampling_params = SamplingParams(temperature=0.0, max_tokens=256)
139
+
140
+ TEMPLATE = "Extract structured JSON from the text:\n{doc}\nJSON Output:"
141
+ docs = [
142
+ "Invoice #INV-881, Vendor: Globex Corp, Date: 2026-08-03, Total: $450.00",
143
+ "Invoice #INV-882, Vendor: Initech LLC, Date: 2026-08-04, Total: $1200.00",
144
+ ]
145
+
146
+ for out in llm.generate([TEMPLATE.format(doc=d) for d in docs], sampling_params):
147
+ print(out.outputs[0].text)
148
+ ```
149
+
150
+ ### Recommended: layer schema-constrained decoding
151
+
152
+ Distillation supplies *semantics*; FSM-guided decoding guarantees *syntax*. Run both.
153
+
154
+ ```python
155
+ from pydantic import BaseModel
156
+ from vllm.sampling_params import GuidedDecodingParams
157
+
158
+ class Invoice(BaseModel):
159
+ invoice_number: str
160
+ vendor_name: str
161
+ invoice_date: str
162
+ subtotal: float
163
+ tax: float
164
+ grand_total: float
165
+
166
+ sampling_params = SamplingParams(
167
+ temperature=0.0,
168
+ max_tokens=256,
169
+ guided_decoding=GuidedDecodingParams(json=Invoice.model_json_schema()),
170
+ )
171
+ ```
172
+
173
+ ---
174
+
175
+ ## Evaluation
176
+
177
+ ### Five-domain enterprise suite (in-domain, n = 5 documents)
178
+
179
+ | Domain | Document type | Base MiniCPM5-1B | **SchemaForge-1B** | F1 | Throughput |
180
+ |---|---|---|---|---|---|
181
+ | BMK-01 Finance | Tax invoices | 65.8 % | **100.0 %** | 1.000 | 61.91 tok/s |
182
+ | BMK-02 Supply chain | Bills of lading | 67.1 % | **100.0 %** | 1.000 | 62.40 tok/s |
183
+ | BMK-03 IT hardware | Procurement bills | 64.2 % | **100.0 %** | 1.000 | 61.80 tok/s |
184
+ | BMK-04 Biomedical | Lab requisitions | 66.5 % | **100.0 %** | 1.000 | 62.15 tok/s |
185
+ | BMK-05 Cloud ops | Billing records | 65.4 % | **100.0 %** | 1.000 | 62.05 tok/s |
186
+
187
+ ### Model comparison
188
+
189
+ | Variant | Teacher | JSON error rate | F1 | Throughput | VRAM |
190
+ |---|---|---|---|---|---|
191
+ | Base MiniCPM5-1B | none | 34.2 % | 0.612 | 62.00 tok/s | β‰ˆ2.4 GB |
192
+ | **SchemaForge-1B** | `gemma-4-E4B-it` | **0.0 %** | **1.000** | **61.91 tok/s** | **β‰ˆ2.4 GB** |
193
+ | **SchemaForge-1B** | `gemma-4-31B` | **0.0 %** | **1.000** | 56.12 tok/s | **β‰ˆ2.4 GB** |
194
+ | Gemma-4-31B | reference | 0.0 % | 1.000 | 12.40 tok/s | β‰ˆ38.5 GB |
195
+
196
+ Teacher scale conferred **no measurable quality advantage** on this task β€” the 4B teacher is the cost-effective choice.
197
+
198
+ ### Out-of-domain (`suneeldk/text-json`)
199
+
200
+ | Iteration | Prompt template | Validity | Throughput |
201
+ |---|---|---|---|
202
+ | iter1 | chat tokens (`<start_of_turn>`) | 0.0 % | 76.94 tok/s |
203
+ | **iter2 (this model)** | **canonical** | **70.0 %** | **76.27 tok/s** |
204
+ | iter3 | system persona header | 0.0 % | 74.12 tok/s |
205
+ | base | canonical | 34.2 % | 62.00 tok/s |
206
+
207
+ ---
208
+
209
+ ## Training Details
210
+
211
+ | | |
212
+ |---|---|
213
+ | Architecture | `LlamaForCausalLM` β€” 24 layers, hidden 1536, GQA 16/2 heads, vocab 130,560 |
214
+ | Parameters | 1,080,632,832 total (679,552,512 non-embedding) |
215
+ | Objective | $\mathcal{L}_{KD} = \alpha\mathcal{L}_{CE} + (1-\alpha)\tau^2\mathcal{L}_{KL}$ |
216
+ | $\alpha$ / $\tau$ | 0.5 / 2.0 |
217
+ | Vocabulary projection | 256,000 β†’ 130,560 (shared-subspace truncation) |
218
+ | Optimizer | AdamW, lr 2e-5, cosine, warmup 0.05 |
219
+ | Epochs | 3 (early-stopped on val loss) |
220
+ | Runtime | bfloat16, single-GPU PyTorch, eager attention (no ZeRO-3 / FlashAttention-2) |
221
+ | Max sequence length | 2,048 |
222
+ | Hardware | 1 Γ— NVIDIA RTX PRO 6000 Blackwell Edition (96 GB), Nebius AI Cloud |
223
+ | Software | Python 3.12 Β· PyTorch 2.5 Β· transformers 5.x |
224
+
225
+ Full methodology, mathematics, compatibility patches, and ablations: **[`SCHEMAFORGE_WHITEPAPER.md`](./SCHEMAFORGE_WHITEPAPER.md)**.
226
+
227
+ ---
228
+
229
+ ## Limitations
230
+
231
+ Please read these before deploying.
232
+
233
+ - **Evaluation scale is small.** The in-domain suite is **n = 5 documents** (one per domain). The 100 % validity / 1.000 F1 figures are exact-match results on a small curated set, not population estimates β€” the Wilson 95 % CI on 5/5 is **[56.6 %, 100.0 %]**.
234
+ - **Training scale is small.** This checkpoint was distilled on **n = 5 samples**. An SFT control ($\alpha = 1.0$, no teacher logits) was **not run**, so we cannot presently separate the contribution of knowledge distillation from that of prompt-format conditioning.
235
+ - **Single seed.** No variance estimates or error bars. Sub-2B models vary substantially run-to-run on small datasets.
236
+ - **Prompt-template brittleness.** The headline failure mode. Deviating from the canonical template drops accuracy to ~0, not to a degraded-but-usable level.
237
+ - **Out-of-domain ceiling β‰ˆ 70 %.** Roughly 30 % of unseen real-world documents produce unparseable output. Use constrained decoding in production.
238
+ - **Synthetic in-domain documents.** Clean ASCII, consistent labeling, no OCR noise, English-only. Real scanned documents will be harder.
239
+ - **Teacher outputs as targets.** Where the teacher was wrong, the student learned the error. No human-annotated gold standard exists for this checkpoint.
240
+ - **Not evaluated against alternatives.** No comparison to Qwen2.5-1.5B, Phi-3-mini, rule-based extractors, or commercial document-AI APIs.
241
+
242
+ **Intended use:** structured extraction from short English business documents, behind a schema-validation layer.
243
+ **Out of scope:** open-domain chat, reasoning, code, multilingual input, medical/legal decision-making, or any use where an unvalidated extraction reaches a system of record.
244
+
245
+ ### Planned v2 run
246
+
247
+ This is a **v1 release**, and the accuracy numbers above should be read as provisional. A second training and evaluation campaign is planned to address the limitations listed here directly:
248
+
249
+ - **Real-world evaluation corpus** replacing the synthetic 5-document suite β€” $n \geq 500$ held-out documents per domain, including OCR-noisy scans, multi-column layouts, and non-English fields, with a **human-annotated gold subset** so accuracy is no longer measured against teacher output.
250
+ - **The SFT control** ($\alpha = 1.0$, no teacher logits) to determine whether the distillation objective contributes anything beyond prompt-format conditioning.
251
+ - **Competitive baselines** β€” Qwen2.5-1.5B, Phi-3-mini, prompt-engineered base MiniCPM5-1B with constrained decoding, and a rule-based extractor β€” under one unified harness.
252
+ - **Multi-seed runs** (β‰₯3) with reported variance and confidence intervals on every metric.
253
+ - **Expanded metrics** beyond validity/F1/throughput/VRAM: per-field accuracy, schema-conformance rate, hallucinated-key rate, time-to-first-token, p50/p95 latency under concurrency, and cost per thousand documents.
254
+
255
+ Results will be published as a v2 card revision with the v1 numbers retained for comparison rather than quietly replaced.
256
+
257
+ ---
258
+
259
+ ## Citation
260
+
261
+ ```bibtex
262
+ @techreport{ty2026schemaforge,
263
+ title = {SchemaForge: Distilling Ultra-Large Foundation Models into Edge SLMs
264
+ for Real-Time Enterprise JSON Extraction --
265
+ A Comparative Study of Gemma-4 Teachers and MiniCPM5-1B},
266
+ author = {Ty, Arjhine A.},
267
+ year = {2026},
268
+ note = {Model: SchemaForge-1B (schemaforge-1b-iter2)},
269
+ url = {https://huggingface.co/arrochi112/SchemaForge-1B-JSON-Extractor}
270
+ }
271
+ ```
272
+
273
+ ## Acknowledgements
274
+
275
+ Teachers: `google/gemma-4-31B`, `google/gemma-4-E4B-it`. Student architecture: `openbmb/MiniCPM5-1B`. Compute: Nebius AI Cloud. Serving: vLLM. Constrained decoding: Outlines.
276
+
277
+ **License:** Apache 2.0 β€” subject to the upstream licenses of the base and teacher models.
SCHEMAFORGE_WHITEPAPER.md ADDED
The diff for this file is too large to render. See raw diff
 
SchemaForge_Whitepaper.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f4e2c4d4a82f0d9f0e06644cb570b80e17d1406eb2471a9288ed3326167a490
3
+ size 1017064
graphs/accuracy_across_iterations.png ADDED

Git LFS Details

  • SHA256: 7bfe8a3407eeff5d72fe718b9d9c9d4a24060ea98598fb31d104b4fe027ee305
  • Pointer size: 131 Bytes
  • Size of remote file: 125 kB
graphs/loss_convergence.png ADDED

Git LFS Details

  • SHA256: db2527a8044c56f4a40d6ab9a495a2c76548036fc0b71fe1b8e8800455f675e0
  • Pointer size: 131 Bytes
  • Size of remote file: 261 kB
graphs/throughput_vs_vram.png ADDED

Git LFS Details

  • SHA256: e4be797045bc4e98fc7d2925e8c6cc6a42c066dcfaf358078b1779929cfeae1b
  • Pointer size: 131 Bytes
  • Size of remote file: 135 kB