File size: 1,804 Bytes
e5b3d14 1802676 1a4050f c71e10e e5b3d14 3f511ba c71e10e e5b3d14 1a4050f a0ff9be 1a4050f dcf0792 1a4050f dcf0792 1a4050f dcf0792 1a4050f 7239bb5 1a4050f c71e10e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
---
library_name: transformers
datasets:
- jeanflop/post_ocr_correction-512
language:
- fr
- en
base_model:
- google/flan-t5-large
license: apache-2.0
pipeline_tag: text-generation
---
## **Ocr Correcteur v1**
![image/jpeg](https://huggingface.co/jeanflop/ocr_correcteur-v1/resolve/main/an-illustration-of-a-superhero-with-a-smiley-face--R5MceaXPSHOnN5fLITavoQ-zUPTdsBuQKSJyWZmx7sdXw.jpeg)
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.
* **Install dependencies**
```bash
!pip install -q transformers accelerate peft diffusers
!pip install -U bitsandbytes
```
* **Load and merge adaptaters in 8Bit** (recommanded)
```python
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")
```
* **Run inference** (recommanded)
Add your text
```python
inputs=f"""
Fix text : {text}"""
```
Run
```python
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))
``` |