Instructions to use gradients-ai-1/Reflex-2B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use gradients-ai-1/Reflex-2B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="gradients-ai-1/Reflex-2B", trust_remote_code=True) 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("gradients-ai-1/Reflex-2B", trust_remote_code=True) model = AutoModelForMultimodalLM.from_pretrained("gradients-ai-1/Reflex-2B", trust_remote_code=True, 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use gradients-ai-1/Reflex-2B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "gradients-ai-1/Reflex-2B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gradients-ai-1/Reflex-2B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/gradients-ai-1/Reflex-2B
- SGLang
How to use gradients-ai-1/Reflex-2B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "gradients-ai-1/Reflex-2B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gradients-ai-1/Reflex-2B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "gradients-ai-1/Reflex-2B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "gradients-ai-1/Reflex-2B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use gradients-ai-1/Reflex-2B with Docker Model Runner:
docker model run hf.co/gradients-ai-1/Reflex-2B
Reflex-2B
Reflex-2B extracts structured data from documents. Give it a page (a photo, scan, screenshot, PDF or text) and the fields you need; it returns one JSON object with typed values.
- Size: 2B parameters.
- Field types: text, number, date, time, datetime, boolean, enum, object, list.
- Output: JSON matching the schema. Missing values are
null; dates are ISO 8601.
What it's for
- Invoices, receipts, purchase orders and other business documents
- Phone photos, scans and handwritten documents
- Multi-page PDFs with long tables
- Answering questions about a page
- Pulling typed fields out of emails, contracts and other text
You define the fields; there is no fixed schema.
Results
| Benchmark | Metric | Reflex-2B | Clairic Flash 9B |
|---|---|---|---|
| SROIE 2019 test (240 receipts) | Fields correct | 92.6% | 89.3% |
| DocVQA validation (500 questions) | ANLS | 0.933 | 0.920 |
Both models were run on the same documents with the same scorer.
Usage
Serve the model with vLLM:
vllm serve gradients-ai-1/Reflex-2B --trust-remote-code --max-model-len 16384
Then extract with reflex_runtime, the small Python package that ships in this repository:
pip install huggingface_hub pillow pypdfium2
import sys
from huggingface_hub import snapshot_download
sys.path.insert(0, snapshot_download("gradients-ai-1/Reflex-2B", allow_patterns=["reflex_runtime/*"]))
from reflex_runtime import Extractor
from reflex_runtime.backends import OpenAIBackend
ex = Extractor(OpenAIBackend()) # vLLM on localhost:8000, serving gradients-ai-1/Reflex-2B
ex.extract(source, fields) accepts a PDF, an image file, a PIL image, a list of page images, a text file or a plain
string. Every call returns result.answer (the JSON), result.confidence (per value) and result.pages (the page
each value came from).
Phone photo of a receipt
result = ex.extract("receipt.jpg", {
"store_name": {"type": "text"},
"date": {"type": "date"},
"total": {"type": "number", "description": "Amount paid, including tax"},
})
# {"store_name": "ใใใช", "date": "2026-09-05", "total": 1210}
Scanned or digital PDF, several pages
result = ex.extract("statement.pdf", {
"account_holder": {"type": "text"},
"period_end": {"type": "date"},
"transactions": {"type": "list", "items": {"type": "object", "fields": {
"date": {"type": "date"},
"description": {"type": "text"},
"amount": {"type": "number", "description": "Negative for money going out"},
}}},
})
len(result.answer["transactions"]) # rows from every page, in order
result.pages["period_end"] # page the value was read from
Pages with a text layer are read as text and scanned pages as images. Pass mode="image" or mode="text" to force
one.
Several photos of one document
result = ex.extract(["page1.jpg", "page2.jpg", "page3.jpg"], fields)
Each photo is treated as one page, in the order given.
Plain text: an email
email = """Hi team, please book the venue for our offsite next Friday.
Budget is EUR 4,500 for 25 people. Contact: Maria Lopez, +34 600 123 456."""
result = ex.extract(email, {
"event_date": {"type": "date", "description": "Date of the event"},
"budget": {"type": "number"},
"currency": {"type": "text", "description": "ISO 4217 code"},
"attendees": {"type": "number"},
"contact_name": {"type": "text"},
}, reference_date="2026-11-23")
# {"event_date": "2026-11-27", "budget": 4500, "currency": "EUR", "attendees": 25, "contact_name": "Maria Lopez"}
reference_date lets the model resolve relative dates such as "next Friday".
Screenshot or image already in memory
from PIL import Image
result = ex.extract(Image.open("screenshot.png"), {
"order_id": {"type": "text"},
"delivery_date": {"type": "date"},
"items_count": {"type": "number"},
})
Questions about a page
A field's description can be a question:
result = ex.extract("letter.jpg", {
"university": {"type": "text", "description": "What is the name of the university?"},
"signed": {"type": "boolean", "description": "Is the letter signed?"},
})
result.answer["university"] # "University of California, San Diego"
Decisions and categories from a contract
result = ex.extract("contract.txt", {
"contract_type": {"type": "enum", "options": ["employment", "lease", "services", "nda", "other"]},
"auto_renews": {"type": "boolean"},
"notice_period_days": {"type": "number"},
"governing_law": {"type": "text", "description": "Country or state whose law applies"},
})
Without a server (transformers)
from reflex_runtime import Extractor
from reflex_runtime.backends import HFBackend # also needs: pip install torch transformers xgrammar
ex = Extractor(HFBackend())
result = ex.extract("invoice.png", {"invoice_number": {"type": "text"}, "total": {"type": "number"}})
vLLM is faster for batches and long documents; transformers is simpler for a quick test.
Defining fields
Each field has a type and an optional description. A short description of what the field means usually helps more than a precise name.
fields = {
"vendor_name": {"type": "text", "description": "Company that issued the invoice"},
"invoice_date": {"type": "date"},
"currency": {"type": "enum", "options": ["USD", "EUR", "GBP", "other"]},
"is_paid": {"type": "boolean", "description": "True if the invoice is marked as paid"},
"bill_to": {"type": "object", "fields": {
"name": {"type": "text"},
"address": {"type": "text"},
}},
"line_items": {"type": "list", "items": {"type": "object", "fields": {
"description": {"type": "text"},
"quantity": {"type": "number"},
"amount": {"type": "number"},
}}},
}
| Type | Returned as |
|---|---|
text |
string, as written in the document |
number |
plain number, no currency symbols or thousands separators |
date, time, datetime |
ISO 8601 string |
boolean |
true or false |
enum |
one of the listed values |
object |
nested object with its own fields |
list |
array of values or objects, in document order |
Any field the document doesn't contain comes back as null rather than a guess.
Confidence scores
With reflex_runtime, every value gets two numbers:
confidence: how likely the value is to be correct, from 0 to 1p_null: how likely it is that the field is missing from the document
{"total": {"confidence": 0.93, "p_null": 0.0},
"due_date": {"confidence": 0.41, "p_null": 0.55}}
A practical setup is to accept values at or above 0.95 automatically and send the rest for review.
Multi-page documents
Send one page per request. reflex_runtime does this for you: it reads each page, joins tables that continue across pages
in order, and removes repeated header rows and carried-forward totals.
Hardware
The weights are about 3.8 GB. Reflex-2B runs on a single GPU and was tested on an NVIDIA L4 (24 GB) with vLLM.
License
Reflex-2B is a derivative of LFM3-VL-2B, modified by fine-tuning, and is distributed under the LFM Open License v1.0.
Citation
@misc{reflex2b,
title = {Reflex-2B: structured data extraction from documents},
author = {Gradients AI},
year = {2026},
url = {https://huggingface.co/gradients-ai-1/Reflex-2B}
}
- Downloads last month
- 12
