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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
---
license: apache-2.0
license_link: https://huggingface.co/numind/NuExtract3/blob/main/LICENSE
library_name: transformers
pipeline_tag: image-to-text
tags:
- image-text-to-text
- transformers
- safetensors
- qwen3_5
- vision-language
- vlm
- document-understanding
- structured-extraction
- information-extraction
- ocr
- document-to-markdown
- markdown
- rag
- reasoning
- multilingual
- conversational
base_model:
- Qwen/Qwen3.5-4B
model_name: NuExtract3
---

<p align="center">
    <a href="https://nuextract.ai/">
        <img src="header.svg" width="900px"/>
    </a>
</p>


<p align="center">
        🖥️ <a href="https://nuextract.ai/">API / Platform</a>&nbsp;&nbsp; | &nbsp;&nbsp;
        📑 <a href="https://numind.ai/blog">Blog</a>&nbsp;&nbsp; | &nbsp;&nbsp;
        🗣️ <a href="https://discord.gg/3tsEtJNCDe">Discord</a>&nbsp;&nbsp; | &nbsp;&nbsp;
        🛠️ <a href="https://github.com/numindai/nuextract">GitHub</a>
</p>

**NuExtract3** is a unified **4B** vision-language reasoning model for document understanding.

It combines strong **structured information extraction** with high-quality **image-to-Markdown** conversion, making it suitable for extraction pipelines, OCR, and RAG preprocessing for all types of documents such as scans, receipts, forms, invoices, contracts or tables.

Try it out in [the 🤗 space!](https://huggingface.co/spaces/numind/NuExtract-3-4B)

## Overview

- **Structured extraction**: input (text/images) + JSON template + instructions --> JSON output
- **Markdown conversion**: input (text/images) --> Markdown
- **Multimodal inputs**: text, images, or text + images.
- **Multilingual** documents.
- **Reasoning** and non-reasoning inference modes.
- **Template generation** for structured extraction from natural language or input document.

# Benchmark results

## Structured Extraction

We benchmarked NuExtract on NuMind's internal structured benchmark, measuring model's performances on ~600 documents of diverse types including invoices, movie posters or floor plans. These documents and their ground-truth cover diverse use-cases testing model visual understanding, OCR, reasoning and ability to handle long input and output contexts.
We plan to open-source this benchmark in the coming weeks, along with a extensive leaderboard including most popular open-weight and closed-sourced APIs and a Python library allowing to easily measure model performances on structured extraction.

<img src="st.svg" width="1000"/>

To measure a pair of predicted and ground-truth JSONs, we represent both as trees which we align based on node names, compute metric scores for aligned leaves and report the average of these scores. `string` and `verbatim-string` leaves are evaluated with indel distance (i.e. Levenshtein without replacement), while all others are evaluated with exact-match.
Models were evaluated using vllm, with a temperature of 0.25 and a maximum of 65000 output token (for both thinking and answer), which largely exceeds 22000 which is the number of tokens of the largest ground truth output.

<figure>

|Model name          |Average score|Num. failed⁽¹⁾|Avg. num tokens thinking|Avg. num tokens answer|
|--------------------|-------------|-----------|------------------------|----------------------|
|NuExtract3.4_4B-RL  |**0.651 ± 0.019**|27     |2036                    |1856                  |
|gemma-4-E4B-it      |0.538 ± 0.023|31         |3005                    |1287                  |
|Qwen3.5-9B          |0.479 ± 0.030|170        |22409                   |1257                  |
|Qwen3.5-4B          |0.417 ± 0.031|229        |27177                   |1201                  |
|GLM-4.6V-Flash      |0.435 ± 0.026|153        |2989                    |1357                  |
|Nemotron-3-Nano-Omni|0.387 ± 0.028|204        |25827                   |522                   |
|Ministral-3-3B      |0.240 ± 0.022|344        |27586                   |362                   |

<figcaption>
<small>
(1) number of model outputs that were not JSON deserializable, either directly or by removing leading and trailing backticks.<br>
95% confidence intervals computed using a nonparametric bootstrap over scores distributions.
</small>
</figcaption>
</figure>

The benchmark include samples containing multiple images resulting in large input context, and some with ground-truth containing large numbers of items to extract resulting in large outputs. We found that the reasoning of small models significantly negatively impact their performances. The reason is that many models ended up falling in repetition loops, hitting the output tokens limit and resulting in failed requests.

## Document to Markdown

NuExtract can also convert document images into clean Markdown. Output will be Markdown for text (headers etc), HTML for tables, LaTeX for math and ```<figure data-type="image" data-id="img_n"><img src="/NM-dev/model_card-A/resolve/main/img_n.png" alt="Detail description of the images"/> ```

Modern, format-agnostic benchmarks for complex document understanding are limited, so we explored a new evaluation approach.
We selected 100 documents with challenging layouts and tables, asked each model to convert them into a structured representation, then used Gemini 3 Flash to compare model outputs against the source document and choose the most accurate result.
The rankings aligned with human votes, suggesting this is a promising method for evaluating document-to-Markdown capabilities. More details will be shared in an upcoming technical report.
Here are some results:

<img src="ocr_preferences.svg" width="1000"/>

### Using "Markdown-to-structured"

To add other evaluate references, we used our structured extraction benchmark to evaluate models in a two-step fashion: convert the benchmark inputs to Markdown, then use Qwen3.6 27B to perform the structured extraction task on them. Intuitively, it allows to evaluate how models achieve to keep the input document content and layout: good models will allow the "structured extractor" model to perform better scores.

<img src="md2st.svg" width="1000"/>


# Using NuExtract

## Structured extraction

Structured extraction takes as inputs:

1. An input document, which can be text, image, or both;
2. A JSON template describing the information to extract;
3. (Optional) Instructions, allowing to specify expected output formats or values, to provide with the `instructions` chat template kwarg;
4. (Optional) In-Context Learning (ICL) examples.

### Input JSON template

NuExtract uses a input JSON template whose structure is identical to the output JSON. Its leaf values are specify the **types** of the output JSON leaves. For examples:

```json
{
  "invoice_number": "verbatim-string",
  "invoice_date": "date",
  "total_amount": "number",
  "currency": "currency",
  "line_items": [
    {
      "description": "verbatim-string",
      "item_type": ["electronics", "clothing", "vehicle", "furniture", "other"],
      "quantity": "integer",
      "unit_price": "number",
      "total": "number"
    }
  ]
}
```

Supported template types include:

- `verbatim-string`: extract text exactly as it appears in the document;
- `string`: generic string field, allowing abstraction or light paraphrasing;
- `integer`: whole number;
- `number`: integer or decimal number;
- `date-time`: ISO-8601 date, time or date-time;
- Other specific types such as `data`, `time`, `country`, `currency`, `email` and so on.
[**For more details, read the complete types specifications and examples**](TYPES.md)

Template constructors:

- Arrays, for example `["string"]`;
- Enums, for example `["yes", "no", "maybe"]`;
- Multi-enums (multiple possible values), for example `[["A", "B", "C"]]`.

If the model does not find relevant information for a field, it returns `null` or `[]`.

### Converting JSON schema / Pydantic models to NuExtract template

Our Python SDK (`pip install numind`) offers a method to convert JSON schemas to NuExtract templates:

```Python
from typing import Literal

from pydantic import Field, BaseModel
from numind.nuextract_utils import convert_json_schema_to_nuextract_template


class HotelBooking(BaseModel):
    city: str
    check_in_date: str = Field(description="date")
    check_out_date: str = Field(description="date")
    number_of_guests: int
    room_type: Literal["single", "double", "suite"]


template, dropped_branches = convert_json_schema_to_nuextract_template(
    HotelBooking.model_json_schema()
)

# {'check_in_date': 'date', 'check_out_date': 'date', 'city': 'string', 'number_of_guests': 'integer', 'room_type': ['single', 'double', 'suite']}
```

## Document-to-Markdown

NuExtract can also convert document images into clean Markdown. Output will be markdown for text (headers etc), html for tables, latex for mat and ```<figure data-type="image" data-id="img_n"><img src="/NM-dev/model_card-A/resolve/main/img_n.png" alt="Detail description of the images"/> ```

Markdown example:

```markdown
<figure data-type="image" data-id="img_1">
  <img src="img_1.png" alt="Logo of Mobilier 2000 with contact information: Tél.: (418) 275-4232, 1654, boul. Marcotte, Roberval (Qc) G8H 2P2"/>
</figure>

# COMMANDE
**NUMÉRO 72259**

1

**Vendu à**
TREMBLAY ERIC
ERIC TREMBLAY
348 BOUL. DE L'ANSE
ROBERVAL
G8H 1Y9

**Livré à**
TREMBLAY ERIC
ERIC TREMBLAY
348 BOUL. DE L'ANSE
ROBERVAL
G8H 1Y9

<table>
  <thead>
    <tr>
      <th># CLIENT</th>
      <th>EXPÉDITEUR</th>
      <th>TERME DE CRÉDIT</th>
      <th>DATE</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>2753133</td>
      <td>Notre camion</td>
      <td>à la livraison</td>
      <td>22/06/2023</td>
    </tr>
  </tbody>
</table>

<table>
  <thead>
    <tr>
      <th>NOM DU VENDEUR</th>
      <th>VOTRE ÉCONOMIE !</th>
      <th># COMMANDE</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Éric</td>
      <td>0.00</td>
      <td></td>
    </tr>
  </tbody>
</table>
```

---

## Reasoning and non-reasoning modes

NuExtract supports both reasoning and non-reasoning inference.

### Non-thinking mode

Use this for fast and deterministic extraction or Markdown conversion.

```python
enable_thinking = False
temperature = 0.2
```

### Thinking mode

Use this for difficult documents, complex layouts, ambiguous fields, or cases where the document structure requires additional reasoning.

```python
enable_thinking = True
temperature = 0.6
```

For production extraction workloads, we recommend starting with **non-reasoning mode** and enabling reasoning only for difficult examples.


---

## vLLM deployment

NuExtract can be served with vLLM using an OpenAI-compatible API.

```bash
vllm serve numind/NuExtract3 \
  --trust-remote-code \
  --limit-mm-per-prompt '{"image": 99, "video": 0}' \
  --chat-template-content-format openai \
  --generation-config vllm \
  --max-model-len 131072 \
  --speculative-config '{"method": "qwen3_next_mtp", "num_speculative_tokens": 2}'
```


### Multi Token Prediction
<details>
The deployment commands above enable Multi Token Prediction (MTP) through vLLM speculative decoding:

```bash
--speculative-config '{"method": "qwen3_next_mtp", "num_speculative_tokens": 2}'
```

MTP can improve decoding throughput without changing the OpenAI-compatible request payload. You can tune `num_speculative_tokens` for your hardware and workload, or remove `--speculative-config` if your vLLM version or environment does not support this speculative decoding method.

If you encounter memory issues, reduce the maximum model length and the maximum number of images:

```bash
vllm serve numind/NuExtract-3 \
  --trust-remote-code \
  --limit-mm-per-prompt '{"image": 6, "video": 0}' \
  --chat-template-content-format openai \
  --generation-config vllm \
  --max-model-len 16384 \
  --speculative-config '{"method": "qwen3_next_mtp", "num_speculative_tokens": 2}'
```
</details>

## vLLM inference: structured extraction: text
```python
import json
from openai import OpenAI

client = OpenAI(
    api_key="EMPTY",
    base_url="http://localhost:8000/v1",
)

template = {
    "store": "verbatim-string",
    "date": "date-time",
    "total": "number",
    "currency": ["USD", "EUR", "GBP", "JPY", "Other"],
    "items": [
        {
            "name": "verbatim-string",
            "price": "number"
        }
    ]
}

response = client.chat.completions.create(
    model="numind/NuExtract3",
    temperature=0.2,
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "Yesterday I bought apples and coffee at Trader Joe's for a total of $12.40."
                }
            ],
        }
    ],
    extra_body={
        "chat_template_kwargs": {
            "template": json.dumps(template),
            "instructions": "Specify the time for the `date` entry only if it is present, otherwise only output the date component.",
            "enable_thinking": False
        }
    }
)

print(response.choices[0].message.content)
```

Example output:

```json
{
  "store": "Trader Joe's",
  "date": null,
  "total": 12.40,
  "currency": "USD",
  "items": [
    {
      "name": "apples",
      "price": null
    },
    {
      "name": "coffee",
      "price": null
    }
  ]
}
```

---

## vLLM inference: structured extraction: image

```python
import json
import base64
from openai import OpenAI

client = OpenAI(
    api_key="EMPTY",
    base_url="http://localhost:8000/v1",
)

def encode_image(image_path):
    with open(image_path, "rb") as image_file:
        return base64.b64encode(image_file.read()).decode("utf-8")

image_base64 = encode_image("receipt.png")
data_url = f"data:image/png;base64,{image_base64}"

template = {
    "store": "verbatim-string",
    "date": "date-time",
    "total": "number",
    "payment_method": "verbatim-string"
}

response = client.chat.completions.create(
    model="numind/NuExtract3",
    temperature=0.2,
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": {"url": data_url}
                }
            ],
        }
    ],
    extra_body={
        "chat_template_kwargs": {
            "template": json.dumps(template, indent=4),
            "enable_thinking": False
        }
    }
)

print(response.choices[0].message.content)
```

Example output:

```json
{
  "store": "Trader Joe's",
  "date": "2025-04-12",
  "total": 42.85,
  "payment_method": "Visa"
}
```

### Multiple page PDF
<details>
You can render a PDF to one PNG image per page with PyMuPDF, then pass the images to vLLM in page order.

```python
import base64
import json

import fitz  # pip install pymupdf
from openai import OpenAI

client = OpenAI(
    api_key="EMPTY",
    base_url="http://localhost:8000/v1",
)

def pdf_to_png_data_urls(pdf_path, dpi=170):
    data_urls = []

    with fitz.open(pdf_path) as doc:
        for page in doc:
            pix = page.get_pixmap(dpi=dpi, alpha=False)
            png_bytes = pix.tobytes("png")
            png_base64 = base64.b64encode(png_bytes).decode("utf-8")
            data_urls.append(f"data:image/png;base64,{png_base64}")

    return data_urls

data_urls = pdf_to_png_data_urls("invoice.pdf", dpi=170)

template = {
    "invoice_number": "verbatim-string",
    "invoice_date": "date",
    "total": "number",
    "currency": "currency",
    "line_items": [
        {
            "description": "verbatim-string",
            "quantity": "number",
            "unit_price": "number",
            "total": "number"
        }
    ]
}

response = client.chat.completions.create(
    model="numind/NuExtract3",
    temperature=0.2,
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": {"url": data_url}
                }
                for data_url in data_urls
            ],
        }
    ],
    extra_body={
        "chat_template_kwargs": {
            "template": json.dumps(template, indent=4),
            "enable_thinking": False
        }
    }
)

print(response.choices[0].message.content)
```
</details>



## vLLM inference: document-to-Markdown

For Markdown OCR, use `mode="markdown"` or `mode="content"` without a template.

```python
import base64
from openai import OpenAI

client = OpenAI(
    api_key="EMPTY",
    base_url="http://localhost:8000/v1",
)

def encode_image(image_path):
    with open(image_path, "rb") as image_file:
        return base64.b64encode(image_file.read()).decode("utf-8")

image_base64 = encode_image("document.png")
data_url = f"data:image/png;base64,{image_base64}"

response = client.chat.completions.create(
    model="numind/NuExtract3",
    temperature=0,
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": {"url": data_url}
                }
            ],
        }
    ],
    extra_body={
        "chat_template_kwargs": {
            "mode": "markdown",
            "enable_thinking": False
        }
    }
)

print(response.choices[0].message.content)
```

---

## vLLM inference: reasoning mode
<details>
Reasoning can be enabled for harder structured extraction or Markdown tasks.

```python
response = client.chat.completions.create(
    model="numind/NuExtract3",
    temperature=0.7,
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "image_url",
                    "image_url": {"url": data_url}
                }
            ],
        }
    ],
    extra_body={
        "chat_template_kwargs": {
            "mode": "markdown",
            "enable_thinking": True
        }
    }
)

result = response.choices[0].message.content

if "</think>" in result:
    reasoning = result.split("<think>")[1].split("</think>")[0]
    answer = result.split("</think>")[-1].strip()
else:
    reasoning = None
    answer = result

print(answer)
```
</details>


## In-context examples for extraction
<details>
NuExtract supports in-context examples for structured extraction.

Examples are especially useful when the desired formatting is ambiguous or when the schema requires task-specific conventions. Examples can be provided by using `developer` messages, for which all items of the contents except the last one are the input, and the last one is the expected output.

```python
import json
from openai import OpenAI

client = OpenAI(
    api_key="EMPTY",
    base_url="http://localhost:8000/v1",
)

template = {
    "names": ["string"]
}

response = client.chat.completions.create(
    model="numind/NuExtract3",
    temperature=0,
    messages=[
        {
            "role": "developer",
            "content": [
                {
                    "type": "text",
                    "text": "Stephen is the manager at Susan's store.",
                },
                {
                    "type": "text",
                    "text": "{\"names\": [\"-STEPHEN-\", \"-SUSAN-\"]}",
                }
            ],
        },
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "John went to the restaurant with Mary. James went to the cinema."
                }
            ],
        }
    ],
    extra_body={
        "chat_template_kwargs": {
            "template": json.dumps(template, indent=4),
            "enable_thinking": False
        }
    }
)

print(response.choices[0].message.content)
```

Example output:

```json
{
  "names": ["-JOHN-", "-MARY-", "-JAMES-"]
}
```
</details>


## vLLM inference: template generation

NuExtract can generate an extraction template from a natural language description.

```python
from openai import OpenAI

client = OpenAI(
    api_key="EMPTY",
    base_url="http://localhost:8000/v1",
)

response = client.chat.completions.create(
    model="numind/NuExtract3",
    temperature=0,
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "I want to extract the key details from a rental contract."
                }
            ],
        }
    ],
    extra_body={
        "chat_template_kwargs": {
            "mode": "template-generation"
        }
    }
)

print(response.choices[0].message.content)
```

Example output:

```json
{
  "contract_title": "verbatim-string",
  "landlord": "verbatim-string",
  "tenant": "verbatim-string",
  "property_address": "verbatim-string",
  "start_date": "date-time",
  "end_date": "date-time",
  "monthly_rent": "number",
  "currency": "verbatim-string",
  "deposit": "number",
  "signatories": ["verbatim-string"]
}
```

## Curl examples
<details>

The following examples assume that vLLM is running locally on port 8000. They use `jq` to build valid JSON request bodies without manually escaping the image data or template string.

### Single image structured extraction

```bash
API_KEY="EMPTY"
IMAGE_BASE64_FILE=$(mktemp)
REQUEST_BODY_FILE=$(mktemp)

base64 < receipt.png | tr -d '\n' > "$IMAGE_BASE64_FILE"

TEMPLATE=$(cat <<'JSON'
{
  "store": "verbatim-string",
  "date": "date-time",
  "total": "number",
  "payment_method": "verbatim-string"
}
JSON
)

jq -n \
  --rawfile image_base64 "$IMAGE_BASE64_FILE" \
  --arg template "$TEMPLATE" \
  '{
    model: "numind/NuExtract3",
    temperature: 0,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "image_url",
            image_url: {url: ("data:image/png;base64," + $image_base64)}
          }
        ]
      }
    ],
    chat_template_kwargs: {
      template: $template,
      enable_thinking: false
    }
  }' > "$REQUEST_BODY_FILE"

curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  --data-binary "@$REQUEST_BODY_FILE"

rm "$IMAGE_BASE64_FILE" "$REQUEST_BODY_FILE"
```

### Single image content extraction

```bash
API_KEY="EMPTY"
IMAGE_BASE64_FILE=$(mktemp)
REQUEST_BODY_FILE=$(mktemp)

base64 < document.png | tr -d '\n' > "$IMAGE_BASE64_FILE"

jq -n \
  --rawfile image_base64 "$IMAGE_BASE64_FILE" \
  '{
    model: "numind/NuExtract3",
    temperature: 0,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "image_url",
            image_url: {url: ("data:image/png;base64," + $image_base64)}
          }
        ]
      }
    ],
    chat_template_kwargs: {
      mode: "content",
      enable_thinking: false
    }
  }' > "$REQUEST_BODY_FILE"

curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  --data-binary "@$REQUEST_BODY_FILE"

rm "$IMAGE_BASE64_FILE" "$REQUEST_BODY_FILE"
```
</details>


## Transformers example
<details>
You can also run NuExtract directly with `transformers`. The same `template`, `mode`, and `enable_thinking` options are passed to `processor.apply_chat_template`.

```python
import json

import torch
from PIL import Image
from transformers import AutoModelForImageTextToText, AutoProcessor

model_id = "numind/NuExtract3"

processor = AutoProcessor.from_pretrained(
    model_id,
    trust_remote_code=True,
)
model = AutoModelForImageTextToText.from_pretrained(
    model_id,
    dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True,
).eval()

def run_nuextract(messages, **chat_template_kwargs):
    inputs = processor.apply_chat_template(
        messages,
        add_generation_prompt=True,
        tokenize=True,
        return_dict=True,
        return_tensors="pt",
        **chat_template_kwargs,
    ).to(model.device)

    with torch.inference_mode():
        generated_ids = model.generate(
            **inputs,
            max_new_tokens=4096,
            do_sample=False,
        )

    generated_ids = generated_ids[:, inputs.input_ids.shape[1]:]
    return processor.batch_decode(
        generated_ids,
        skip_special_tokens=True,
        clean_up_tokenization_spaces=False,
    )[0].strip()

# Single image structured extraction
receipt_image = Image.open("receipt.png").convert("RGB")
receipt_messages = [
    {
        "role": "user",
        "content": [
            {
                "type": "image",
                "image": receipt_image,
            }
        ],
    }
]

template = {
    "store": "verbatim-string",
    "date": "date-time",
    "total": "number",
    "payment_method": "verbatim-string"
}

structured_output = run_nuextract(
    receipt_messages,
    template=json.dumps(template, indent=4),
    enable_thinking=False,
)
print(structured_output)

# Single image content extraction
document_image = Image.open("document.png").convert("RGB")
document_messages = [
    {
        "role": "user",
        "content": [
            {
                "type": "image",
                "image": document_image,
            }
        ],
    }
]

content_output = run_nuextract(
    document_messages,
    mode="content",
    enable_thinking=False,
)
print(content_output)
```
</details>

Special thanks to the Lambda.ai team for the compute that made this project a success.

## Citation

If you use NuExtract, please cite NuMind and link to the model page.

```bibtex
@misc{nuextract3,
  title = {NuExtract3},
  author = {NuMind},
  year = {2026},
  url = {https://nuextract.ai/}
}
```