Empatixx commited on
Commit
f51c151
·
verified ·
1 Parent(s): 41366bb

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +224 -3
README.md CHANGED
@@ -1,3 +1,224 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+ # Czech Synthetic Multiline Text Recognition Dataset
5
+
6
+ A large-scale synthetic dataset for Czech multiline text recognition, containing 100,000 text images with corresponding transcriptions. Created using [SynthTiger](https://github.com/clovaai/synthtiger).
7
+
8
+ ## Dataset Description
9
+
10
+ This dataset consists of synthetically generated images of Czech text with multiple lines per image, designed for training optical character recognition (OCR) models that can handle complex multiline text layouts. Each image contains approximately 10 lines of Czech text rendered with various fonts and alignments.
11
+
12
+ ### Dataset Statistics
13
+ - **Total samples**: 100,000 image-text pairs
14
+ - **Language**: Czech (cs_CZ)
15
+ - **Lines per image**: ~10 lines
16
+ - **Image format**: JPEG
17
+ - **Storage format**: Parquet files (10 files total)
18
+ - **Total size**: ~6.3 GB
19
+
20
+ ## Dataset Structure
21
+
22
+ The dataset is organized into 10 Parquet files for efficient storage and loading:
23
+
24
+ ```
25
+ data/
26
+ ├── train-00000-of-00010.parquet # 10,000 samples
27
+ ├── train-00001-of-00010.parquet # 10,000 samples
28
+ ├── ...
29
+ ├── train-00008-of-00010.parquet # 10,000 samples
30
+ └── train-00009-of-00010.parquet # 10,000 samples
31
+ ```
32
+
33
+ Each Parquet file contains two columns:
34
+ - `image`: PIL Image object (JPEG format, properly typed for HuggingFace)
35
+ - `text`: Ground truth text transcription (multiple lines)
36
+
37
+ ## Usage
38
+
39
+ ### Loading with Hugging Face Datasets
40
+
41
+ ```python
42
+ from datasets import load_dataset
43
+
44
+ # Load the entire dataset
45
+ dataset = load_dataset("Empatixx/synth-text-recognition-multilines-cs")
46
+
47
+ # Access samples
48
+ sample = dataset['train'][0]
49
+ image = sample['image'] # PIL Image object
50
+ text = sample['text'] # Multiline text transcription
51
+
52
+ # Load specific splits or streaming
53
+ dataset = load_dataset("Empatixx/synth-text-recognition-multilines-cs", split="train[:1000]") # First 1000 samples
54
+ dataset = load_dataset("Empatixx/synth-text-recognition-multilines-cs", streaming=True) # Stream the dataset
55
+ ```
56
+
57
+ ### Working with Multiline Text
58
+
59
+ ```python
60
+ # Split text into individual lines
61
+ sample = dataset['train'][0]
62
+ lines = sample['text'].split('\n')
63
+ print(f"Number of lines: {len(lines)}")
64
+ for i, line in enumerate(lines):
65
+ print(f"Line {i+1}: {line}")
66
+ ```
67
+
68
+ ### PyTorch DataLoader Example
69
+
70
+ ```python
71
+ from datasets import load_dataset
72
+ from torch.utils.data import DataLoader
73
+ from torchvision import transforms
74
+ import torch
75
+
76
+ # Load dataset
77
+ dataset = load_dataset("Empatixx/synth-text-recognition-multilines-cs")
78
+
79
+ # Define transforms
80
+ transform = transforms.Compose([
81
+ transforms.Resize((512, 512)), # Larger size for multiline text
82
+ transforms.ToTensor(),
83
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
84
+ ])
85
+
86
+ # Create DataLoader
87
+ def collate_fn(batch):
88
+ images = [transform(sample['image']) for sample in batch]
89
+ texts = [sample['text'] for sample in batch]
90
+ return torch.stack(images), texts
91
+
92
+ dataloader = DataLoader(
93
+ dataset['train'],
94
+ batch_size=16, # Smaller batch size due to larger images
95
+ shuffle=True,
96
+ collate_fn=collate_fn
97
+ )
98
+ ```
99
+
100
+ ### TrOCR Fine-tuning Example
101
+
102
+ ```python
103
+ from transformers import TrOCRProcessor, VisionEncoderDecoderModel
104
+ from datasets import load_dataset
105
+ import torch
106
+
107
+ # Load model and processor
108
+ processor = TrOCRProcessor.from_pretrained("microsoft/trocr-base-handwritten")
109
+ model = VisionEncoderDecoderModel.from_pretrained("microsoft/trocr-base-handwritten")
110
+
111
+ # Load dataset
112
+ dataset = load_dataset("Empatixx/synth-text-recognition-multilines-cs")
113
+
114
+ # Preprocessing function
115
+ def preprocess_function(examples):
116
+ # Process images
117
+ pixel_values = processor(images=examples['image'], return_tensors="pt").pixel_values
118
+
119
+ # Process text labels
120
+ labels = processor.tokenizer(
121
+ examples['text'],
122
+ padding=True,
123
+ truncation=True,
124
+ max_length=512 # Longer for multiline text
125
+ ).input_ids
126
+
127
+ return {
128
+ 'pixel_values': pixel_values,
129
+ 'labels': labels
130
+ }
131
+
132
+ # Apply preprocessing
133
+ processed_dataset = dataset.map(preprocess_function, batched=True)
134
+ ```
135
+
136
+ ## Generation Details
137
+
138
+ The dataset was generated using SynthTiger with the following characteristics:
139
+
140
+ ### Text Sources
141
+ - Czech words from Czech corpus (524,474 unique words)
142
+ - Text lengths: 1-25 characters per line
143
+ - Lines per image: 10 lines (configurable)
144
+ - Character set: Full Czech alphabet including diacritics
145
+
146
+ ### Visual Variations
147
+ - **Image size**: 1024x1024 pixels canvas
148
+ - **Fonts**: Multiple font families with sizes 32-64px
149
+ - **Font weight**: 50% probability of bold text
150
+ - **Colors**: Black text on white background
151
+ - **Text alignment**: Left, center, right, and justify
152
+ - **Line spacing**: 0-16 pixels between lines
153
+ - **Text case**: Lowercase, uppercase, and capitalized variations
154
+
155
+ ### Layout Properties
156
+ - **Orientation**: Horizontal text (left-to-right)
157
+ - **Line arrangement**: Top-to-bottom
158
+ - **Text positioning**: Centered on canvas with variable line heights
159
+ - **Real-world simulation**: Natural text flow with proper line breaks
160
+
161
+ ## Dataset Creation
162
+
163
+ The dataset was created using the following process:
164
+
165
+ 1. **Text Selection**: Random selection of Czech words from corpus
166
+ 2. **Line Generation**: Combining words to create 10 lines per image
167
+ 3. **Layout Computation**: Calculating positions for multiline text rendering
168
+ 4. **Visual Rendering**: Text rendered with random fonts and alignments
169
+ 5. **Image Generation**: Creating final images with proper spacing and layout
170
+ 6. **Format Conversion**: Converting to HuggingFace-compatible Parquet format
171
+
172
+ ### Generation Command
173
+
174
+ The dataset was generated using:
175
+ ```bash
176
+ synthtiger -o results_100k_lines -c 100000 -w 8 -v examples/multiline/template.py Multiline examples/multiline/config.yaml
177
+ ```
178
+
179
+ ## Use Cases
180
+
181
+ This multiline dataset is particularly suitable for:
182
+
183
+ 1. **Document OCR**: Training models for document text extraction
184
+ 2. **Multiline Recognition**: Models that need to handle multiple text lines
185
+ 3. **Layout Analysis**: Understanding text structure and organization
186
+ 4. **Czech Language Models**: Specialized OCR for Czech text
187
+ 5. **Benchmark Dataset**: Evaluating multiline OCR performance
188
+
189
+ ## Citation
190
+
191
+ If you use this dataset, please cite:
192
+
193
+ ```bibtex
194
+ @misc{czech-synth-multiline-text-2025,
195
+ title={Czech Synthetic Multiline Text Recognition Dataset},
196
+ author={Empatixx},
197
+ year={2025},
198
+ publisher={Hugging Face},
199
+ url={https://huggingface.co/datasets/Empatixx/synth-text-recognition-multilines-cs}
200
+ }
201
+ ```
202
+
203
+ Also cite the SynthTiger paper:
204
+
205
+ ```bibtex
206
+ @inproceedings{yim2021synthtiger,
207
+ title={SynthTiger: Synthetic Text Image GEneratoR Towards Better Text Recognition Models},
208
+ author={Yim, Moonbin and Kim, Yoonsik and Cho, Han-Cheol and Park, Sungrae},
209
+ booktitle={International Conference on Document Analysis and Recognition},
210
+ pages={109--124},
211
+ year={2021},
212
+ organization={Springer}
213
+ }
214
+ ```
215
+
216
+ ## License
217
+
218
+ This dataset is released under the MIT license, following the SynthTiger licensing terms.
219
+
220
+ ## Acknowledgments
221
+
222
+ - Dataset generated using [SynthTiger](https://github.com/clovaai/synthtiger)
223
+ - Czech word corpus with 524,474 unique Czech words
224
+ - Multiline template configuration for realistic document-like text layouts