jeanflop/post_ocr_correction-512
Viewer • Updated • 1M • 78
How to use jeanflop/ocr_correcteur-v1 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="jeanflop/ocr_correcteur-v1") # Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("jeanflop/ocr_correcteur-v1", dtype="auto")How to use jeanflop/ocr_correcteur-v1 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "jeanflop/ocr_correcteur-v1"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "jeanflop/ocr_correcteur-v1",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/jeanflop/ocr_correcteur-v1
How to use jeanflop/ocr_correcteur-v1 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "jeanflop/ocr_correcteur-v1" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "jeanflop/ocr_correcteur-v1",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "jeanflop/ocr_correcteur-v1" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "jeanflop/ocr_correcteur-v1",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use jeanflop/ocr_correcteur-v1 with Docker Model Runner:
docker model run hf.co/jeanflop/ocr_correcteur-v1
This model lora weight has been finetune on french OCR dataset. The architecture used is Flan T large. On a sample of 1000. More stong model is under cooks.
!pip install -q transformers accelerate peft diffusers
!pip install -U bitsandbytes
import torch
from peft import PeftModel, PeftConfig
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer,BitsAndBytesConfig
# Load peft config for pre-trained checkpoint etc.
peft_model_id = "jeanflop/ocr_correcteur-v1"
config = PeftConfig.from_pretrained(peft_model_id)
# load base LLM model and tokenizer
peft_model = AutoModelForSeq2SeqLM.from_pretrained(config.base_model_name_or_path, load_in_8bit=True, device_map={"":1})
peft_tokenizer = AutoTokenizer.from_pretrained('google/flan-t5-large')
# Load the Lora model
peft_model = PeftModel.from_pretrained(peft_model, peft_model_id, device_map={"":1})
# model.eval()
print("Peft model loaded")
Add your text
inputs=f"""
Fix text : {text}"""
Run
peft_model.config.max_length=512
peft_tokenizer.model_max_length=512
inputs = peft_tokenizer(inputs, return_tensors="pt")
outputs = peft_model.generate(**inputs,max_length=512)
answer = peft_tokenizer.decode(outputs[0])
from textwrap import fill
print(fill(answer, width=80))
Base model
google/flan-t5-large