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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# RoWeR: RoBERTa Word Error Rate Estimator for OCRed Texts
|
| 2 |
+
|
| 3 |
+
```yaml
|
| 4 |
+
---
|
| 5 |
+
language:
|
| 6 |
+
- en
|
| 7 |
+
- fr
|
| 8 |
+
- de
|
| 9 |
+
- es
|
| 10 |
+
- it
|
| 11 |
+
- nl
|
| 12 |
+
- pt
|
| 13 |
+
library_name: transformers
|
| 14 |
+
base_model: FacebookAI/xlm-roberta-base
|
| 15 |
+
tags:
|
| 16 |
+
- ocr
|
| 17 |
+
- quality-estimation
|
| 18 |
+
- word-error-rate
|
| 19 |
+
- xlm-roberta
|
| 20 |
+
- regression
|
| 21 |
+
- historical-documents
|
| 22 |
+
- multilingual
|
| 23 |
+
---
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
**RoWeR** is a reference-free quality estimation model for OCRed text. It predicts the **Word Error Rate (WER)** of OCR output using **only the OCR text itself**, without requiring a manually corrected reference transcription.
|
| 27 |
+
|
| 28 |
+
RoWeR is based on **XLM-RoBERTa** and was adapted for WER regression using **LoRA**. The models were trained and evaluated on historical OCR data in seven languages:
|
| 29 |
+
|
| 30 |
+
* Portuguese
|
| 31 |
+
* German
|
| 32 |
+
* French
|
| 33 |
+
* Italian
|
| 34 |
+
* English
|
| 35 |
+
* Dutch
|
| 36 |
+
* Spanish
|
| 37 |
+
|
| 38 |
+
The main use case is **OCR quality estimation at scale**: deciding which OCR outputs are good enough for downstream processing, which should be sent to post-OCR correction, and which are too degraded to use reliably.
|
| 39 |
+
|
| 40 |
+
### Important: output scaling
|
| 41 |
+
|
| 42 |
+
RoWeR was trained to focus on WER values in the **0.0–0.2** range. During training, this interval was linearly scaled to **0–1**, with WER values above `0.2` clipped at the upper boundary.
|
| 43 |
+
|
| 44 |
+
Therefore, the model's raw regression output should be converted back to WER approximately as:
|
| 45 |
+
|
| 46 |
+
```python
|
| 47 |
+
estimated_wer = clip(model_output, 0, 1) * 0.2
|
| 48 |
+
```
|
| 49 |
+
|
| 50 |
+
For example:
|
| 51 |
+
|
| 52 |
+
| Model output | Estimated WER |
|
| 53 |
+
| -----------: | ---------------------: |
|
| 54 |
+
| `0.10` | `0.02` — 2% |
|
| 55 |
+
| `0.25` | `0.05` — 5% |
|
| 56 |
+
| `0.50` | `0.10` — 10% |
|
| 57 |
+
| `1.00` | `0.20` — 20% or higher |
|
| 58 |
+
|
| 59 |
+
The model is intended primarily for quality estimation and triage in the **0–20% WER range**. It should not be used to distinguish precisely between highly degraded texts above that range.
|
| 60 |
+
|
| 61 |
+
## Available models
|
| 62 |
+
|
| 63 |
+
The repository contains both language-specific and multilingual RoWeR models.
|
| 64 |
+
|
| 65 |
+
### Multilingual models
|
| 66 |
+
|
| 67 |
+
| Folder | Description |
|
| 68 |
+
| -------------------------------- | ----------------------------------------------------------------------- |
|
| 69 |
+
| `RoWer-multi-lingual-balanced` | Multilingual model trained with balanced language sampling |
|
| 70 |
+
| `RoWer-multi-lingual-unbalanced` | Multilingual model trained using the natural training-data distribution |
|
| 71 |
+
|
| 72 |
+
For general use, we recommend starting with a **multilingual model**. In the paper, multilingual training substantially reduced the cross-language calibration problems observed with some language-specific models, while the balanced and unbalanced variants performed similarly overall.
|
| 73 |
+
|
| 74 |
+
### Language-specific models
|
| 75 |
+
|
| 76 |
+
| Folder | Language | Training corpus |
|
| 77 |
+
| ------------------------ | ---------- | --------------- |
|
| 78 |
+
| `RoWeR-RETAS_english` | English | RETAS |
|
| 79 |
+
| `RoWeR-RETAS_french` | French | RETAS |
|
| 80 |
+
| `RoWeR-RETAS_german` | German | RETAS |
|
| 81 |
+
| `RoWeR-RETAS_spanish` | Spanish | RETAS |
|
| 82 |
+
| `RoWeR-dbnl_dutch` | Dutch | DBNL |
|
| 83 |
+
| `RoWeR-pocr_english` | English | POCR |
|
| 84 |
+
| `RoWeR-pocr_french` | French | POCR |
|
| 85 |
+
| `RoWeR-pocr_german` | German | POCR |
|
| 86 |
+
| `RoWeR-pocr_italian` | Italian | POCR |
|
| 87 |
+
| `RoWeR-porto_portuguese` | Portuguese | PORTO |
|
| 88 |
+
|
| 89 |
+
Where multiple models exist for the same language, the variants were trained on different OCR corpora and therefore represent different domains and OCR-noise distributions.
|
| 90 |
+
|
| 91 |
+
## Repository structure
|
| 92 |
+
|
| 93 |
+
Each model variant contains a LoRA checkpoint and a merged model:
|
| 94 |
+
|
| 95 |
+
```text
|
| 96 |
+
<Model folder>/
|
| 97 |
+
├── checkpoint-final/
|
| 98 |
+
└── final_merged_model/
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
For the simplest inference setup, use `final_merged_model`.
|
| 102 |
+
|
| 103 |
+
The merged model folders contain the trained XLM-RoBERTa regression model. The tokenizer should be loaded from the original base model:
|
| 104 |
+
|
| 105 |
+
```text
|
| 106 |
+
FacebookAI/xlm-roberta-base
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
## Installation
|
| 110 |
+
|
| 111 |
+
```bash
|
| 112 |
+
pip install torch transformers
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
## Quick start
|
| 116 |
+
|
| 117 |
+
The following example uses the balanced multilingual model.
|
| 118 |
+
|
| 119 |
+
```python
|
| 120 |
+
import torch
|
| 121 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 122 |
+
|
| 123 |
+
REPO_ID = "TomasOsorio/RoweR"
|
| 124 |
+
MODEL_SUBFOLDER = "RoWer-multi-lingual-balanced/final_merged_model"
|
| 125 |
+
BASE_MODEL = "FacebookAI/xlm-roberta-base"
|
| 126 |
+
|
| 127 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 128 |
+
|
| 129 |
+
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
| 130 |
+
|
| 131 |
+
model = AutoModelForSequenceClassification.from_pretrained(
|
| 132 |
+
REPO_ID,
|
| 133 |
+
subfolder=MODEL_SUBFOLDER,
|
| 134 |
+
)
|
| 135 |
+
model.to(device)
|
| 136 |
+
model.eval()
|
| 137 |
+
|
| 138 |
+
ocr_text = """
|
| 139 |
+
Th1s is an examp1e of OCRed text with recogn1tion errors.
|
| 140 |
+
"""
|
| 141 |
+
|
| 142 |
+
inputs = tokenizer(
|
| 143 |
+
ocr_text,
|
| 144 |
+
return_tensors="pt",
|
| 145 |
+
truncation=True,
|
| 146 |
+
max_length=256,
|
| 147 |
+
)
|
| 148 |
+
inputs = {key: value.to(device) for key, value in inputs.items()}
|
| 149 |
+
|
| 150 |
+
with torch.no_grad():
|
| 151 |
+
output = model(**inputs).logits.squeeze().item()
|
| 152 |
+
|
| 153 |
+
# RoWeR was trained with WER [0, 0.2] scaled to [0, 1].
|
| 154 |
+
normalized_score = max(0.0, min(1.0, output))
|
| 155 |
+
estimated_wer = normalized_score * 0.2
|
| 156 |
+
|
| 157 |
+
print(f"Estimated WER: {estimated_wer:.4f}")
|
| 158 |
+
print(f"Estimated word error percentage: {estimated_wer * 100:.2f}%")
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
## Training data
|
| 162 |
+
|
| 163 |
+
RoWeR was developed using four OCR corpora:
|
| 164 |
+
|
| 165 |
+
* **PORTO** — historical Portuguese OCR data
|
| 166 |
+
* **DBNL** — historical Dutch texts from the Digital Library of Dutch Literature
|
| 167 |
+
* **RETAS** — English, French, German, and Spanish OCR data
|
| 168 |
+
* **POCR** — large-scale English, French, German, and Italian OCR data
|
| 169 |
+
|
| 170 |
+
The training pipeline aligned OCR outputs with reference transcriptions, computed segment-level WER, and applied quality filters to remove unreliable or anomalous samples.
|
| 171 |
+
|
| 172 |
+
## Model architecture
|
| 173 |
+
|
| 174 |
+
RoWeR uses:
|
| 175 |
+
|
| 176 |
+
* `FacebookAI/xlm-roberta-base`
|
| 177 |
+
* a sequence-level regression head
|
| 178 |
+
* LoRA-based parameter-efficient fine-tuning
|
| 179 |
+
|
| 180 |
+
At inference time, the model takes OCR text as input and outputs a single regression value representing estimated OCR degradation.
|
| 181 |
+
|
| 182 |
+
RoWeR does **not** require:
|
| 183 |
+
|
| 184 |
+
* the source document image
|
| 185 |
+
* OCR-engine confidence scores
|
| 186 |
+
* a second OCR system
|
| 187 |
+
* a manually corrected reference transcription
|
| 188 |
+
|
| 189 |
+
## Intended uses
|
| 190 |
+
|
| 191 |
+
RoWeR is intended for tasks such as:
|
| 192 |
+
|
| 193 |
+
* large-scale OCR quality assessment
|
| 194 |
+
* document triage before downstream NLP
|
| 195 |
+
* deciding whether post-OCR correction is likely to be necessary
|
| 196 |
+
* filtering low-quality OCR text
|
| 197 |
+
* prioritising documents for manual review
|
| 198 |
+
* monitoring OCR quality across large digital collections
|
| 199 |
+
|
| 200 |
+
RoWeR estimates OCR quality; it does **not** correct OCR errors.
|
| 201 |
+
|
| 202 |
+
## Citation
|
| 203 |
+
|
| 204 |
+
If you use RoWeR in your work, please cite:
|
| 205 |
+
|
| 206 |
+
```bibtex
|
| 207 |
+
@InProceedings{10.1007/978-3-032-36033-5_1,
|
| 208 |
+
author="Os{\'o}rio, Tom{\'a}s Freitas and Cardoso, Henrique Lopes",
|
| 209 |
+
title="RoWeR: RoBERTa Word Error Rate Estimator for OCRed Texts",
|
| 210 |
+
booktitle="Document Analysis and Recognition -- ICDAR 2026",
|
| 211 |
+
year="2027",
|
| 212 |
+
publisher="Springer Nature Switzerland",
|
| 213 |
+
address="Cham",
|
| 214 |
+
pages="3--18",
|
| 215 |
+
}
|
| 216 |
+
```
|