Maksonchek commited on
Commit
9b84c8c
·
verified ·
1 Parent(s): 2386d7e

Update README.md

Browse files

---
pretty_name: "CodeOCR Dataset (Python Code Images + Ground Truth)"
license: mit
language:
- en
task_categories:
- image-to-text
tags:
- ocr
- code
- python
- leetcode
- synthetic
- computer-vision
size_categories:
- 1K<n<10K
---

# CodeOCR Dataset (Python Code Images + Ground Truth)

This dataset is designed for **Optical Character Recognition (OCR) of source code**.
Each example pairs **Python code (ground-truth text)** with **image renderings** of that code (light/dark themes) and an optional **real photo**.

## Dataset Summary

- **Language:** Python (text ground truth), images of code
- **Splits:** `easy`, `medium`, `hard`
- **Total examples:** 1,000
- `easy`: 700
- `medium`: 200
- `hard`: 100
- **Modalities:** image + text

### What is “ground truth” here?

The `code` field is **exactly the content of `gt.py`** used to generate the synthetic renderings.
During dataset creation, code is normalized to ensure stable GT properties:

- UTF-8 encoding
- newline normalization to **LF (`\n`)**
- tabs expanded to **4 spaces**
- syntax checked with Python `compile()` (syntax/indentation correctness)

This makes the dataset suitable for training/evaluating OCR models that output **plain code text**.

---

## Data Fields

Each row contains:

- `id` *(string)*: sample identifier (e.g., `easy_000123`)
- `difficulty` *(string)*: `easy` / `medium` / `hard`
- `code` *(string)*: **ground-truth Python code**
- `render_light` *(image)*: synthetic rendering (light theme)
- `render_dark` *(image)*: synthetic rendering (dark theme)
- `photo` *(image, optional)*: real photo of the code (may be `null`/missing)

---

## How to Use

### Load with Datasets

```python
from datasets import load_dataset

ds = load_dataset("maksonchek/codeocr-dataset")
print(ds)
print(ds["easy"][0].keys())
```

### Access code and images
```python
ex = ds["easy"][0]

# Ground-truth code
print(ex["code"][:500])

# Images are stored as `datasets.Image` features.
# Depending on decoding, you can access PIL image or a dict with a local path.
render = ex["render_light"]
print(render)
```

## Statistics (high-level)

Average code length by difficulty (computed on this dataset):

easy: ~27 lines, ~669 chars

medium: ~36 lines, ~997 chars

hard: ~55 lines, ~1767 chars

(Exact values may vary if the dataset is extended.)

## License & Attribution

This dataset is released under the MIT License.

The included solution code is derived from kamyu104/LeetCode-Solutions (MIT License):
https://github.com/kamyu104/LeetCode-Solutions

If you use this dataset in academic work, please cite the dataset and credit the original solution repository.

## Citation
```bibtex
@dataset {codeocr_leetcode_2025,
author = {Maksonchek},
title = {CodeOCR Dataset (Python Code Images + Ground Truth)},
year = {2025},
publisher = {Hugging Face},
url = {https://huggingface.co/datasets/maksonchek/codeocr-dataset}
}
```

Files changed (1) hide show
  1. README.md +47 -37
README.md CHANGED
@@ -1,37 +1,47 @@
1
- ---
2
- dataset_info:
3
- features:
4
- - name: id
5
- dtype: string
6
- - name: difficulty
7
- dtype: string
8
- - name: code
9
- dtype: string
10
- - name: render_light
11
- dtype: image
12
- - name: render_dark
13
- dtype: image
14
- - name: photo
15
- dtype: image
16
- splits:
17
- - name: easy
18
- num_bytes: 3086674334
19
- num_examples: 700
20
- - name: medium
21
- num_bytes: 902595780
22
- num_examples: 200
23
- - name: hard
24
- num_bytes: 500128560
25
- num_examples: 100
26
- download_size: 4485774053
27
- dataset_size: 4489398674
28
- configs:
29
- - config_name: default
30
- data_files:
31
- - split: easy
32
- path: data/easy-*
33
- - split: medium
34
- path: data/medium-*
35
- - split: hard
36
- path: data/hard-*
37
- ---
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ dataset_info:
3
+ features:
4
+ - name: id
5
+ dtype: string
6
+ - name: difficulty
7
+ dtype: string
8
+ - name: code
9
+ dtype: string
10
+ - name: render_light
11
+ dtype: image
12
+ - name: render_dark
13
+ dtype: image
14
+ - name: photo
15
+ dtype: image
16
+ splits:
17
+ - name: easy
18
+ num_bytes: 3086674334
19
+ num_examples: 700
20
+ - name: medium
21
+ num_bytes: 902595780
22
+ num_examples: 200
23
+ - name: hard
24
+ num_bytes: 500128560
25
+ num_examples: 100
26
+ download_size: 4485774053
27
+ dataset_size: 4489398674
28
+ configs:
29
+ - config_name: default
30
+ data_files:
31
+ - split: easy
32
+ path: data/easy-*
33
+ - split: medium
34
+ path: data/medium-*
35
+ - split: hard
36
+ path: data/hard-*
37
+ license: mit
38
+ task_categories:
39
+ - image-to-text
40
+ - text-generation
41
+ tags:
42
+ - code
43
+ - ocr
44
+ pretty_name: CodeOCR
45
+ size_categories:
46
+ - 1K<n<10K
47
+ ---