YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

ByT5 Bengali OCR Error Correction

This is a fine-tuned google/byt5-small model specifically trained to correct severe Optical Character Recognition (OCR) errors in Bengali text generated by Tesseract.

Dataset & Training

Because real-world Bengali OCR datasets are extremely rare, this model was trained using a massive synthetically damaged dataset anchored and evaluated against human-annotated ground truth (credit to swapnil7777/bangla-ocr-dataset).

To make the model bulletproof against real-world degradation, we built a custom stochastic physics engine (BigBeutifoolDamajeEnjene) to physically damage pristine Bengali text before feeding it to Tesseract. The model learned to fix errors caused by:

  • Heavy Gaussian Blur (defocusing)
  • Severe Phone Shadows & Vignetting
  • Sensor Noise & Paper Grain (Salt & Pepper)
  • JPEG Compression Artifacts
  • Page Bleed-through and Skewing
  • Water Damage & Ink Smudging
  • Page Creases & Folds
  • Book Spine Warping
  • Pencil Marks & Hole Punches

Performance

By operating directly at the UTF-8 byte level (ByT5 architecture), this model bypasses the traditional tokenization limits of the complex Bengali alphabet (Juktakkhor/Conjuncts). It maps damaged OCR bytes directly back to pristine Bengali bytes, achieving exceptionally low validation loss.

How to Use

from transformers import AutoTokenizer, T5ForConditionalGeneration
import torch

tokenizer = AutoTokenizer.from_pretrained("Stup702/ByT5-Bengali-OCR-Correction")
model = T5ForConditionalGeneration.from_pretrained("Stup702/ByT5-Bengali-OCR-Correction")

def chunk_text_by_lines(text, max_chars=300):
    lines = text.split('
')
    chunks = []
    current_chunk = ""
    for line in lines:
        if len(current_chunk) + len(line) + 1 > max_chars:
            if current_chunk:
                chunks.append(current_chunk)
                current_chunk = line
            else:
                chunks.append(line)
        else:
            if current_chunk:
                current_chunk += '
' + line
            else:
                current_chunk = line
    if current_chunk:
        chunks.append(current_chunk)
    return chunks

raw_ocr_text = "আপনার খারাপ OCR টেক্সট..."
raw_chunks = chunk_text_by_lines(raw_ocr_text, max_chars=300)

corrected_chunks = []
for chunk in raw_chunks:
    inputs = tokenizer(chunk, return_tensors="pt", max_length=1024, truncation=True)
    with torch.no_grad():
        outputs = model.generate(**inputs, max_length=1024, num_beams=4, repetition_penalty=2.0)
    corrected_chunks.append(tokenizer.decode(outputs[0], skip_special_tokens=True))

print("\n".join(corrected_chunks))
Downloads last month
177
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support