Update README.md
Browse files
README.md
CHANGED
@@ -17,3 +17,82 @@ configs:
|
|
17 |
- split: train
|
18 |
path: data/train-*
|
19 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
- split: train
|
18 |
path: data/train-*
|
19 |
---
|
20 |
+
|
21 |
+
# Sanskrit Dataset
|
22 |
+
|
23 |
+
## Overview
|
24 |
+
|
25 |
+
This dataset is a conversion of the Pracalit for Sanskrit and Newar MSS 16th to 19th C., Ground Truth dataset, originally published on [Zenodo](https://zenodo.org/records/6967421). The dataset contains pairs of images and corresponding plain text extracted from XML files. This dataset specifically includes the ground truth data from the original repository.
|
26 |
+
|
27 |
+
## Dataset Description
|
28 |
+
|
29 |
+
- **Images**: The original images from the dataset.
|
30 |
+
- **Text**: The text is extracted from XML files using the PAGE XML schema.
|
31 |
+
|
32 |
+
## Potential Use for VLM-based OCR Training
|
33 |
+
|
34 |
+
The existing ground truth OCR data can be particularly useful for bootstrapping datasets for Vision Language Model (VLM) based OCR training. By leveraging the high-quality annotations provided in this dataset, researchers can train models to recognize and transcribe text from images more accurately. This can be especially beneficial for languages and scripts that are underrepresented in existing OCR datasets.
|
35 |
+
|
36 |
+
## Processing Script
|
37 |
+
|
38 |
+
The dataset was processed using the following script:
|
39 |
+
|
40 |
+
```python
|
41 |
+
import os
|
42 |
+
import xml.etree.ElementTree as ET
|
43 |
+
from pathlib import Path
|
44 |
+
from PIL import Image as PILImage
|
45 |
+
import datasets
|
46 |
+
from datasets import Image, Features, Dataset
|
47 |
+
from tqdm import tqdm
|
48 |
+
|
49 |
+
def extract_text_from_xml(xml_path):
|
50 |
+
"""Extract plain text from XML file."""
|
51 |
+
tree = ET.parse(xml_path)
|
52 |
+
root = tree.getroot()
|
53 |
+
text_lines = []
|
54 |
+
for textline in root.findall('.//{http://schema.primaresearch.org/PAGE/gts/pagecontent/2013-07-15}TextLine'):
|
55 |
+
text = textline.find('.//{http://schema.primaresearch.org/PAGE/gts/pagecontent/2013-07-15}TextEquiv/{http://schema.primaresearch.org/PAGE/gts/pagecontent/2013-07-15}Unicode')
|
56 |
+
if text is not None and text.text:
|
57 |
+
text_lines.append(text.text.strip())
|
58 |
+
return ' '.join(text_lines)
|
59 |
+
|
60 |
+
def create_dataset():
|
61 |
+
base_dir = Path("Copy_of_HTR_Train_Set_'Pracalit_for_Sanskrit_and_Newar_MSS_16th_to_19th_C_'")
|
62 |
+
page_dir = base_dir / "page"
|
63 |
+
images = []
|
64 |
+
texts = []
|
65 |
+
image_files = list(base_dir.glob("*.jpg"))
|
66 |
+
for img_file in tqdm(image_files, desc="Processing images"):
|
67 |
+
xml_file = page_dir / f"{img_file.stem}.xml"
|
68 |
+
if not xml_file.exists():
|
69 |
+
print(f"Warning: No matching XML found for {img_file.name}")
|
70 |
+
continue
|
71 |
+
try:
|
72 |
+
text = extract_text_from_xml(xml_file)
|
73 |
+
img = PILImage.open(img_file)
|
74 |
+
img.verify()
|
75 |
+
images.append(str(img_file))
|
76 |
+
texts.append(text)
|
77 |
+
except Exception as e:
|
78 |
+
print(f"Error processing {img_file.name}: {str(e)}")
|
79 |
+
continue
|
80 |
+
dataset = Dataset.from_dict({
|
81 |
+
"image": images,
|
82 |
+
"text": texts
|
83 |
+
}, features=Features({
|
84 |
+
"image": Image(),
|
85 |
+
"text": datasets.Value("string")
|
86 |
+
}))
|
87 |
+
print(f"Dataset created with {len(dataset)} examples")
|
88 |
+
print("Saved to sanskrit_dataset.parquet")
|
89 |
+
dataset.push_to_hub("davanstrien/sanskrit_dataset", private=True)
|
90 |
+
|
91 |
+
if __name__ == "__main__":
|
92 |
+
create_dataset()
|
93 |
+
```
|
94 |
+
|
95 |
+
## Citation
|
96 |
+
|
97 |
+
If you use this dataset, please cite the original dataset on Zenodo:
|
98 |
+
[OCR model for Pracalit for Sanskrit and Newar MSS 16th to 19th C., Ground Truth](https://zenodo.org/records/6967421)
|