Views
No views yet
| Parameter | Value |
|---|---|
| Model Size | 4B parameters |
| Context Length | 32K tokens |
| Image Resolution | Flexible (optimized for documents) |
| Precision | BFloat16 |
| Framework | Transformers + Unsloth |
pip install transformers torch pillow unsloth1from transformers import AutoProcessor, AutoModelForImageTextToText
2from PIL import Image
3import torch
4
5# Load model and processor
6model_id = "Nayana-cognitivelab/NayanaSectionOCR"
7processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
8model = AutoModelForImageTextToText.from_pretrained(
9 model_id,
10 device_map="auto",
11 torch_dtype=torch.bfloat16,
12 trust_remote_code=True
13)
14
15# System prompt
16system_prompt = "You are Nayana, an advanced AI assistant developed by CognitiveLab. You specialize in vision-based tasks, particularly Optical Character Recognition (OCR) and Document Visual Question Answering (Document VQA). You are highly accurate, fast, and reliable when working with complex visual documents. Most importantly, you are multilingual, capable of understanding and processing documents in a wide range of languages with precision."
17
18# Load and process image
19image = Image.open("your_document.jpg")
20language = "English" # or "Kannada", "Hindi", "Marathi", "Sanskrit"
21user_prompt = f"Extract the text from this image in {language}"
22
23# Prepare messages
24messages = [
25 {
26 "role": "system",
27 "content": [{"type": "text", "text": system_prompt}]
28 },
29 {
30 "role": "user",
31 "content": [
32 {"type": "text", "text": user_prompt},
33 {"type": "image", "image": image}
34 ]
35 }
36]
37
38# Apply chat template
39inputs = processor.apply_chat_template(
40 messages,
41 add_generation_prompt=True,
42 tokenize=True,
43 return_dict=True,
44 return_tensors="pt"
45)
46
47# Generate response
48with torch.inference_mode():
49 outputs = model.generate(
50 **inputs,
51 max_new_tokens=1024,
52 temperature=1.0,
53 top_p=0.95,
54 top_k=64,
55 do_sample=True
56 )
57
58# Decode response
59response = processor.tokenizer.decode(
60 outputs[0][inputs["input_ids"].shape[1]:],
61 skip_special_tokens=True
62)
63print(response)1@model{nayana_sectionocr_2024,
2 title={Nayana SectionOCR: Multilingual Document Understanding with Gemma 3n},
3 author={CognitiveLab},
4 year={2024},
5 url={https://huggingface.co/Nayana-cognitivelab/SectionOCR_SFT_v3_half_en_kn_hi_sa_mr_7250}
6}