W4ashabii's picture
Update README.md
779508f verified
|
Raw
History Blame Contribute Delete
8.81 kB
---
license: apache-2.0
size_categories:
- 1M<n<10M
language:
- ne
- hi
- mr
- sa
- pi
pretty_name: Devanagari Compiled Dataset (ShareGPT)
tags:
- ocr
- devanagari
- image-to-text
- sharegpt
- instruction-tuning
- nepali
- hindi
- marathi
- document-understanding
task_categories:
- image-to-text
- question-answering
---
# Dataset Card: Devanagari Compiled Dataset (ShareGPT)
## Dataset Description
This is a **curated compilation of 7 public Devanagari OCR datasets**, filtered for script purity and repackaged into the **ShareGPT conversation format** for fine-tuning vision-language models like GLM-OCR.
The dataset is distributed as **42 compressed image batches** (to enable manageable downloads) alongside a **single consolidated JSON annotation file**`devanagari_ocr.json`. No fixed train/validation/test splits are provided, allowing you to create your own stratified splits based on your specific downstream tasks.
**Total size**: ~58 GB (images) + annotations.
---
## Repository Structure
```
devanagari_ocr_dataset/
├── data/
│ ├── images_batch_001.tar.gz
│ ├── images_batch_002.tar.gz
│ ├── ...
│ └── images_batch_042.tar.gz
├── devanagari_ocr.json
└── README.md
```
- **`data/`**: Contains all 42 compressed tarballs. Each tarball holds a subset of the images (e.g., `images_batch_001/`, `images_batch_002/`, etc.) or a flat directory of image files.
- **`devanagari_ocr.json`**: The single annotation file containing all samples in ShareGPT format. It can be either a JSON array or JSONL (JSON Lines) format — loaders for both are provided below.
---
## Extraction Instructions
### Extract All Image Batches into a Single Folder
Run the following commands to extract every tarball into a unified `images/` directory:
```bash
cd data
mkdir -p ../images
for tar in images_batch_*.tar.gz; do
echo "Extracting $tar ..."
tar -xzf "$tar" -C ../images/
done
```
After successful extraction, your root folder will look like:
```
devanagari_ocr_dataset/
├── images/
│ ├── 000001.jpg
│ ├── 000002.png
│ └── ... (all extracted image files)
├── devanagari_ocr.json
└── README.md
```
> **Important**: The image paths inside `devanagari_ocr.json` are relative (e.g., `"images/000001.jpg"`). After extraction, ensure the `images/` folder is in the same root directory as the JSON file so the paths resolve correctly. If your tarballs extract into subfolders (e.g., `batch_001/`), you may need to move all files up one level using `mv ../images/*/* ../images/` or update the JSON paths accordingly.
---
## Data Format (ShareGPT Schema)
`devanagari_ocr.json` contains all samples. Each entry follows the ShareGPT conversation structure:
```json
{
"image": "images/000001.jpg",
"conversations": [
{
"from": "human",
"value": "<image>\nText Recognition:"
},
{
"from": "gpt",
"value": "स्वर्ग आफै"
}
]
}
```
- **`image`** (`str`): Relative path to the image file from the repository root.
- **`conversations`** (`list`): A list of turns. The `human` turn always includes the `<image>` token followed by `Text Recognition:`. The `gpt` turn contains the ground-truth transcription.
---
## Loading the Dataset in Python
### Step 1: Verify Extraction
Ensure all images are extracted into `./images/`.
### Step 2: Load Annotations
`devanagari_ocr.json` may be a **JSON array** or **JSONL** format. The following loader handles both:
```python
import json
from PIL import Image
import os
def load_sharegpt_annotations(json_path):
with open(json_path, "r", encoding="utf-8") as f:
# Try parsing as a JSON array first
try:
data = json.load(f)
if isinstance(data, list):
return data
except json.JSONDecodeError:
pass
# Fallback: treat as JSONL (one JSON object per line)
f.seek(0)
data = []
for line in f:
line = line.strip()
if line:
data.append(json.loads(line))
return data
def load_sharegpt_samples(json_path, image_root="./images"):
annotations = load_sharegpt_annotations(json_path)
samples = []
for item in annotations:
# The "image" field is relative to the root, e.g., "images/000001.jpg"
img_rel_path = item["image"]
# Extract just the filename in case the path includes "images/" already
img_filename = os.path.basename(img_rel_path)
img_abs_path = os.path.join(image_root, img_filename)
# Fallback: if the path in JSON includes a directory, try that too
if not os.path.exists(img_abs_path):
img_abs_path = os.path.join(image_root, img_rel_path.replace("images/", ""))
image = Image.open(img_abs_path).convert("RGB")
# Extract prompt and response
human_turn = item["conversations"][0]
gpt_turn = item["conversations"][1]
samples.append({
"image": image,
"prompt": human_turn["value"],
"response": gpt_turn["value"]
})
return samples
# Load all samples
all_samples = load_sharegpt_samples("devanagari_ocr.json")
print(f"Total samples: {len(all_samples)}")
```
### Step 3: Create Your Own Train/Val/Test Splits
Since no predefined splits exist, we recommend creating reproducible splits using `sklearn`:
```python
from sklearn.model_selection import train_test_split
# 80% train, 10% val, 10% test
train, temp = train_test_split(all_samples, test_size=0.2, random_state=42)
val, test = train_test_split(temp, test_size=0.5, random_state=42)
print(f"Train: {len(train)}, Val: {len(val)}, Test: {len(test)}")
```
For domain-specific evaluation (e.g., Nepali-only), you can filter by source metadata if included, or use the language tags (some entries may have `metadata.language`).
---
## Source Compilation Details
| Source Repository | Domain | Languages | Notes |
| :--- | :--- | :--- | :--- |
| `gauravgiri/nepali-ocr-dataset` | Printed page OCR | Nepali | Main source for Nepali printed text |
| `Malathip72/devanagari-ocr-dataset` | Page OCR | Pali/Sanskrit | Useful for script generalization |
| `rockerritesh/devanagari_and_roman_digits` | Digit recognition | Nepali/Hindi/English | Mixed Devanagari/Latin numerals |
| `krutrim-ai-labs/IndicVisionBench` (OCR config) | Page OCR | Hindi, Marathi | High-quality page-level data |
| `darknight054/indic-mozhi-ocr` | Word OCR | Hindi, Marathi | Cropped word-level recognition |
| `c3rl/IIIT-INDIC-HW-WORDS-Hindi` | Handwritten word OCR | Hindi | Handwritten names and words |
| `Nayana-cognitivelab/NayanaBench` | Document layout / VQA | Hindi, Marathi, Sanskrit | Complex layouts, useful for RAG |
*Duplicates (e.g., `vishwam-101/devanagari-ocr-dataset`) were manually excluded to prevent data leakage.*
---
## Intended Uses
1. **Fine-tuning GLM-OCR / other VLMs** on Devanagari script recognition.
2. **Nepali / Hindi / Marathi document digitization** pipelines.
---
## Limitations and Biases
- **Geographic bias**: Primarily drawn from academic datasets; may not represent mobile-captured, low-quality, or highly cursive regional scripts.
- **Mixed numerals**: Digit datasets contain both Devanagari and Latin numerals. If you require pure Devanagari output, apply a regex filter during post-processing.
- **Pali/Sanskrit content**: The page-OCR subset includes Pali/Sanskrit, which has different lexical patterns than modern Nepali/Hindi — useful for script learning but not for language-specific semantic tasks.
- **Storage requirements**: ~58 GB extracted. Ensure sufficient disk space.
- **No fixed splits**: Users must create their own splits. We recommend a reproducible random seed (e.g., 42) for consistency across experiments.
---
## Evaluation Metrics
When evaluating your model, we recommend:
- **CER** (Character Error Rate)
- **WER** (Word Error Rate)
- **Exact Match** (for short strings like digits or isolated words)
Compute these on the `gpt` response field against your model's decoded output.
---
## Citation
If you use this compiled dataset, please cite:
```bibtex
@misc{devanagari_ocr_dataset,
author = {himalaya-ai},
title = {Devanagari Compiled Dataset (ShareGPT)},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/datasets/himalaya-ai/devanagari_ocr_dataset}
}
```
Additionally, please cite the individual source datasets listed in the Source Compilation table based on their respective repository documentation.
---
## Contact & Feedback
For questions, issues, or extraction problems, please open an issue on the Hugging Face repository. Contributions and suggestions are welcome!