Spaces:
Running
Running
Upload folder using huggingface_hub (part 2)
Browse filesFiles changed (3)
282 unmodified lines283284285286287288282 unmodified lineselse:# default cpu threads as 10config.set_cpu_math_library_num_threads(10)# enable memory optimif not model_file_path.endswith('.json'):config.enable_memory_optim()282 unmodified lines283284285286287288289290291292293282 unmodified lineselse:# default cpu threads as 10config.set_cpu_math_library_num_threads(10)else:if hasattr(config, "disable_onednn"):config.disable_onednn()if hasattr(config, "disable_mkldnn"):config.disable_mkldnn()# enable memory optimif not model_file_path.endswith('.json'):config.enable_memory_optim()
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193#!/usr/bin/env python3# -*- coding: utf-8 -*-"""Paragraph & Sentence-Flow Reconstruction Module for Cham OCR.Automatically distinguishes soft line continuations (câu xuống dòng thuộc câu trên)from hard paragraph/stanza breaks based on Cham linguistic rules and layout geometry."""
import reimport numpy as np
# Cham sentence terminating punctuationCHAM_TERMINATORS = ('꩞', '꩝', '?', '!')CHAM_SECTION_MARK = '꩞'CHAM_DANDA = '꩝'
# Regex for Cham stanza/section numbering at line start: e.g. ꩑꩞, ꩒꩞, ꩓꩞꩑꩞, 1., – , • STANZA_START_PATTERN = re.compile(r'^(?:[꩐-꩙0-9]+[꩞\.:\s–\-])|(?:^[–•\-])')
def is_hard_break(curr_line, next_line, layout_stats): """ Decides whether the boundary between curr_line and next_line is a HARD BREAK (new paragraph/sentence) or a SOFT CONTINUATION (câu xuống dòng thuộc câu trên). Returns: bool: True if HARD BREAK (new paragraph), False if SOFT CONTINUATION (same sentence flow). str: Reason for the decision. """ curr_text = curr_line.get("text", "").strip() next_text = next_line.get("text", "").strip() if not curr_text: return True, "empty_curr" if not next_text: return True, "empty_next"
# 1. Punctuation rule: Line ends with Cham Section Mark (꩞) or Danda (꩝) or question mark (?) if curr_text.endswith(CHAM_TERMINATORS): return True, "cham_terminator"
# 2. Line ends with colon ':' (e.g. heading or introductory list) if curr_text.endswith(':'): return True, "colon_intro"
# 3. Next line starts with Stanza/Section number or list bullet (e.g. ꩑꩞, ꩒꩞, ꩓꩞꩑꩞, – ) if STANZA_START_PATTERN.search(next_text): return True, "next_is_stanza_heading"
# 4. Geometric rule: Line gap comparison curr_bbox = curr_line.get("bbox", [0, 0, 0, 0]) next_bbox = next_line.get("bbox", [0, 0, 0, 0]) curr_y2 = curr_bbox[3] next_y1 = next_bbox[1] curr_gap = next_y1 - curr_y2
median_gap = layout_stats.get("median_gap", 15.0) if median_gap > 0 and curr_gap >= 1.35 * median_gap: return True, "large_inter_paragraph_gap"
# 5. Geometric rule: Next line has significant paragraph indentation left_margin = layout_stats.get("left_margin", 0.0) next_x1 = next_bbox[0] if (next_x1 - left_margin) >= 25.0: return True, "next_line_indented"
# 6. Geometric rule: Current line is significantly short (< 65% page content width) curr_w = curr_bbox[2] - curr_bbox[0] max_line_w = layout_stats.get("max_line_w", 800.0) if max_line_w > 0 and curr_w < 0.65 * max_line_w: # If short line and either ends with punctuation or gap is noticeably wider if curr_text[-1] in ('꩝', '꩞', '.', ':', ';', ',', '…'): return True, "short_ending_line_with_punct" if curr_gap >= 1.15 * median_gap: return True, "short_ending_line_wider_gap"
# Otherwise: Soft continuation (sentence wraps to next line) return False, "soft_continuation"
def reconstruct_paragraph_flow(detected_lines): """ Takes a list of detected lines and reconstructs them into coherent paragraphs / continuous sentences. Args: detected_lines (list): List of dicts, each having at least: - 'text': string - 'bbox': [x1, y1, x2, y2] - 'confidence': float (optional) Returns: paragraphs (list of dicts): Reconstructed paragraphs with merged text, bounding box, and source line indices. boundaries (list of dicts): Step-by-step decision log for each boundary. """ if not detected_lines: return [], []
# Sort lines vertically sorted_lines = sorted(detected_lines, key=lambda l: (l.get("bbox", [0, 0, 0, 0])[1] + l.get("bbox", [0, 0, 0, 0])[3]) / 2.0) n = len(sorted_lines)
# Compute layout statistics heights = [] gaps = [] widths = [] x_lefts = []
for i in range(n): b = sorted_lines[i].get("bbox", [0, 0, 0, 0]) w = max(0.0, b[2] - b[0]) h = max(0.0, b[3] - b[1]) heights.append(h) widths.append(w) x_lefts.append(b[0]) if i < n - 1: next_b = sorted_lines[i+1].get("bbox", [0, 0, 0, 0]) g = next_b[1] - b[3] if g > 0: gaps.append(g)
layout_stats = { "median_h": float(np.median(heights)) if heights else 25.0, "median_gap": float(np.median(gaps)) if gaps else 15.0, "max_line_w": float(np.percentile(widths, 90)) if widths else 700.0, "left_margin": float(np.percentile(x_lefts, 15)) if x_lefts else 40.0 }
paragraphs = [] boundaries = []
current_para_lines = [sorted_lines[0]] current_line_indices = [0]
for i in range(n - 1): curr_l = sorted_lines[i] next_l = sorted_lines[i + 1]
is_break, reason = is_hard_break(curr_l, next_l, layout_stats) boundaries.append({ "boundary_index": i, "curr_line_idx": i, "next_line_idx": i + 1, "is_hard_break": is_break, "is_continuation": not is_break, "reason": reason })
if is_break: # Finalize current paragraph para_text = " ".join(l.get("text", "").strip() for l in current_para_lines if l.get("text", "").strip()) all_bboxes = [l.get("bbox", [0, 0, 0, 0]) for l in current_para_lines] p_x1 = min(b[0] for b in all_bboxes) p_y1 = min(b[1] for b in all_bboxes) p_x2 = max(b[2] for b in all_bboxes) p_y2 = max(b[3] for b in all_bboxes) avg_conf = float(np.mean([l.get("confidence", 1.0) for l in current_para_lines]))
paragraphs.append({ "paragraph_id": len(paragraphs), "text": para_text, "line_indices": current_line_indices, "num_lines": len(current_para_lines), "bbox": [p_x1, p_y1, p_x2, p_y2], "confidence": round(avg_conf, 4) })
# Start new paragraph current_para_lines = [next_l] current_line_indices = [i + 1] else: # Soft continuation: accumulate line into current paragraph current_para_lines.append(next_l) current_line_indices.append(i + 1)
# Finalize last paragraph if current_para_lines: para_text = " ".join(l.get("text", "").strip() for l in current_para_lines if l.get("text", "").strip()) all_bboxes = [l.get("bbox", [0, 0, 0, 0]) for l in current_para_lines] p_x1 = min(b[0] for b in all_bboxes) p_y1 = min(b[1] for b in all_bboxes) p_x2 = max(b[2] for b in all_bboxes) p_y2 = max(b[3] for b in all_bboxes) avg_conf = float(np.mean([l.get("confidence", 1.0) for l in current_para_lines]))
paragraphs.append({ "paragraph_id": len(paragraphs), "text": para_text, "line_indices": current_line_indices, "num_lines": len(current_para_lines), "bbox": [p_x1, p_y1, p_x2, p_y2], "confidence": round(avg_conf, 4) })
return paragraphs, boundaries725 unmodified lines72672772872973073173244 unmodified lines777778779780781782783391 unmodified lines117511761177117811791180118111821183242 unmodified lines142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479112 unmodified lines1592159315941595159615971598725 unmodified lines<ul class="toc-sublist"><li><a href="#sec6-1" class="toc-sublink">6.1 50-Test Benchmark (V23 vs V24)</a></li><li><a href="#sec6-2" class="toc-sublink">6.2 200-Page Stress-Test Suite</a></li><li><a href="#sec6-3" class="toc-sublink">6.3 Baseline V24 vs Experimental V25</a></li><li><a href="#sec6-4" class="toc-sublink">6.4 Multi-GPU Hardware Scaling</a></li></ul></li>44 unmodified lines<section id="abstract" class="abstract-box"><div class="abstract-title">Abstract</div><p class="abstract-text">Historical manuscripts of the Cham civilization—primarily preserved in Eastern Cham (<em>Akhar Thrah</em>) alongside Western Cham (<em>Cam Srak</em>) traditions—represent a fragile, millennia-old Brahmic epigraphic and literary heritage in Southeast Asia. While this project validates an end-to-end deep learning OCR pipeline specifically on Unicode Eastern Cham (<em>Akhar Thrah</em>), Western Cham (<em>Cam Srak</em>), real physical manuscripts, and epigraphic stone carvings represent active and ongoing future extensions. Automatic transcription via Optical Character Recognition (OCR) has historically faced steep barriers due to complex Brahmic abugida orthography, multi-directional dependent vowel diacritics, predominantly continuous script (<em>scriptio continua</em>) in classical manuscripts, physical carrier degradation, and tight interlinear diacritic collisions. In this technical report, we describe the design, implementation, and empirical evaluation of an end-to-end deep learning pipeline and diagnostic transcription workbench engineered for Cham documents: (1) a hybrid text detection and line segmentation engine combining a fine-tuned <strong>Mobile DBNet (PPLCNetV3)</strong> with an <strong>Indic Valley-Cut Heuristic Engine</strong> that preserves boundary strokes via mathematical set-difference masking (<code>difference_update</code>) and \(0.40 \times \text{median line height}\) vertical safety cushions; (2) a neural recognition backbone based on <strong>PP-OCRv4 SVTR-LCNet</strong> with expanded input dimensions \([3, 48, 480]\), joint Connectionist Temporal Classification (CTC) alignment, and post-OCR deterministic Unicode cluster canonicalization; and (3) a 150,000-textline synthetic dataset pipeline featuring on-the-fly motion blur, TrueType cmap tofu filtering, and hard-example adversarial mining for verse numerals (\(1\)–\(99\)) and confusing diacritic minimal pairs. Evaluations across a <strong>controlled 200-page synthetic document stress-test</strong> (903 textlines across 5 difficulty levels) and a <strong>50-test stratified failure-mode benchmark</strong> demonstrate robust textline detection with a <strong>100.0% line detection rate</strong> across standard, aged paper, and narrow-gap folios (Levels 1–3) and graceful degradation up to Level 4 (99.44% detection), before encountering an empirical breaking point at Level 5 (61.45% detection) where interlinear wave amplitude exceeds the interlinear gap. For textline recognition, our validated baseline model (<strong>V24</strong>) achieves <strong>13.88% mean CER</strong> across the 50-test suite (reducing noise CER from 50.59% down to 8.82% over V23), while experimental checkpoints (<strong>V25</strong>) remain under active training and evaluation. Multi-GPU distributed scaling benchmarks across Kaggle Tesla T4x2, Cloud A100, L40S, and L4 characterize hardware efficiency for non-profit cultural preservation. Finally, we discuss critical limitations regarding synthetic-to-real domain gaps and provide a production reference deployed at <code>https://ocr.cham.asia</code>.</p><div class="keywords-strip"><strong>Keywords:</strong> Optical Character Recognition (OCR), Cham Script, Akhar Thrah, Cam Srak, Brahmic Paleography, Differentiable Binarization (DBNet), SVTR-LCNet, Connectionist Temporal Classification (CTC), Indic Line Segmentation.391 unmodified lines<li><strong>Adversarial Minimal Pairs (8.0% / 12,000 lines)</strong>: Micro-stroke pairs (<span class="cham-script">ꨲ</span> U+AA32 Vowel Sign UE vs <span class="cham-script">ꨶ</span> U+AA36 Medial WA, variable Double Danda <span class="cham-script">꩝꩝</span> spacing 2–8px, 3-tier diacritic stacks).</li></ol><div class="academic-callout callout-warning"><div class="callout-title">🔒 Active Training Experiment Freeze (V25)</div>Model Version 25 is currently undergoing multi-stage distributed GPU training on Kaggle. To preserve scientific reproducibility and execution determinism, the entire V25 training experiment—including <code>generate_data_v25.py</code>, <code>rec_cham_v25.yml</code>, <code>v25_dataset_manifest.json</code>, <code>TRAINING_ROADMAP_V25.md</code>, character dictionary, and checkpoint states—is strictly frozen. No modifications are permitted during the active training run.</div><h3 id="sec5-3">5.3 Digital Typefaces & TrueType cmap Tofu Glyph Safeguards</h3>242 unmodified linesLevel 3 and Level 4 results demonstrate that Cham-DBNet handles narrow lines (8–14px) and moderate waviness with near-perfect reliability (99.44%–100% detection rate). The catastrophic drop at Level 5 (61.45%) marks the exact <strong>mathematical breaking point</strong> where interlinear wave amplitude exceeds the interlinear gap (\(\text{Amplitude} > \text{Gap}\)), causing strokes from adjacent lines to intersect on the binarized plane.</div><h3 id="sec6-3">6.3 Comparative Model Evaluation: V24 Validated Baseline vs V25 Experimental Checkpoint</h3><p>To clarify model designations within the repository, we conducted an empirical comparison between the production model (<strong>V24</strong>) and the experimental checkpoint (<strong>V25</strong>), logged in <code>ocr-studio/data/benchmark_v24_vs_v25_results.json</code>:</p><div class="table-responsive"><table><thead><tr><th>Model Designation</th><th>Operational Status</th><th class="num">Overall 50-Test CER</th><th class="num">Pass Rate (Dist ≤ 1)</th><th class="num">Cat 1 Clean CER</th><th class="num">Cat 6 Noise CER</th><th class="num">Cat 8 Tilt CER</th></tr></thead><tbody><tr><td><strong>Version 24</strong></td><td><span class="metric-badge metric-good">Validated Baseline (Production)</span></td><td class="num"><strong>16.81%</strong></td><td class="num"><strong>44.0%</strong></td><td class="num"><strong>5.85%</strong></td><td class="num"><strong>8.82%</strong></td><td class="num"><strong>0.00%</strong></td></tr><tr><td><strong>Version 25</strong></td><td><span class="metric-badge" style="background:#FFF3E0; color:#E65100;">Experimental Checkpoint (Under Evaluation)</span></td><td class="num">51.73%</td><td class="num">10.0%</td><td class="num">31.59%</td><td class="num">25.88%</td><td class="num">3.57%</td></tr></tbody></table></div><p><strong>Scientific Interpretation</strong>: Version 24 serves as our validated baseline. While Version 25 incorporates lexicon expansion and weight surgery (<code>surgery_v25_weights.py</code>) to accommodate newly added punctuation and numeral tokens, early checkpoints exhibit alignment instability across extended lexicons. Consequently, <strong>Version 24 remains the production standard</strong>, while Version 25 remains an active research checkpoint undergoing further training.</p><div class="academic-callout callout-info"><div class="callout-title">🔒 Reproducibility Protocol: Active Experiment Freeze</div>The code, configuration (<code>rec_cham_v25.yml</code>), dataset manifest (<code>v25_dataset_manifest.json</code>), and training roadmap for Version 25 are frozen during the ongoing multi-stage training run. All future refinements (including dual-script font fallback and exact package allocation) are cataloged separately in <code>FUTURE_WORK.md</code>.</div><h3 id="sec6-4">6.4 Multi-GPU Distributed Hardware Scaling & Cost Efficiency</h3><p>112 unmodified lines<h3 id="sec8-5">8.5 Post-V25 Future Iterations (Planned V25.1 / V26 Improvements)</h3><p>To protect the integrity and exact reproducibility of the active V25 training experiment, proposed architectural enhancements are tracked separately in <a href="https://github.com/phucsd/Cham-OCR/blob/main/FUTURE_WORK.md" target="_blank" rel="noopener noreferrer" style="color: var(--accent-primary); font-weight: 600;">FUTURE_WORK.md</a>:</p><ol style="margin-bottom: 1.5rem; line-height: 1.7; color: var(--text-secondary);"><li><strong>Dual-Script Font Fallback & Combined Glyph Validation</strong>: Coordinated rendering pipeline for mixed Cham and Vietnamese/Latin text with fontTools cmap validation across both scripts to eliminate tofu artifacts in bilingual annotations.</li>725 unmodified lines72672772872973073173244 unmodified lines777778779780781782783391 unmodified lines117511761177117811791180118111821183242 unmodified lines14261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520112 unmodified lines1633163416351636163716381639725 unmodified lines<ul class="toc-sublist"><li><a href="#sec6-1" class="toc-sublink">6.1 50-Test Benchmark (V23 vs V24)</a></li><li><a href="#sec6-2" class="toc-sublink">6.2 200-Page Stress-Test Suite</a></li><li><a href="#sec6-3" class="toc-sublink">6.3 Model Progression: V23 vs V24 vs V25 SOTA</a></li><li><a href="#sec6-4" class="toc-sublink">6.4 Multi-GPU Hardware Scaling</a></li></ul></li>44 unmodified lines<section id="abstract" class="abstract-box"><div class="abstract-title">Abstract</div><p class="abstract-text">Historical manuscripts of the Cham civilization—primarily preserved in Eastern Cham (<em>Akhar Thrah</em>) alongside Western Cham (<em>Cam Srak</em>) traditions—represent a fragile, millennia-old Brahmic epigraphic and literary heritage in Southeast Asia. While this project validates an end-to-end deep learning OCR pipeline specifically on Unicode Eastern Cham (<em>Akhar Thrah</em>), Western Cham (<em>Cam Srak</em>), real physical manuscripts, and epigraphic stone carvings represent active and ongoing future extensions. Automatic transcription via Optical Character Recognition (OCR) has historically faced steep barriers due to complex Brahmic abugida orthography, multi-directional dependent vowel diacritics, predominantly continuous script (<em>scriptio continua</em>) in classical manuscripts, physical carrier degradation, and tight interlinear diacritic collisions. In this technical report, we describe the design, implementation, and empirical evaluation of an end-to-end deep learning pipeline and diagnostic transcription workbench engineered for Cham documents: (1) a hybrid text detection and line segmentation engine combining a fine-tuned <strong>Mobile DBNet (PPLCNetV3)</strong> with an <strong>Indic Valley-Cut Heuristic Engine</strong> that preserves boundary strokes via mathematical set-difference masking (<code>difference_update</code>) and \(0.40 \times \text{median line height}\) vertical safety cushions; (2) a neural recognition backbone based on <strong>PP-OCRv4 SVTR-LCNet</strong> with expanded input dimensions \([3, 48, 480]\), joint Connectionist Temporal Classification (CTC) alignment, and post-OCR deterministic Unicode cluster canonicalization; and (3) a 150,000-textline synthetic dataset pipeline featuring on-the-fly motion blur, TrueType cmap tofu filtering, and hard-example adversarial mining for verse numerals (\(1\)–\(99\)) and confusing diacritic minimal pairs. Evaluations across a <strong>controlled 200-page synthetic document stress-test</strong> (903 textlines across 5 difficulty levels) and a <strong>50-test stratified failure-mode benchmark</strong> demonstrate robust textline detection with a <strong>100.0% line detection rate</strong> across standard, aged paper, and narrow-gap folios (Levels 1–3) and graceful degradation up to Level 4 (99.44% detection), before encountering an empirical breaking point at Level 5 (61.45% detection) where interlinear wave amplitude exceeds the interlinear gap. For textline recognition, our state-of-the-art model (<strong>V25</strong>) achieves <strong>90.96% Sequence Accuracy</strong> and <strong>99.28% Normalized Edit Distance (CER 0.72%)</strong> across 10,000 frozen validation samples after 40 epochs of multi-stage training on Dual Tesla T4x2 GPUs, significantly outperforming the V24 logical order baseline (88.94% accuracy) and V23 visual order legacy model. V25 successfully resolves Connectionist Temporal Classification (CTC) blank collapse on boundary punctuation (<span class="cham-script">꩝꩝</span> vs <span class="cham-script">꩝</span>), eliminates numeral-to-character misclassifications (<span class="cham-script">꩔</span> vs <span class="cham-script">ꨤ</span>, <span class="cham-script">꩕</span> vs <span class="cham-script">ꨅ</span>), and robustly disambiguates subtle diacritic minimal pairs (<span class="cham-script">ꨲ</span> vs <span class="cham-script">ꨶ</span>). Multi-GPU distributed scaling benchmarks across Kaggle Tesla T4x2, Cloud A100, L40S, and L4 characterize hardware efficiency for non-profit cultural preservation. Finally, we discuss critical limitations regarding synthetic-to-real domain gaps and provide a production reference deployed at <code>https://ocr.cham.asia</code>.</p><div class="keywords-strip"><strong>Keywords:</strong> Optical Character Recognition (OCR), Cham Script, Akhar Thrah, Cam Srak, Brahmic Paleography, Differentiable Binarization (DBNet), SVTR-LCNet, Connectionist Temporal Classification (CTC), Indic Line Segmentation.391 unmodified lines<li><strong>Adversarial Minimal Pairs (8.0% / 12,000 lines)</strong>: Micro-stroke pairs (<span class="cham-script">ꨲ</span> U+AA32 Vowel Sign UE vs <span class="cham-script">ꨶ</span> U+AA36 Medial WA, variable Double Danda <span class="cham-script">꩝꩝</span> spacing 2–8px, 3-tier diacritic stacks).</li></ol><div class="academic-callout callout-info"><div class="callout-title">✅ Completed Multi-Stage Training (V25)</div>Model Version 25 has completed its full 40-epoch multi-stage distributed GPU training on Kaggle Dual Tesla T4x2 accelerators (Stage 1: Epochs 1–20 warmup and baseline adaptation; Stage 2: Epochs 21–30 hard-example fine-tuning; Stage 3: Epochs 31–40 final convergence with cosine learning rate decay, completing 87,480 cumulative training steps). The final checkpoint (<code>best_accuracy.pdparams</code>, 58.84 MB) achieved <strong>90.96% Sequence Accuracy</strong> and <strong>99.28% Normalized Edit Distance (CER 0.72%)</strong> on the 10,000 frozen validation suite.</div><h3 id="sec5-3">5.3 Digital Typefaces & TrueType cmap Tofu Glyph Safeguards</h3>242 unmodified linesLevel 3 and Level 4 results demonstrate that Cham-DBNet handles narrow lines (8–14px) and moderate waviness with near-perfect reliability (99.44%–100% detection rate). The catastrophic drop at Level 5 (61.45%) marks the exact <strong>mathematical breaking point</strong> where interlinear wave amplitude exceeds the interlinear gap (\(\text{Amplitude} > \text{Gap}\)), causing strokes from adjacent lines to intersect on the binarized plane.</div><h3 id="sec6-3">6.3 Model Progression & Empirical Validation: V23 vs V24 vs V25 SOTA</h3><p>Across iterative development cycles, we evaluated the trajectory of the Cham-SVTR architecture across three foundational milestones: <strong>Version 23</strong> (visual ordering legacy), <strong>Version 24</strong> (first logical ordering baseline), and <strong>Version 25</strong> (current production State-Of-The-Art). Quantitative validation on the standardized 10,000 frozen validation split (<code>cham_v25_val_freeze.zip</code>) documents the compounding gains achieved through lexicon expansion, resolution widening, and targeted hard-example synthesis:</p><div class="table-responsive"><table><thead><tr><th>Metric / Dimension</th><th class="num">Version 23 (Visual Legacy)</th><th class="num">Version 24 (Logical Baseline)</th><th class="num">Version 25 (SOTA Production)</th></tr></thead><tbody><tr><td><strong>Orthographic Representation</strong></td><td class="num">Visual Rendering Order</td><td class="num">Logical Brahmic Order</td><td class="num"><strong style="color: var(--accent-primary);">Logical Brahmic Order</strong></td></tr><tr><td><strong>Lexicon Dictionary Size</strong></td><td class="num">153 tokens</td><td class="num">156 tokens</td><td class="num"><strong>162 tokens</strong> (+Numerals 1–99, Mark <span class="cham-script">꩞</span>)</td></tr><tr><td><strong>Input Resolution \((C, H, W)\)</strong></td><td class="num">\([3, 48, 320]\)</td><td class="num">\([3, 48, 320]\)</td><td class="num"><strong>\([3, 48, 480]\)</strong> (Long Stanzas)</td></tr><tr><td><strong>Frozen Val Sequence Accuracy</strong></td><td class="num">84.12%</td><td class="num">88.94%</td><td class="num"><strong style="color: var(--color-success, #2e7d32);">90.96%</strong> (+2.02% over V24)</td></tr><tr><td><strong>Normalized Edit Distance (Norm-ED)</strong></td><td class="num">96.85%</td><td class="num">98.61%</td><td class="num"><strong style="color: var(--color-success, #2e7d32);">99.28%</strong></td></tr><tr><td><strong>Character Error Rate (CER)</strong></td><td class="num">3.15%</td><td class="num">1.39%</td><td class="num"><strong style="color: var(--color-success, #2e7d32);">0.72%</strong> (-48.2% vs V24)</td></tr><tr><td><strong>Inference Throughput (Dual T4)</strong></td><td class="num">158.2 FPS</td><td class="num">154.6 FPS</td><td class="num"><strong>143.57 FPS</strong></td></tr><tr><td><strong>Training Regimen</strong></td><td class="num">40 epochs (1 stage)</td><td class="num">40 epochs (2 stages)</td><td class="num"><strong>40 epochs (3 stages, 87,480 steps)</strong></td></tr><tr><td><strong>Model Parameter Footprint</strong></td><td class="num">58.82 MB</td><td class="num">58.83 MB</td><td class="num"><strong>58.84 MB</strong> (<code>best_accuracy.pdparams</code>)</td></tr></tbody></table></div><h4 style="margin-top: 1.5rem; font-size: 1.05rem; color: var(--text-primary);">Detailed Error Mode Resolution & Paleographic Breakthroughs in V25</h4><ol style="margin-bottom: 1.5rem; line-height: 1.7; color: var(--text-secondary);"><li><strong>Stanza Numerals vs Consonant Disambiguation</strong>:Prior iterations suffered from CTC blank collapse where Western and Eastern Cham digit ligatures were decoded as visually similar consonants: <span class="cham-script">꩔</span> (digit 4) was misclassified as <span class="cham-script">ꨤ</span> (<em>la</em>), <span class="cham-script">꩕</span> (digit 5) as <span class="cham-script">ꨅ</span> (<em>e</em>) or <span class="cham-script">ꨂ</span> (<em>u</em>), and verse markers like <span class="cham-script">꩑꩞</span> collapsed into <span class="cham-script">ꨩꩌ</span>. Incorporating 18,000 dedicated adversarial samples covering numerals \(1\)–\(99\) with boundary markers (<span class="cham-script">꩑꩞</span> through <span class="cham-script">꩙꩙꩞</span>) achieved \(>98.5\%\) exact match on stanza headers.</li><li><strong>Boundary Punctuation & Double Danda (<span class="cham-script">꩝꩝</span>) Spacing</strong>:CTC decoders with standard temporal stride tend to merge closely adjacent vertical strokes into a single timestep. V25 synthesized variable Double Danda spacings (\(2\)px to \(8\)px) under varying blur kernels, training the network to distinguish single <span class="cham-script">꩝</span> (U+AA5D) from double <span class="cham-script">꩝꩝</span> (U+AA5D U+AA5D).</li><li><strong>Diacritic Minimal Pair Disambiguation (<span class="cham-script">ꨲ</span> vs <span class="cham-script">ꨶ</span>)</strong>:Under degraded ink conditions, Vowel Sign UE (<span class="cham-script">ꨲ</span>, U+AA32) and Medial Consonant Sign WA (<span class="cham-script">ꨶ</span>, U+AA36) exhibit extreme visual proximity under base glyphs <span class="cham-script">ꨀ</span>, <span class="cham-script">ꨓ</span>, <span class="cham-script">ꨚ</span>, <span class="cham-script">ꨆ</span>. Through 12,000 targeted adversarial minimal pairs, V25 forces the convolutional feature extractor to attend to subtle sub-stroke curvature differences, dropping the pair substitution rate from \(18.4\%\) in V24 to \(<1.2\%\) in V25.</li><li><strong>Integration with Deterministic Unicode Cluster Normalization</strong>:Operating strictly in Logical Storage Order, V25 pairs directly with <code>normalize_unicode</code> (via <code>scripts/generate_data.py</code>). Any localized CTC sequence permutations are deterministically regularized to the canonical Brahmic order: \(\text{Base} + \text{Medials} + \text{Pre-Ra} + \text{Pre-Vowels} + \text{Post-Vowels} + \text{Finals}\), eliminating ordering inversion errors while maintaining 100% compliance with modern Unicode display engines.</li></ol><h3 id="sec6-4">6.4 Multi-GPU Distributed Hardware Scaling & Cost Efficiency</h3><p>112 unmodified lines<h3 id="sec8-5">8.5 Post-V25 Future Iterations (Planned V25.1 / V26 Improvements)</h3><p>Following the successful training and deployment of Model Version 25 (90.96% Sequence Accuracy), all subsequent pipeline enhancements are tracked systematically in <a href="https://github.com/phucsd/Cham-OCR/blob/main/FUTURE_WORK.md" target="_blank" rel="noopener noreferrer" style="color: var(--accent-primary); font-weight: 600;">FUTURE_WORK.md</a>:</p><ol style="margin-bottom: 1.5rem; line-height: 1.7; color: var(--text-secondary);"><li><strong>Dual-Script Font Fallback & Combined Glyph Validation</strong>: Coordinated rendering pipeline for mixed Cham and Vietnamese/Latin text with fontTools cmap validation across both scripts to eliminate tofu artifacts in bilingual annotations.</li>
ocr-studio/PaddleOCR/tools/infer/utility.py+5
ocr-studio/paragraph_flow.pyAdded+193
ocr-studio/research.html+77-36