Image-to-Text
Transformers
Sinhala
trocr
ocr
sinhala
printed-text
vision-encoder-decoder
kaan84 commited on
Commit
18fcd7f
Β·
verified Β·
1 Parent(s): 1d9d2b7

Add Phase 0 research package

Browse files
.gitignore ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ .env
5
+ .DS_Store
6
+ checkpoints/
7
+ wandb/
8
+ results/predictions/
9
+ *.bin
10
+ *.pt
11
+ *.pth
12
+
ATTRIBUTION_AND_LICENSING.md ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Attribution and Licensing Record
2
+
3
+ This file tracks asset-level licensing. It is not legal advice.
4
+
5
+ ## Release decision
6
+
7
+ The project metadata uses `license: other` with a pending-clarification label. The dataset is MIT-licensed, but the intermediate checkpoint has no declared license. Public release of derivative weights remains blocked.
8
+
9
+ | Asset | Role | Recorded status | Required action |
10
+ |---|---|---|---|
11
+ | `microsoft/trocr-base-printed` | Ultimate base | MIT via Microsoft UniLM | Retain attribution and MIT notice |
12
+ | `Ransaka/TrOCR-Sinhala` | Intermediate checkpoint | No declared license | Obtain explicit clarification before publishing derivative weights |
13
+ | `Ransaka/sinhala_synthetic_ocr-large` | Training data | MIT `LICENSE`; DOI 10.57967/hf/1809 | Attribute Ransaka Ravihara and cite DOI |
14
+ | `avishadilhara/sinhala-ocr-lk-acts-1010` | Evaluation source | CC BY 4.0 | Attribute authors and cite source |
15
+ | Tesseract | Baseline | Apache 2.0 | Record version and cite |
16
+ | Surya OCR | Optional baseline | Version-dependent code and model terms | Re-check terms at execution time |
17
+
18
+ ## Mandatory evidence to add
19
+
20
+ - Link to the checkpoint license-clarification discussion
21
+ - Author response or other permission record
22
+ - Immutable revisions for all Hub assets
23
+ - Copies or links to applicable notices at public release
24
+
25
+ ## Citations
26
+
27
+ ### TrOCR
28
+
29
+ ```bibtex
30
+ @article{li2021trocr,
31
+ title={TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models},
32
+ author={Li, Minghao and Lv, Tengchao and Cui, Lei and Lu, Yijuan and Florencio, Dinei and Zhang, Cha and Li, Zhoujun and Wei, Furu},
33
+ journal={arXiv preprint arXiv:2109.10282},
34
+ year={2021}
35
+ }
36
+ ```
37
+
38
+ ### Synthetic Sinhala OCR dataset
39
+
40
+ ```bibtex
41
+ @misc{ravihara2024sinhala,
42
+ author={Ransaka Ravihara},
43
+ title={sinhala_synthetic_ocr-large},
44
+ year={2024},
45
+ publisher={Hugging Face},
46
+ doi={10.57967/hf/1809},
47
+ url={https://huggingface.co/datasets/Ransaka/sinhala_synthetic_ocr-large}
48
+ }
49
+ ```
50
+
51
+ ### Real Sinhala legislative-acts benchmark
52
+
53
+ Add the authors' preferred BibTeX from arXiv:2606.29378 before publication. Do not reconstruct bibliographic details from memory when the canonical citation is available.
54
+
PROTOCOL.md ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Pre-registered Research Protocol
2
+
3
+ ## 1. Administrative record
4
+
5
+ - Project: TrOCR Sinhala Printed Lines
6
+ - Protocol version: 1.0
7
+ - Protocol date: 2026-07-28
8
+ - Researcher: Kalana Hewapathirana
9
+ - Planned repository: `kaan84/trocr-sinhala-printed-lines`
10
+ - Phase: Phase 0, before training
11
+
12
+ Commit this file before training. Any later change must be appended to the deviation log with its date, rationale, and expected impact.
13
+
14
+ ## 2. Research question
15
+
16
+ Does synthetic-data fine-tuning of `Ransaka/TrOCR-Sinhala` improve printed, line-level Sinhala OCR on real documents?
17
+
18
+ ## 3. Hypotheses
19
+
20
+ ### Primary hypothesis H1
21
+
22
+ Fine-tuning the starting checkpoint on `Ransaka/sinhala_synthetic_ocr-large` will reduce CER on a real printed Sinhala line benchmark relative to the unchanged checkpoint and Tesseract 5.5.
23
+
24
+ ### Secondary hypothesis H2
25
+
26
+ The fine-tuned checkpoint will reduce WER relative to the unchanged checkpoint and Tesseract 5.5.
27
+
28
+ ### Secondary hypothesis H3
29
+
30
+ Performance will be lower on older or visibly degraded documents than on newer or cleaner documents.
31
+
32
+ ## 4. Experimental unit and scope
33
+
34
+ The evaluation unit is one cropped text-line image paired with one reference transcription. Page-level and line-level metrics must not be combined in the same comparison table without an explicit unit label.
35
+
36
+ Included:
37
+
38
+ - Printed Sinhala
39
+ - Real and synthetic text lines
40
+ - CER and WER
41
+ - Starting checkpoint and Tesseract comparisons
42
+ - Optional Surya comparison
43
+
44
+ Excluded:
45
+
46
+ - Handwriting
47
+ - End-to-end page layout analysis
48
+ - Production-readiness claims
49
+ - Hyperparameter optimization outside the declared contingency rules
50
+
51
+ ## 5. Assets and fixed revisions
52
+
53
+ Before training, replace `TO_RECORD` with immutable Hub commit hashes:
54
+
55
+ | Asset | Role | Revision |
56
+ |---|---|---|
57
+ | `Ransaka/TrOCR-Sinhala` | Starting model | `TO_RECORD` |
58
+ | `Ransaka/sinhala_synthetic_ocr-large` | Train/validation | `TO_RECORD` |
59
+ | `avishadilhara/sinhala-ocr-lk-acts-1010` | Real evaluation source | `TO_RECORD` |
60
+
61
+ The experiment manifest must also record the Transformers, Datasets, PyTorch, CUDA, jiwer, Pillow, NumPy, and Tesseract versions.
62
+
63
+ ## 6. Data splits
64
+
65
+ ### Synthetic dataset
66
+
67
+ Use the published dataset's single train split.
68
+
69
+ - Split seed: 42
70
+ - Train share: 90%
71
+ - Validation share: 10%
72
+ - Split method: deterministic shuffled index split
73
+ - No sample may appear in both partitions
74
+ - Save the exact indices to version-controlled JSON files
75
+ - Record SHA-256 checksums of the index files
76
+
77
+ ### Real-document benchmark
78
+
79
+ Use only the published test partition for the final real-document analysis. Do not use its labels for training or hyperparameter selection.
80
+
81
+ Because the source is page-level, create line crops and transcriptions using one versioned procedure. Record:
82
+
83
+ - Source page identifier
84
+ - Line identifier
85
+ - Crop coordinates
86
+ - Reference transcription
87
+ - Segmentation method and version
88
+ - Any exclusion reason
89
+ - Document year or period, if available
90
+
91
+ Freeze the line benchmark before final evaluation. Manual corrections made after viewing model predictions invalidate the final test and must trigger a new held-out test set.
92
+
93
+ ## 7. Preprocessing
94
+
95
+ ### Images
96
+
97
+ - Convert to RGB
98
+ - Use the processor associated with the starting checkpoint
99
+ - Do not apply test-time enhancement unless declared as a separate experimental condition
100
+ - Preserve raw evaluation crops
101
+
102
+ ### Text normalization
103
+
104
+ Report both raw and normalized metrics.
105
+
106
+ The fixed normalized condition:
107
+
108
+ 1. Unicode normalize with NFC.
109
+ 2. Convert line breaks and tabs to spaces.
110
+ 3. Collapse consecutive Unicode whitespace to one ASCII space.
111
+ 4. Strip leading and trailing whitespace.
112
+ 5. Preserve Sinhala characters, punctuation, numerals, and letter case.
113
+
114
+ Do not remove punctuation or diacritics in the primary analysis. Any alternative normalization is exploratory and must be labeled accordingly.
115
+
116
+ ## 8. Training configuration
117
+
118
+ | Parameter | Fixed value |
119
+ |---|---|
120
+ | Model | `Ransaka/TrOCR-Sinhala` |
121
+ | Optimizer | AdamW |
122
+ | Learning rate | 4e-5 |
123
+ | Epochs | 10 |
124
+ | Effective batch size | 8 |
125
+ | Precision | FP16 if supported |
126
+ | Seeds | 42, 123, 2026 |
127
+ | Generation beams | 4 |
128
+ | Save strategy | Every epoch |
129
+ | Selection rule | Lowest validation CER |
130
+
131
+ Gradient accumulation may change only to preserve effective batch size 8. Physical batch size may be lowered for memory limits.
132
+
133
+ ## 9. Contingency rules
134
+
135
+ Permitted without redefining hypotheses:
136
+
137
+ - Reduce physical batch size and increase gradient accumulation.
138
+ - Resume from the latest complete checkpoint after infrastructure interruption.
139
+ - Use gradient checkpointing if the GPU cannot hold the declared effective batch.
140
+ - Disable FP16 only if the hardware or software fails to support it reliably.
141
+
142
+ Not permitted in the confirmatory experiment:
143
+
144
+ - Selecting a new learning rate after inspecting final-test results
145
+ - Increasing epochs because final-test performance is weak
146
+ - Training on real-test labels
147
+ - Removing difficult samples based on prediction errors
148
+ - Reporting only the best seed
149
+
150
+ Any other adjustment becomes exploratory and must be separated from confirmatory results.
151
+
152
+ ## 10. Baselines
153
+
154
+ Required:
155
+
156
+ 1. Unchanged `Ransaka/TrOCR-Sinhala`
157
+ 2. Tesseract 5.5
158
+ 3. Fine-tuned TrOCR for all three seeds
159
+
160
+ Optional:
161
+
162
+ 4. Surya OCR, only after recording the exact version and applicable model terms
163
+
164
+ Every system must receive the same frozen line images. Use system-appropriate decoding without model-specific alteration of references.
165
+
166
+ ## 11. Metrics
167
+
168
+ Primary: Character Error Rate.
169
+
170
+ Secondary: Word Error Rate.
171
+
172
+ Use `jiwer` with transformations that exactly implement Section 7. Compute:
173
+
174
+ - Per-sample edit counts
175
+ - Corpus-level raw CER and WER
176
+ - Corpus-level normalized CER and WER
177
+ - Mean and standard deviation across training seeds
178
+ - Paired bootstrap 95% confidence interval for differences, resampling line IDs with 10,000 replicates and bootstrap seed 42
179
+
180
+ ## 12. Decision rules
181
+
182
+ H1 is supported only when:
183
+
184
+ 1. The fine-tuned model's mean normalized CER is lower than both the starting checkpoint and Tesseract 5.5.
185
+ 2. Improvement over each comparator has a paired-bootstrap 95% confidence interval that excludes zero in the favorable direction.
186
+ 3. All three fine-tuning seeds improve over the starting checkpoint.
187
+
188
+ H2 uses the same rule with normalized WER.
189
+
190
+ H3 is descriptive unless each period contains at least 30 evaluation lines. Report counts and confidence intervals and avoid strong generalization when slices are small.
191
+
192
+ Publish results regardless of outcome. A result above published page-level baselines is not automatically a failure because the evaluation units differ.
193
+
194
+ ## 13. Error analysis
195
+
196
+ Before viewing predictions, define these error groups:
197
+
198
+ - Character substitution
199
+ - Character deletion
200
+ - Character insertion
201
+ - Whitespace or word-boundary error
202
+ - Punctuation or numeral error
203
+ - Degraded print
204
+ - Skew or rotation
205
+ - Segmentation failure
206
+ - Mixed-language or unsupported symbol
207
+
208
+ Sample up to 50 errors using a deterministic random seed. Do not select only visually compelling cases.
209
+
210
+ ## 14. Reporting requirements
211
+
212
+ The final report must include:
213
+
214
+ - Every seed
215
+ - Mean and standard deviation
216
+ - Confidence intervals
217
+ - Dataset and code revisions
218
+ - Hardware and runtime
219
+ - Raw and normalized metrics
220
+ - Exact evaluation-unit counts
221
+ - Exclusion counts and reasons
222
+ - Period-stratified results when valid
223
+ - Known limitations
224
+ - Deviations from this protocol
225
+
226
+ ## 15. Licensing gate
227
+
228
+ The training dataset license is confirmed MIT. The intermediate checkpoint currently has no declared license. Training experiments may be prepared, but public redistribution of derivative weights is blocked until the checkpoint licensing position is clarified or independently reviewed.
229
+
230
+ ## 16. Deviation log
231
+
232
+ | Date | Change | Rationale | Expected impact | Confirmatory or exploratory |
233
+ |---|---|---|---|---|
234
+ | β€” | None | β€” | β€” | β€” |
235
+
README.md ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ο»Ώ---
2
+ language:
3
+ - si
4
+ license: other
5
+ license_name: pending-upstream-checkpoint-license-clarification
6
+ library_name: transformers
7
+ pipeline_tag: image-to-text
8
+ tags:
9
+ - trocr
10
+ - ocr
11
+ - sinhala
12
+ - printed-text
13
+ - vision-encoder-decoder
14
+ base_model: Ransaka/TrOCR-Sinhala
15
+ datasets:
16
+ - Ransaka/sinhala_synthetic_ocr-large
17
+ - avishadilhara/sinhala-ocr-lk-acts-1010
18
+ metrics:
19
+ - cer
20
+ - wer
21
+ ---
22
+
23
+ # TrOCR Sinhala Printed Lines
24
+
25
+ > Phase 0 research repository. No fine-tuned weights or final evaluation results have been released yet.
26
+
27
+ This project investigates whether fine-tuning `Ransaka/TrOCR-Sinhala` on synthetic Sinhala text-line images improves printed, line-level Sinhala OCR performance on real documents.
28
+
29
+ ## Project status
30
+
31
+ | Workstream | Status |
32
+ |---|---|
33
+ | Research scope | Locked in `PROTOCOL.md` |
34
+ | Dataset license | Confirmed MIT |
35
+ | Intermediate checkpoint license | Clarification required |
36
+ | Training | Not started |
37
+ | Evaluation | Not started |
38
+ | Model weights | Not published |
39
+
40
+ The synthetic dataset contains an MIT `LICENSE` file. However, `Ransaka/TrOCR-Sinhala` does not currently declare a license. This repository therefore uses `license: other` as a temporary, conservative status. Do not publish or redistribute derived weights until the checkpoint author provides a clear license or the release basis is independently reviewed.
41
+
42
+ ## Research question
43
+
44
+ Does synthetic-data fine-tuning of TrOCR improve printed, line-level Sinhala OCR on real documents?
45
+
46
+ ## Scope
47
+
48
+ ### In scope
49
+
50
+ - Printed Sinhala text
51
+ - Line-level text recognition
52
+ - Character Error Rate (CER)
53
+ - Word Error Rate (WER)
54
+ - Comparisons with the unmodified checkpoint and Tesseract 5.5
55
+ - Optional Surya comparison when its applicable terms are confirmed
56
+ - Period-stratified analysis where document-year metadata is available
57
+
58
+ ### Out of scope
59
+
60
+ - Handwriting
61
+ - Full-page layout detection or reading order
62
+ - Production or high-stakes deployment
63
+ - Broad Sinhala-English code mixing
64
+ - Claims of parity with page-level commercial or large vision-language systems
65
+
66
+ ## Data
67
+
68
+ ### Training and validation
69
+
70
+ `Ransaka/sinhala_synthetic_ocr-large`
71
+
72
+ - 6,969 synthetic Sinhala image-text pairs
73
+ - One published `train` split
74
+ - Five reported font families
75
+ - Dataset DOI: [10.57967/hf/1809](https://doi.org/10.57967/hf/1809)
76
+ - Repository `LICENSE`: MIT
77
+ - Fixed project split: 90% train and 10% validation using seed 42
78
+
79
+ The exact generated indices and dataset revision must be written to the experiment manifest before training.
80
+
81
+ ### Real-document evaluation
82
+
83
+ `avishadilhara/sinhala-ocr-lk-acts-1010`
84
+
85
+ - 1,010 page images from Sri Lankan legislative acts
86
+ - Published splits: train 707, test 202, evaluation 101
87
+ - License: CC BY 4.0
88
+ - Paper: [arXiv:2606.29378](https://arxiv.org/abs/2606.29378)
89
+
90
+ TrOCR is a line-recognition model. The page dataset must therefore be converted into a documented, deterministic line-level benchmark before direct evaluation. Page-level benchmark figures are contextual references and must not be presented as directly comparable line-level results.
91
+
92
+ ## Pre-registered experiment
93
+
94
+ The hypotheses, fixed splits, seeds, metrics, normalization, hyperparameters, decision rules, and reporting requirements are defined in [`PROTOCOL.md`](PROTOCOL.md). Material deviations must be documented before results are interpreted.
95
+
96
+ ## Planned baselines
97
+
98
+ | System | Role | Primary comparison |
99
+ |---|---|---|
100
+ | `Ransaka/TrOCR-Sinhala` | Starting checkpoint | Measures improvement from additional fine-tuning |
101
+ | Tesseract 5.5 | Permissive classical baseline | CER and WER on the same line images |
102
+ | Surya OCR | Optional research baseline | CER and WER on the same evaluation unit |
103
+
104
+ Published page-level results are contextual targets only:
105
+
106
+ | System | CER | WER | Evaluation unit |
107
+ |---|---:|---:|---|
108
+ | Tesseract v5 | 10.69% | Not reported | Real pages |
109
+ | Surya OCR | 8.84% | 26.64% | Real pages |
110
+ | Google Document AI | 2.06% | Not reported | Real pages |
111
+ | Fine-tuned LightOnOCR-2-1B | 1.05% | 5.63% | Real pages |
112
+
113
+ These figures come from a June 2026 preprint and are not direct line-level acceptance thresholds.
114
+
115
+ ## Planned training configuration
116
+
117
+ | Parameter | Pre-registered value |
118
+ |---|---|
119
+ | Optimizer | AdamW |
120
+ | Learning rate | 4e-5 |
121
+ | Epochs | 10 |
122
+ | Effective batch size | 8 |
123
+ | Precision | FP16 when supported |
124
+ | Seed | 42 |
125
+ | Evaluation beams | 4 |
126
+ | Runs | 3 independent runs |
127
+
128
+ The machine-readable configuration is in [`configs/phase0.yaml`](configs/phase0.yaml).
129
+
130
+ ## Evaluation and reporting
131
+
132
+ CER is the primary metric and WER is secondary. Report:
133
+
134
+ - Results for every seed, plus mean and standard deviation
135
+ - Exact dataset revisions and split-index checksum
136
+ - Raw and normalized metrics
137
+ - 95% paired bootstrap confidence intervals for model differences
138
+ - Error examples grouped by degradation type
139
+ - Results by document period where supported
140
+ - Runtime and hardware details
141
+
142
+ Final results belong in `results/metrics.json` and the table below. Do not add zero-value placeholders to Hugging Face `model-index` metadata because they can be mistaken for real results.
143
+
144
+ | System | Dataset/slice | CER mean ± SD | WER mean ± SD | Status |
145
+ |---|---|---:|---:|---|
146
+ | Starting checkpoint | Real Sinhala line benchmark | TBD | TBD | Not run |
147
+ | Fine-tuned model | Real Sinhala line benchmark | TBD | TBD | Not run |
148
+ | Tesseract 5.5 | Real Sinhala line benchmark | TBD | TBD | Not run |
149
+ | Surya OCR | Real Sinhala line benchmark | TBD | TBD | Optional |
150
+
151
+ ## Intended use
152
+
153
+ The eventual model is intended for research and prototyping involving printed Sinhala text lines, including OCR experiments, document digitization research, and accessibility prototypes. Human review is required for consequential use.
154
+
155
+ ## Limitations
156
+
157
+ - Synthetic training data may not represent real scanning noise, skew, bleed-through, compression, damaged print, or historical typography.
158
+ - Training fonts cover only a limited part of Sinhala typography.
159
+ - Accuracy may degrade on older documents, handwriting, mixed-language text, unusual symbols, curved lines, and full pages.
160
+ - Line segmentation quality can dominate end-to-end page performance.
161
+ - Results from legislative acts may not generalize to receipts, books, forms, signs, or contemporary digital screenshots.
162
+
163
+ ## Bias and responsible use
164
+
165
+ The training domain may overrepresent clean, computer-generated Sinhala and underrepresent historical fonts and real capture conditions. Evaluate new domains before use. Do not use unreviewed OCR output as authoritative evidence in legal, medical, financial, identity, or public-administration decisions.
166
+
167
+ Public legislative documents can contain names. Preserve source attribution, minimize unnecessary retention, and review extracted text before redistribution.
168
+
169
+ ## Planned inference
170
+
171
+ The final release will support the standard Transformers interface:
172
+
173
+ ```python
174
+ from PIL import Image
175
+ from transformers import TrOCRProcessor, VisionEncoderDecoderModel
176
+
177
+ repo_id = "kaan84/sinhala-print-trocr"
178
+ processor = TrOCRProcessor.from_pretrained(repo_id)
179
+ model = VisionEncoderDecoderModel.from_pretrained(repo_id)
180
+
181
+ image = Image.open("sinhala-line.png").convert("RGB")
182
+ pixel_values = processor(images=image, return_tensors="pt").pixel_values
183
+ generated_ids = model.generate(pixel_values, num_beams=4)
184
+ text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
185
+ print(text)
186
+ ```
187
+
188
+ This snippet will work only after weights and processor assets are published.
189
+
190
+ ## Repository structure
191
+
192
+ ```text
193
+ .
194
+ Ò”œÒ”€Ò”€ README.md
195
+ Ò”œÒ”€Ò”€ PROTOCOL.md
196
+ Ò”œÒ”€Ò”€ RISK_REGISTER.md
197
+ Ò”œÒ”€Ò”€ ATTRIBUTION_AND_LICENSING.md
198
+ Ò”œÒ”€Ò”€ REPRODUCIBILITY_CHECKLIST.md
199
+ Ò”œÒ”€Ò”€ requirements.txt
200
+ Ò”œÒ”€Ò”€ configs/
201
+ Γ’β€β€š Ò””Ò”€Ò”€ phase0.yaml
202
+ Ò”œÒ”€Ò”€ scripts/
203
+ Γ’β€β€š Ò””Ò”€Ò”€ README.md
204
+ Ò”œÒ”€Ò”€ assets/
205
+ Γ’β€β€š Ò””Ò”€Ò”€ README.md
206
+ Ò”œÒ”€Ò”€ runs/
207
+ Γ’β€β€š Ò””Ò”€Ò”€ README.md
208
+ Ò””Ò”€Ò”€ results/
209
+ Ò”œÒ”€Ò”€ README.md
210
+ Ò””Ò”€Ò”€ metrics.template.json
211
+ ```
212
+
213
+ ## Release gates
214
+
215
+ 1. Obtain and archive explicit licensing clarification for `Ransaka/TrOCR-Sinhala`.
216
+ 2. Record immutable dataset and model revisions.
217
+ 3. Commit split indices and their checksum.
218
+ 4. Complete three seeded runs.
219
+ 5. Run every baseline on identical evaluation units.
220
+ 6. Populate real metrics and add `model-index` metadata.
221
+ 7. Complete the reproducibility checklist.
222
+ 8. Publish model weights only after the licensing gate passes.
223
+
224
+ ## Citation
225
+
226
+ If this research is published, add its final citation here. Upstream citations and licensing notes are maintained in [`ATTRIBUTION_AND_LICENSING.md`](ATTRIBUTION_AND_LICENSING.md).
227
+
228
+
229
+
REPRODUCIBILITY_CHECKLIST.md ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Reproducibility Checklist
2
+
3
+ Complete every item before public release.
4
+
5
+ ## Claims and scope
6
+
7
+ - [x] Primary research question is stated.
8
+ - [x] Confirmatory hypotheses are stated before training.
9
+ - [x] In-scope and out-of-scope uses are stated.
10
+ - [ ] Final claims match the evaluation unit.
11
+
12
+ ## Data
13
+
14
+ - [ ] Immutable model and dataset revisions recorded.
15
+ - [ ] Train and validation indices committed.
16
+ - [ ] Split-index SHA-256 checksums recorded.
17
+ - [ ] Real line benchmark frozen before prediction review.
18
+ - [ ] Exclusion rules and counts reported.
19
+ - [ ] Dataset licenses and attributions included.
20
+
21
+ ## Training
22
+
23
+ - [x] Seeds and fixed hyperparameters declared.
24
+ - [ ] Hardware and runtime recorded.
25
+ - [ ] Dependency versions recorded.
26
+ - [ ] Checkpoints saved in safetensors format.
27
+ - [ ] TensorBoard logs retained under `runs/`.
28
+ - [ ] Three seeded runs completed.
29
+
30
+ ## Evaluation
31
+
32
+ - [x] CER is the primary metric.
33
+ - [x] WER is secondary.
34
+ - [x] Text normalization is specified.
35
+ - [ ] Raw and normalized results reported.
36
+ - [ ] Paired bootstrap confidence intervals reported.
37
+ - [ ] Baselines run on identical evaluation units.
38
+ - [ ] Period-level sample counts reported.
39
+ - [ ] Error analysis follows the pre-declared taxonomy.
40
+
41
+ ## Publication
42
+
43
+ - [ ] Intermediate checkpoint license clarified.
44
+ - [ ] Model-card metadata updated with the final license.
45
+ - [ ] Real results added to `model-index`.
46
+ - [ ] Inference example tested from a clean environment.
47
+ - [ ] Intended use, limitations, bias, and responsible-use sections reviewed.
48
+ - [ ] DOI generated after the repository becomes stable.
49
+ - [ ] Final citation added.
50
+
RISK_REGISTER.md ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Risk Register
2
+
3
+ Scales: likelihood and impact are Low, Medium, or High. The owner should update status at each project checkpoint.
4
+
5
+ | ID | Risk | Likelihood | Impact | Early indicator | Mitigation | Contingency | Owner | Status |
6
+ |---|---|---|---|---|---|---|---|---|
7
+ | R01 | No declared license for `Ransaka/TrOCR-Sinhala` | High | High | No license tag or file | Request explicit clarification; retain evidence; attribute upstreams | Keep repository research-only and do not publish weights | Researcher | Open |
8
+ | R02 | Synthetic-to-real domain shift | High | High | Validation improves while real CER remains weak | Use real frozen test benchmark; report gap; add pre-declared augmentation only in later exploratory phase | Publish negative result and design Phase 1 domain adaptation | Researcher | Open |
9
+ | R03 | Line segmentation confounds recognition | High | High | Errors cluster around bad crops or merged lines | Version segmentation pipeline; audit a deterministic sample; retain crop coordinates | Report recognition and segmentation failures separately | Researcher | Open |
10
+ | R04 | Older documents perform substantially worse | High | Medium | Period-level CER rises for early years | Report period-stratified metrics; document typography and degradation | Limit intended use and prioritize later historical augmentation | Researcher | Open |
11
+ | R05 | Test-set leakage during benchmark construction | Medium | High | References corrected after predictions are viewed | Freeze benchmark before evaluation; checksum manifests; blind correction workflow | Create a new untouched holdout | Researcher | Open |
12
+ | R06 | Too few independent real test units | Medium | Medium | Wide confidence intervals | Report paired bootstrap intervals and exact sample counts | Add a separately licensed benchmark without merging claims improperly | Researcher | Open |
13
+ | R07 | Colab or GPU interruption | Medium | Medium | Runtime disconnects or out-of-memory errors | Save each epoch; log revisions; use FP16 and gradient accumulation | Resume from last complete checkpoint under protocol rules | Researcher | Open |
14
+ | R08 | Non-deterministic training | Medium | Medium | Large seed-to-seed variance | Fix seeds; record environment; run three seeds | Increase runs in an explicitly amended protocol | Researcher | Open |
15
+ | R09 | Inconsistent text normalization | Medium | High | Metric changes across scripts | Centralize normalization; unit test examples; report raw and normalized scores | Recompute all systems using the corrected fixed pipeline | Researcher | Open |
16
+ | R10 | Baselines evaluated on different units | Medium | High | Page metrics compared with line metrics | Label evaluation unit in every table; run local baselines on identical lines | Treat published page results as context only | Researcher | Open |
17
+ | R11 | Surya terms change or are misinterpreted | Medium | Medium | Conflicting license thresholds | Pin version and archive current terms before use | Omit Surya and retain Tesseract as required baseline | Researcher | Open |
18
+ | R12 | Public documents contain personal names | Low | Medium | Named individuals appear in extracted text | Minimize retained text; preserve provenance; review redistribution | Release aggregate metrics and restricted examples only | Researcher | Open |
19
+ | R13 | Model card overstates readiness | Medium | High | Unqualified benchmark or production claims | Use release gates; distinguish page and line results; maintain limitations | Correct card and issue a new version note | Researcher | Open |
20
+ | R14 | Placeholder metrics mistaken for results | Medium | High | Zero values appear in metadata | Do not add `model-index` until results exist; use `TBD` only in prose | Remove incorrect metadata immediately | Researcher | Controlled |
21
+ | R15 | Dependency or dataset revision drift | Medium | Medium | Re-run changes without code edits | Pin revisions and environment; save lock file or environment export | Reproduce using the archived manifest | Researcher | Open |
22
+
23
+ ## Review cadence
24
+
25
+ Review this register:
26
+
27
+ 1. Before data download
28
+ 2. Before the first training run
29
+ 3. Before final-test evaluation
30
+ 4. Before any public release
31
+
32
+ Close a risk only when evidence is recorded in the repository.
33
+
assets/README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Assets
2
+
3
+ Place only redistributable demonstration images here.
4
+
5
+ For each image, record:
6
+
7
+ - Source
8
+ - Creator
9
+ - License
10
+ - Date accessed
11
+ - Whether the transcription is manually verified
12
+
13
+ Do not upload benchmark images unless their license and redistribution terms permit it.
14
+
configs/phase0.yaml ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ project:
2
+ name: trocr-sinhala-printed-lines
3
+ protocol_version: "1.0"
4
+ protocol_date: "2026-07-28"
5
+
6
+ assets:
7
+ base_model:
8
+ id: Ransaka/TrOCR-Sinhala
9
+ revision: TO_RECORD
10
+ training_dataset:
11
+ id: Ransaka/sinhala_synthetic_ocr-large
12
+ revision: TO_RECORD
13
+ split: train
14
+ evaluation_dataset:
15
+ id: avishadilhara/sinhala-ocr-lk-acts-1010
16
+ revision: TO_RECORD
17
+ split: test
18
+
19
+ data_split:
20
+ seed: 42
21
+ train_fraction: 0.90
22
+ validation_fraction: 0.10
23
+
24
+ training:
25
+ optimizer: adamw
26
+ learning_rate: 0.00004
27
+ epochs: 10
28
+ effective_batch_size: 8
29
+ fp16: true
30
+ seeds: [42, 123, 2026]
31
+ save_strategy: epoch
32
+ selection_metric: normalized_cer
33
+ selection_mode: min
34
+
35
+ generation:
36
+ num_beams: 4
37
+
38
+ normalization:
39
+ unicode_form: NFC
40
+ convert_linebreaks_and_tabs_to_spaces: true
41
+ collapse_whitespace: true
42
+ strip_outer_whitespace: true
43
+ preserve_punctuation: true
44
+ preserve_diacritics: true
45
+
46
+ evaluation:
47
+ primary_metric: cer
48
+ secondary_metric: wer
49
+ report_raw_and_normalized: true
50
+ bootstrap_replicates: 10000
51
+ bootstrap_seed: 42
52
+ confidence_level: 0.95
53
+
54
+ release:
55
+ publish_weights: false
56
+ blocker: Ransaka/TrOCR-Sinhala has no declared license
57
+
requirements.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ accelerate
2
+ datasets
3
+ evaluate
4
+ huggingface_hub
5
+ jiwer
6
+ numpy
7
+ Pillow
8
+ pyyaml
9
+ safetensors
10
+ tensorboard
11
+ torch
12
+ transformers
13
+
results/README.md ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Results
2
+
3
+ Store final, machine-readable results here.
4
+
5
+ - `metrics.json` β€” aggregate and per-seed results
6
+ - `predictions/` β€” sample IDs, references, predictions, and edit counts
7
+ - `bootstrap/` β€” paired comparison intervals
8
+ - `manifests/` β€” revisions, environment, split hashes, and hardware
9
+
10
+ Do not publish sensitive or unnecessarily identifying text. Do not add `metrics.json` until evaluation has actually run.
11
+
results/metrics.template.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "status": "not_run",
3
+ "evaluation_unit": "line",
4
+ "dataset_revision": "TO_RECORD",
5
+ "normalization_version": "protocol-1.0",
6
+ "systems": []
7
+ }
8
+
runs/README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Training Logs
2
+
3
+ Upload TensorBoard event files under seed-specific directories:
4
+
5
+ ```text
6
+ runs/
7
+ β”œβ”€β”€ seed-42/
8
+ β”œβ”€β”€ seed-123/
9
+ └── seed-2026/
10
+ ```
11
+
12
+ Do not overwrite runs. Each run must record the git commit, asset revisions, hardware, start time, end time, and configuration checksum.
13
+
scripts/README.md ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Scripts
2
+
3
+ Add version-controlled programs here during Phase 1:
4
+
5
+ - `make_splits.py` β€” deterministic synthetic train/validation indices
6
+ - `prepare_real_lines.py` β€” page-to-line benchmark construction
7
+ - `train.py` β€” three-seed fine-tuning entry point
8
+ - `evaluate.py` β€” raw and normalized CER/WER
9
+ - `bootstrap.py` β€” paired bootstrap confidence intervals
10
+ - `run_tesseract.py` β€” Tesseract baseline
11
+ - `run_surya.py` β€” optional Surya baseline
12
+ - `validate_release.py` β€” verify required files, revisions, metrics, and license gate
13
+
14
+ Each script must expose `--help`, accept revisions and seeds explicitly, and write a machine-readable manifest.
15
+