Maksonchek commited on
Commit
4c8742b
·
verified ·
1 Parent(s): 9b84c8c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +233 -47
README.md CHANGED
@@ -1,47 +1,233 @@
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
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ---
48
+
49
+ ---
50
+ pretty_name: "CodeOCR Dataset (Python Code Images + Ground Truth)"
51
+ license: mit
52
+ language:
53
+ - en
54
+ task_categories:
55
+ - image-to-text
56
+ tags:
57
+ - ocr
58
+ - code
59
+ - python
60
+ - leetcode
61
+ - synthetic
62
+ - computer-vision
63
+ size_categories:
64
+ - 1K<n<10K
65
+ ---
66
+
67
+ # CodeOCR Dataset (Python Code Images + Ground Truth)
68
+
69
+ This dataset is designed for **Optical Character Recognition (OCR) of source code**.
70
+ Each example pairs **Python code (ground-truth text)** with **image renderings** of that code (light/dark themes) and a **real photo**.
71
+
72
+ ## Dataset Summary
73
+
74
+ - **Language:** Python (text ground truth), images of code
75
+ - **Splits:** `easy`, `medium`, `hard`
76
+ - **Total examples:** 1,000
77
+ - `easy`: 700
78
+ - `medium`: 200
79
+ - `hard`: 100
80
+ - **Modalities:** image + text
81
+
82
+ ### What is “ground truth” here?
83
+
84
+ The `code` field is **exactly the content of `gt.py`** used to generate the synthetic renderings.
85
+ During dataset creation, code is normalized to ensure stable GT properties:
86
+
87
+ - UTF-8 encoding
88
+ - newline normalization to **LF (`\n`)**
89
+ - tabs expanded to **4 spaces**
90
+ - syntax checked with Python `compile()` (syntax/indentation correctness)
91
+
92
+ This makes the dataset suitable for training/evaluating OCR models that output **plain code text**.
93
+
94
+ ---
95
+
96
+ ## Data Fields
97
+
98
+ Each row contains:
99
+
100
+ - `id` *(string)*: sample identifier (e.g., `easy_000123`)
101
+ - `difficulty` *(string)*: `easy` / `medium` / `hard`
102
+ - `code` *(string)*: **ground-truth Python code**
103
+ - `render_light` *(image)*: synthetic rendering (light theme)
104
+ - `render_dark` *(image)*: synthetic rendering (dark theme)
105
+ - `photo` *(image)*: real photo of the code
106
+
107
+ ---
108
+
109
+ ## How to Use
110
+
111
+ ### Load with 🤗 Datasets
112
+
113
+ ```python
114
+ from datasets import load_dataset
115
+
116
+ ds = load_dataset("maksonchek/codeocr-dataset")
117
+ print(ds)
118
+ print(ds["easy"][0].keys())
119
+ ```
120
+
121
+ ### Access code and images
122
+
123
+ ```python
124
+ ex = ds["easy"][0]
125
+
126
+ # Ground-truth code
127
+ print(ex["code"][:500])
128
+
129
+ # Images are stored as `datasets.Image` features.
130
+ render = ex["render_light"]
131
+ print(render)
132
+ ```
133
+
134
+ If your environment returns image dicts with local paths:
135
+
136
+ ```python
137
+ from PIL import Image
138
+
139
+ img = Image.open(ex["render_light"]["path"])
140
+ img.show()
141
+ ```
142
+
143
+ Real photo (always present in this dataset):
144
+
145
+ ```python
146
+ from PIL import Image
147
+
148
+ photo = Image.open(ex["photo"]["path"])
149
+ photo.show()
150
+ ```
151
+
152
+ ---
153
+
154
+ ## Dataset Creation
155
+
156
+ ### 1) Code selection
157
+ Python solutions were collected from an open-source repository of LeetCode solutions (MIT licensed).
158
+
159
+ ### 2) Normalization to produce stable GT
160
+ The collected code is written into `gt.py` after:
161
+
162
+ - newline normalization to LF
163
+ - tab expansion to 4 spaces
164
+ - basic cleanup (no hidden control characters)
165
+ - Python syntax check via `compile()`
166
+
167
+ ### 3) Synthetic rendering
168
+ Synthetic images are generated from the normalized `gt.py` in:
169
+
170
+ - light theme (`render_light`)
171
+ - dark theme (`render_dark`)
172
+
173
+ ### 4) Real photos
174
+ Real photos are manually captured and linked **for every sample**.
175
+
176
+ ---
177
+
178
+ ## Statistics (high-level)
179
+
180
+ Average code length by difficulty (computed on this dataset):
181
+
182
+ - `easy`: ~27 lines, ~669 chars
183
+ - `medium`: ~36 lines, ~997 chars
184
+ - `hard`: ~55 lines, ~1767 chars
185
+
186
+ (Exact values may vary if the dataset is extended.)
187
+
188
+ ---
189
+
190
+ ## Intended Use
191
+
192
+ - OCR for programming code
193
+ - robust text extraction from screenshot-like renders and real photos
194
+ - benchmarking OCR pipelines for code formatting / indentation preservation
195
+
196
+ ### Not Intended Use
197
+
198
+ - generating or re-distributing problem statements
199
+ - competitive programming / cheating use-cases
200
+
201
+ ---
202
+
203
+ ## Limitations
204
+
205
+ - Code is checked for **syntax correctness**, but not necessarily for runtime correctness.
206
+ - Rendering style is controlled and may differ from real-world photos.
207
+
208
+ ---
209
+
210
+ ## License & Attribution
211
+
212
+ This dataset is released under the **MIT License**.
213
+
214
+ The included solution code is derived from **kamyu104/LeetCode-Solutions** (MIT License):
215
+ https://github.com/kamyu104/LeetCode-Solutions
216
+
217
+ If you use this dataset in academic work, please cite the dataset and credit the original solution repository.
218
+
219
+ ---
220
+
221
+ ## Citation
222
+
223
+ ### BibTeX
224
+
225
+ ```bibtex
226
+ @dataset{codeocr_leetcode_2025,
227
+ author = {Maksonchek},
228
+ title = {CodeOCR Dataset (Python Code Images + Ground Truth)},
229
+ year = {2025},
230
+ publisher = {Hugging Face},
231
+ url = {https://huggingface.co/datasets/maksonchek/codeocr-dataset}
232
+ }
233
+ ```