ocr-miracl / README.md
Psychias's picture
Add OCR-robust embeddings citation (michail-etal-2025)
5cb0601 verified
---
language:
- de
- en
- es
- fr
- ru
task_categories:
- text-retrieval
tags:
- ocr
- information-retrieval
- noisy-text
- miracl
- benchmark
- ocr-simulation
size_categories:
- 10K<n<100K
---
# OCR-MIRACL
An OCR-degraded version of the [MIRACL](https://project-miracl.github.io/) multilingual retrieval benchmark (`miracl/miracl`), designed to evaluate embedding models on **noisy, OCR-like text**.
## Dataset Description
A 2,000-document subsample per language was drawn from `miracl/miracl` (dev split).
Each passage and query was rendered as a PDF at a specific DPI / font-size setting and
re-extracted via OCR using the
[ocr-robust-multilingual-embeddings](https://github.com/impresso/ocr-robust-multilingual-embeddings/tree/main/ocr_simulator/ocr_simulator)
OCR simulator to introduce realistic character-level noise.
Both the **original clean text** and the **OCR-noised text** are provided,
together with the original MIRACL relevance judgments (qrels).
### Configurations
| Config | DPI | Font Size | Description |
|---|---|---|---|
| `{lang}_dpi120_font10` | 120 | 10 pt | Low quality — high noise |
| `{lang}_dpi130_font10` | 130 | 10 pt | Medium quality |
| `{lang}_dpi300_font12` | 300 | 12 pt | High quality — low noise |
Languages: `de`, `en`, `es`, `fr`, `ru`
### Configs per Language/DPI
Each (language, DPI) combination provides three configs:
| Config | Columns | Description |
|---|---|---|
| `{lang}_{dpi}_corpus` | `_id`, `clean_text`, `ocr_text` | Document passages |
| `{lang}_{dpi}_queries` | `_id`, `clean_text`, `ocr_text` | Search queries |
| `{lang}_{dpi}_qrels` | `query_id`, `corpus_id`, `score` | Relevance judgments |
All configs use a single split: `test`.
### Sample Sizes
| Language | Corpus | Queries |
|---|---|---|
| de | 2,000 | 305 |
| en | 2,296 | 799 |
| es | 2,976 | 648 |
| fr | 2,000 | 343 |
| ru | 3,441 | 1,252 |
## Usage
```python
from datasets import load_dataset
# Load English at DPI 120
corpus = load_dataset("YOUR_ORG/ocr-miracl", data_dir="data/en_dpi120_font10_corpus", split="test")
queries = load_dataset("YOUR_ORG/ocr-miracl", data_dir="data/en_dpi120_font10_queries", split="test")
qrels = load_dataset("YOUR_ORG/ocr-miracl", data_dir="data/en_dpi120_font10_qrels", split="test")
# Access clean and OCR-noised text
print(corpus[0]["clean_text"])
print(corpus[0]["ocr_text"])
```
## Evaluation
### Quick Start (Python)
```python
import numpy as np
from datasets import load_dataset
from sentence_transformers import SentenceTransformer
# 1. Load data
corpus = load_dataset("YOUR_ORG/ocr-miracl", data_dir="data/en_dpi120_font10_corpus", split="test")
queries = load_dataset("YOUR_ORG/ocr-miracl", data_dir="data/en_dpi120_font10_queries", split="test")
qrels = load_dataset("YOUR_ORG/ocr-miracl", data_dir="data/en_dpi120_font10_qrels", split="test")
# 2. Encode with any SentenceTransformer model
model = SentenceTransformer("Alibaba-NLP/gte-multilingual-base", trust_remote_code=True)
corpus_emb = model.encode(corpus["ocr_text"], normalize_embeddings=True, show_progress_bar=True)
query_emb = model.encode(queries["ocr_text"], normalize_embeddings=True, show_progress_bar=True)
# 3. Retrieve — cosine similarity (embeddings are L2-normalised)
similarities = np.dot(query_emb, corpus_emb.T)
# 4. Compute NDCG@10 for each query
qrels_dict = {}
for row in qrels:
qrels_dict.setdefault(row["query_id"], {})[row["corpus_id"]] = row["score"]
corpus_ids = corpus["_id"]
for i, qid in enumerate(queries["_id"]):
if qid not in qrels_dict:
continue
top_idx = np.argsort(similarities[i])[::-1][:10]
hits = [qrels_dict[qid].get(corpus_ids[j], 0) for j in top_idx]
dcg = sum(r / np.log2(k + 2) for k, r in enumerate(hits))
ideal = sorted(hits, reverse=True)
idcg = sum(r / np.log2(k + 2) for k, r in enumerate(ideal))
print(f"Query {qid}: NDCG@10 = {dcg / idcg if idcg else 0:.4f}")
```
### Full Evaluation Script
The included `evaluation_IR.py` evaluates across all languages, DPI settings, and modes in one run:
```bash
pip install datasets sentence-transformers torch numpy pandas
python evaluation_IR.py \
--model Alibaba-NLP/gte-multilingual-base \
--dataset YOUR_ORG/ocr-miracl \
--dpi dpi120_font10 dpi130_font10 dpi300_font12 \
--langs de en es fr ru \
--mode clean ocr \
--batch_size 64
```
Results are saved to `./ir_results/results_latest.csv`.
### Evaluation Modes
| Mode | Corpus | Queries | Purpose |
|---|---|---|---|
| `clean` | clean_text | clean_text | Upper bound (no OCR noise) |
| `ocr` | ocr_text | ocr_text | Realistic full-OCR scenario |
| `clean2ocr` | clean_text | ocr_text | Noisy user query against clean index |
| `ocr2clean` | ocr_text | clean_text | Clean query against noisy OCR index |
### Metrics
- **NDCG@10** — Normalized Discounted Cumulative Gain
- **MRR@10** — Mean Reciprocal Rank
- **Recall@100**
## CER Summary (Character Error Rate)
Mean character-level error rates between clean and OCR-noised text, measured per language and DPI setting.
### dpi120_font10 (Low quality)
| Language | Corpus CER | Query CER | Corpus Docs | Queries |
|---|---|---|---|---|
| de | 12.8% | 4.7% | 2,000 | 305 |
| en | 9.4% | 5.8% | 2,296 | 799 |
| es | 8.8% | 4.4% | 2,976 | 648 |
| fr | 9.8% | 7.1% | 2,000 | 343 |
| ru | 10.1% | 7.0% | 3,441 | 1,252 |
### dpi130_font10 (Medium quality)
| Language | Corpus CER | Query CER | Corpus Docs | Queries |
|---|---|---|---|---|
| de | 7.3% | 4.0% | 2,000 | 305 |
| en | 5.2% | 2.9% | 2,296 | 799 |
| es | 4.7% | 2.9% | 2,976 | 648 |
| fr | 5.7% | 5.2% | 2,000 | 343 |
| ru | 6.4% | 5.7% | 3,441 | 1,252 |
### dpi300_font12 (High quality)
| Language | Corpus CER | Query CER | Corpus Docs | Queries |
|---|---|---|---|---|
| de | 1.8% | 1.2% | 2,000 | 305 |
| en | 1.5% | 0.9% | 2,296 | 799 |
| es | 1.4% | 0.7% | 2,976 | 648 |
| fr | 1.8% | 1.1% | 2,000 | 343 |
| ru | 2.9% | 3.0% | 3,441 | 1,252 |
## OCR Noise Generation
Noise was generated with the [OCR Simulator](https://github.com/impresso/ocr-robust-multilingual-embeddings/tree/main/ocr_simulator/ocr_simulator)
using `generate_ocr_miracl.py`:
1. Texts are split into sentences.
2. Each sentence is rendered as a PDF image (Pillow) at the given DPI / font size.
3. The image is OCR-ed via Tesseract.
4. Sentences are rejoined into documents.
## Related
- **[OCR-MLDR](https://huggingface.co/datasets/YOUR_ORG/ocr-mldr)** — Same OCR noise pipeline applied to `mteb/MultiLongDocRetrieval`.
## Citation
If you use this dataset, please cite the OCR noise generation method and the original MIRACL benchmark:
```bibtex
@inproceedings{michail-etal-2025-cheap,
title = "Cheap Character Noise for {OCR}-Robust Multilingual Embeddings",
author = "Michail, Andrianos and
Opitz, Juri and
Wang, Yining and
Meister, Robin and
Sennrich, Rico and
Clematide, Simon",
booktitle = "Findings of the Association for Computational Linguistics: ACL 2025",
month = jul,
year = "2025",
address = "Vienna, Austria",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2025.findings-acl.609/",
pages = "11705--11716",
ISBN = "979-8-89176-256-5"
}
@article{zhang2022miracl,
title={Making a MIRACL: Multilingual Information Retrieval Across a Continuum of Languages},
author={Zhang, Xinyu and Thakur, Nandan and Ogundepo, Odunayo and Kamalloo, Ehsan and Alfonso-Hermelo, David and Li, Xiaoguang and Liu, Qun and Rezagholizadeh, Mehdi and Lin, Jimmy},
journal={arXiv preprint arXiv:2210.09984},
year={2022}
}
```