Instructions to use Reza2kn/Bina-0.3-Koochik with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Reza2kn/Bina-0.3-Koochik with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Reza2kn/Bina-0.3-Koochik") 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("Reza2kn/Bina-0.3-Koochik") model = AutoModelForMultimodalLM.from_pretrained("Reza2kn/Bina-0.3-Koochik", 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 Reza2kn/Bina-0.3-Koochik with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Reza2kn/Bina-0.3-Koochik" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Reza2kn/Bina-0.3-Koochik", "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/Reza2kn/Bina-0.3-Koochik
- SGLang
How to use Reza2kn/Bina-0.3-Koochik 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 "Reza2kn/Bina-0.3-Koochik" \ --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": "Reza2kn/Bina-0.3-Koochik", "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 "Reza2kn/Bina-0.3-Koochik" \ --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": "Reza2kn/Bina-0.3-Koochik", "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 Reza2kn/Bina-0.3-Koochik with Docker Model Runner:
docker model run hf.co/Reza2kn/Bina-0.3-Koochik
Bina 0.3 Koochik
A BF16 model for Persian transcription of complete document images using the original Bina OCR interface. This revision replaces the earlier narrow layout adaptation, which substantially degraded handwriting OCR. Its original weights remain recoverable at revision 66256be67575450dafd8175bd17c765a07462527.
Training
Restarted from Reza2kn/Bina-0.1-Koochik revision 9b5812be94e3e015142da22a4b61b34aad5d2c02. Rank-16 LoRA (alpha 32) adapts MLP projections in all language layers and Q/K/V/O in full-attention layers 19 and 23: 5,668,864 trainable parameters. Vision, recurrent attention and controls, the other full-attention layers, embeddings and output head remain exactly unchanged. The selected checkpoint is step 960, deployed with residual scale 0.9. This multiplies the trained LoRA B matrices before merging; the unscaled training checkpoint and effective deployed adapter are preserved privately.
Training combines 278 audited whole-page PersianVLM transcriptions with printed OCR and complete handwritten-page replay. Replay has 512 printed and 493 handwriting training examples; every optimizer step includes one full document, two printed examples and two handwritten pages. Ordinary assistant-token cross entropy is combined with KL anchoring to the original model on replay (coefficient 1) and on Arshasb document transcription (coefficient 2). Hafez uses verified gold without teacher KL because the original model reads this domain poorly. Hafez EOS has weight 4; all other tokens have weight 1. No image cropping or target truncation is used. The private source labels and images are not redistributed here. After 834 initial steps, the selected run continued for 126 steps from the 0.90 adapter with a reset optimizer and 5e-6 peak learning rate. Each continuation step used one Hafez page, one Arshasb page, two printed samples and two handwriting samples; original-base KL anchoring had coefficient 5 on replay and Arshasb, with no Hafez teacher KL.
Training uses the verbatim whole-page text field with the original transcription prompt. Bounding boxes and the original HTML serialization remain as provenance; they are not crop inputs or output supervision.
Evaluation
On the frozen 13,338-image PersianOCR-TripleThreat benchmark, original base score was 9.6407, and this model scored 9.7782 (lower is better). Both used the same original transcription prompt, BF16 vLLM backend, complete images, greedy decoding and 4,096-token generation cap. The score weights are 0.2 WER + 0.2 CER + 0.6 S3, with equal weighting of printed and handwriting splits. Previous HTML-prompt scores are not a matched comparison to this protocol.
The benchmark was excluded from this repair training, development and checkpoint selection. All earlier repair adapters were retired after a stronger identity audit found benchmark-reference substrings in training data. A fresh base restart excluded 28 samples across the splits, including two private training pages and 19 handwriting replay training pages. The audit excludes exact images and complete normalized protected-reference substrings of at least 30 characters; it does not claim the underlying vocabulary or source families are unseen to the original base. Selection used separate retention and whole-document validation gates. New retention test data contains 96 printed and 91 handwritten pages; these corpora were used to train the original base, so this is a retention check, not a claim of unseen-domain generalization. The 14 private source test pages had already been evaluated during the previous run: this is explicitly a reused source holdout. On those pages, whole-page transcription CER is 5.18%, with 0 truncated outputs. Hafez has only two source holdout pages. Full aggregate metrics, protocols and weight integrity are included in the repository. Raw predictions, source images and labels are kept in the private run archive.
Prompts
For general printed and handwritten OCR, use the original task prompt:
OCR this Persian document image. Return only the complete transcription in reading order.
The complete original image is the input. Box annotations define the source transcript and remain in private provenance. This release is validated for plain transcription using the original prompt above; native HTML box output is not a supported release contract.
import torch
from PIL import Image, ImageOps
from transformers import AutoProcessor, AutoModelForImageTextToText
repo = "Reza2kn/Bina-0.3-Koochik"
processor = AutoProcessor.from_pretrained(repo)
model = AutoModelForImageTextToText.from_pretrained(repo, dtype=torch.bfloat16).cuda().eval()
image = ImageOps.exif_transpose(Image.open("page.png")).convert("RGB")
prompt = "OCR this Persian document image. Return only the complete transcription in reading order."
messages = [{"role": "user", "content": [{"type": "image", "image": image}, {"type": "text", "text": prompt}]}]
inputs = processor.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_dict=True, return_tensors="pt")
inputs = {k: v.to("cuda", dtype=torch.bfloat16 if v.is_floating_point() else v.dtype) for k, v in inputs.items()}
with torch.inference_mode():
output = model.generate(**inputs, max_new_tokens=4096, do_sample=False, eos_token_id=2, pad_token_id=0)
print(processor.tokenizer.decode(output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
The native tokenizer EOS/pad IDs are saved as 2/0. Character splitting now includes consecutive line breaks, which previously became unknown tokens. Vocabulary and token IDs are unchanged; 2,030 targets roundtrip exactly and all 1,719 audited prompt prefixes keep identical token IDs. The upstream modified OpenRAIL-M license and restrictions are retained in LICENSE. Dataset screening by Codex is not independent human certification. No external model service was used for the repair.
- Downloads last month
- 399