--- dataset_info: features: - name: image dtype: image - name: text dtype: string splits: - name: train num_bytes: 508398188 num_examples: 441 download_size: 506925962 dataset_size: 508398188 configs: - config_name: default data_files: - split: train path: data/train-* license: cc-by-4.0 task_categories: - image-to-text language: - sa tags: - ocr size_categories: - n<1K --- # Sanskrit Dataset ## Overview 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. ## Dataset Description - **Images**: The original images from the dataset. - **Text**: The text is extracted from XML files using the PAGE XML schema. ## Potential Use for VLM-based OCR Training 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. ## Processing Script The dataset was processed using the following script: ```python import os import xml.etree.ElementTree as ET from pathlib import Path from PIL import Image as PILImage import datasets from datasets import Image, Features, Dataset from tqdm import tqdm def extract_text_from_xml(xml_path): """Extract plain text from XML file.""" tree = ET.parse(xml_path) root = tree.getroot() text_lines = [] for textline in root.findall('.//{http://schema.primaresearch.org/PAGE/gts/pagecontent/2013-07-15}TextLine'): 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') if text is not None and text.text: text_lines.append(text.text.strip()) return ' '.join(text_lines) def create_dataset(): base_dir = Path("Copy_of_HTR_Train_Set_'Pracalit_for_Sanskrit_and_Newar_MSS_16th_to_19th_C_'") page_dir = base_dir / "page" images = [] texts = [] image_files = list(base_dir.glob("*.jpg")) for img_file in tqdm(image_files, desc="Processing images"): xml_file = page_dir / f"{img_file.stem}.xml" if not xml_file.exists(): print(f"Warning: No matching XML found for {img_file.name}") continue try: text = extract_text_from_xml(xml_file) img = PILImage.open(img_file) img.verify() images.append(str(img_file)) texts.append(text) except Exception as e: print(f"Error processing {img_file.name}: {str(e)}") continue dataset = Dataset.from_dict({ "image": images, "text": texts }, features=Features({ "image": Image(), "text": datasets.Value("string") })) print(f"Dataset created with {len(dataset)} examples") print("Saved to sanskrit_dataset.parquet") dataset.push_to_hub("davanstrien/sanskrit_dataset", private=True) if __name__ == "__main__": create_dataset() ``` ## Citation If you use this dataset, please cite the original dataset on Zenodo: [OCR model for Pracalit for Sanskrit and Newar MSS 16th to 19th C., Ground Truth](https://zenodo.org/records/6967421)