Image-Text-to-Text
Transformers
Safetensors
qwen3_vl
ocr
document-parsing
document-ai
layout
vision-language-model
conversational
Run this model with HF Jobs
Run hanji-dev/hanji-parse-4b on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/hanji-dev/hanji-parse-4b. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/hanji-dev/hanji-parse-4b on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/hanji-dev/hanji-parse-4b. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/hanji-dev/hanji-parse-4b. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use hanji-dev/hanji-parse-4b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use hanji-dev/hanji-parse-4b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="hanji-dev/hanji-parse-4b") 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("hanji-dev/hanji-parse-4b") model = AutoModelForMultimodalLM.from_pretrained("hanji-dev/hanji-parse-4b", 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 hanji-dev/hanji-parse-4b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "hanji-dev/hanji-parse-4b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "hanji-dev/hanji-parse-4b", "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/hanji-dev/hanji-parse-4b
- SGLang
How to use hanji-dev/hanji-parse-4b 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 "hanji-dev/hanji-parse-4b" \ --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": "hanji-dev/hanji-parse-4b", "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 "hanji-dev/hanji-parse-4b" \ --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": "hanji-dev/hanji-parse-4b", "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 hanji-dev/hanji-parse-4b with Docker Model Runner:
docker model run hf.co/hanji-dev/hanji-parse-4b
Trim model card
Browse files21 unmodified lines2223242526272829303116 unmodified lines4849505152535455565714 unmodified lines72737475767778123 unmodified lines20220320420520620720811 unmodified lines22022122222322422522622722822923010 unmodified lines24124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527621 unmodified linestranscribed text. Tables are transcribed as GitHub-Flavored Markdown inside asingle block. Figures, photos, and signatures are returned as image blocks.It was the production parsing model behind the Hanji document-extraction API.The accompanying open-source parse + schema-extraction server is available at**https://github.com/youlearn-ai/hanji**.## Output contractThe model returns **JSON only**: an array of records16 unmodified lines## Usage — read this before running the modelThe model is **tightly coupled to its serving contract**. It was trained andserved with one exact prompt, one image-preprocessing rule, and greedydecoding. Deviating from any of these produces off-distribution output.### 1. Image preprocessing- Downscale so the image is at most **2,000,000 pixels** (2 MP), preserving14 unmodified linesreturn img.convert("RGB").resize((w, h), Image.LANCZOS)```### 2. The prompt (use it verbatim)Send the page image followed by exactly this text as the user turn. Do notparaphrase, extend, or reformat it.123 unmodified linesprocessor = AutoProcessor.from_pretrained(MODEL)image = preprocess(Image.open("page.png")) # see preprocessing abovePROMPT = "..." # the exact prompt above, verbatimmessages = [{"role": "user",11 unmodified linesprint(processor.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))```### Serving (SGLang — the production configuration)The model was served with SGLang `v0.5.12.post1` on a single H100. N-gramspeculative decoding gives a large decode speedup on this output format (therepeated JSON keys draft extremely well):```bashpython -m sglang.launch_server \10 unmodified lines```A ready-to-run server that implements the full preprocessing + prompt contract(and a Baseten deployment config) ships with the open-source repo:https://github.com/youlearn-ai/hanji.## Training summary- Base: `Qwen/Qwen3-VL-4B-Instruct` (Apache-2.0). Language layers fine-tunedwith LoRA (r=32, α=64, all attention + MLP projections); the **vision towerwas frozen**. This repository contains the merged full weights (bf16).- 1,500 steps, effective batch 16, cosine schedule, images at up to 2 MPnative resolution.- ~16k supervised pages spanning synthetic and real business documents:forms, tables (including borderless and dense grids), checkbox and Y/Ngrids, multilingual and RTL pages, degraded scans and faxes, receipts, andcourt transcripts.## Limitations- **Prompt-coupled**: output quality degrades sharply off the exact prompt,preprocessing, and greedy decoding described above.- The base model was loaded from the `main` revision of`Qwen/Qwen3-VL-4B-Instruct` at training time (mid-2026) without a pinnedcommit; bit-exact re-derivation of the merge is therefore approximate.- Signatures and handwritten marks are deliberately returned as `<image>`blocks, never transcribed.- Blocks are page-scoped; the model does not merge tables that continueacross pages (the serving pipeline may do so downstream).- Not an instruction-following chat model: it does one task. For arbitrarydocument Q&A, pair it with a downstream LLM (the open-source repo pairs itwith a schema-extraction pass).## LicenseApache-2.0. Fine-tuned from21 unmodified lines22232425262716 unmodified lines44454647484914 unmodified lines64656667686970123 unmodified lines19419519619719819920011 unmodified lines21221321421521621721821922022110 unmodified lines23223323423523623723823924021 unmodified linestranscribed text. Tables are transcribed as GitHub-Flavored Markdown inside asingle block. Figures, photos, and signatures are returned as image blocks.## Output contractThe model returns **JSON only**: an array of records16 unmodified lines## Usage — read this before running the model### 1. Image preprocessing- Downscale so the image is at most **2,000,000 pixels** (2 MP), preserving14 unmodified linesreturn img.convert("RGB").resize((w, h), Image.LANCZOS)```### 2. The promptSend the page image followed by exactly this text as the user turn. Do notparaphrase, extend, or reformat it.123 unmodified linesprocessor = AutoProcessor.from_pretrained(MODEL)image = preprocess(Image.open("page.png")) # see preprocessing abovePROMPT = "..." # the exact prompt abovemessages = [{"role": "user",11 unmodified linesprint(processor.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))```### Serving (SGLang)N-gram speculative decoding gives a large decode speedup on this outputformat (the repeated JSON keys draft extremely well):```bashpython -m sglang.launch_server \10 unmodified lines```A ready-to-run server that implements the full preprocessing + prompt contract(and a schema-extraction API around it) is available athttps://github.com/youlearn-ai/hanji.## LicenseApache-2.0. Fine-tuned from
README.md+6-42