Update README.md
Browse files
README.md
CHANGED
|
@@ -1,22 +1,81 @@
|
|
| 1 |
---
|
| 2 |
-
base_model:
|
| 3 |
tags:
|
| 4 |
-
-
|
| 5 |
-
- transformers
|
| 6 |
- unsloth
|
| 7 |
-
-
|
| 8 |
-
-
|
|
|
|
| 9 |
license: apache-2.0
|
| 10 |
language:
|
| 11 |
- en
|
| 12 |
---
|
| 13 |
|
| 14 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
base_model: sapkotapraful/FullyOCR
|
| 3 |
tags:
|
| 4 |
+
- vision-language
|
|
|
|
| 5 |
- unsloth
|
| 6 |
+
- fullyocr
|
| 7 |
+
- text-extraction
|
| 8 |
+
- transformers
|
| 9 |
license: apache-2.0
|
| 10 |
language:
|
| 11 |
- en
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Model Card — sapkotapraful/FullyOCR (finetuned)
|
| 15 |
+
|
| 16 |
+
- Developed by: sapkotapraful
|
| 17 |
+
- License: apache-2.0
|
| 18 |
+
- Model: sapkotapraful/FullyOCR
|
| 19 |
+
- Framework: Unsloth (FastVisionModel) + PyTorch
|
| 20 |
+
|
| 21 |
+
Short description
|
| 22 |
+
- FullyOCR is a vision-language OCR model finetuned for extracting text and structured content from images and PDFs. It is intended for research, prototyping, and non-critical document extraction tasks.
|
| 23 |
+
|
| 24 |
+
Intended use
|
| 25 |
+
- OCR/text extraction from images and scanned documents.
|
| 26 |
+
- Not for automated medical, legal, or safety-critical decisions without human review.
|
| 27 |
+
|
| 28 |
+
How to load (using Unsloth; no external API calls)
|
| 29 |
+
- Minimal local loading and inference example. Adjust device/quantization flags as needed.
|
| 30 |
+
|
| 31 |
+
````python
|
| 32 |
+
from unsloth import FastVisionModel
|
| 33 |
+
import torch
|
| 34 |
+
from PIL import Image
|
| 35 |
+
|
| 36 |
+
# Load model + tokenizer (example uses 4-bit quantization if applicable)
|
| 37 |
+
model, tokenizer = FastVisionModel.from_pretrained(
|
| 38 |
+
"sapkotapraful/FullyOCR",
|
| 39 |
+
load_in_4bit=True,
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
model.eval()
|
| 43 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 44 |
+
if device == "cuda":
|
| 45 |
+
model = model.to(device)
|
| 46 |
+
|
| 47 |
+
# Instruction token used during finetuning
|
| 48 |
+
instruction = "<|MD|>"
|
| 49 |
+
|
| 50 |
+
# Prepare messages in training-time template
|
| 51 |
+
messages = [
|
| 52 |
+
{"role": "user", "content": [
|
| 53 |
+
{"type": "image"},
|
| 54 |
+
{"type": "text", "text": instruction}
|
| 55 |
+
]}
|
| 56 |
+
]
|
| 57 |
+
|
| 58 |
+
input_text = tokenizer.apply_chat_template(messages, add_generation_prompt=True)
|
| 59 |
|
| 60 |
+
# [image](http://_vscodecontentref_/0) is a PIL.Image in RGB mode
|
| 61 |
+
# tokenizer returns tensors suitable for model.generate
|
| 62 |
+
inputs = tokenizer(
|
| 63 |
+
image, # PIL.Image object
|
| 64 |
+
input_text,
|
| 65 |
+
add_special_tokens=False,
|
| 66 |
+
return_tensors="pt",
|
| 67 |
+
).to(device)
|
| 68 |
|
| 69 |
+
with torch.no_grad(), torch.amp.autocast(device_type="cuda", enabled=(device=="cuda")):
|
| 70 |
+
output_ids = model.generate(
|
| 71 |
+
**inputs,
|
| 72 |
+
max_new_tokens=1024,
|
| 73 |
+
use_cache=True,
|
| 74 |
+
num_beams=1,
|
| 75 |
+
do_sample=False,
|
| 76 |
+
pad_token_id=tokenizer.pad_token_id,
|
| 77 |
+
)
|
| 78 |
|
| 79 |
+
decoded = tokenizer.batch_decode(output_ids, skip_special_tokens=True)[0]
|
| 80 |
+
extracted = decoded.split(instruction)[-1].strip()
|
| 81 |
+
print(extracted)
|