Skip to content
← Blog

The Invisible OCR Bug: How Byte-Level ByT5 and Empirical Noise Correct Mixed-Script Uzbek Documents

Based on: Post-OCR Correction of Mixed-Script Uzbek Text: Byte-Level ByT5 with an Empirical Homoglyph Noise Matrix — Mannon Ochilov, Oybek Narzullayev, Bahodir Zaripov

Imagine running an exact-match database search for a string in an infrastructure report. The query returns zero results. You pull up the physical scan, inspect the line by eye, and everything looks completely sharp. The text appears to say "ер" or "ВА" in Cyrillic.

To a human reviewer, the characters look correct. To an exact string comparison, they are different text.

Under the hood, an optical character recognition engine such as Tesseract 5.3 may have assigned Latin code points (U+0065 U+0070, spelling "ep") instead of Cyrillic code points (U+0435 U+0440). Because Latin "e" and Cyrillic "е", or Latin "p" and Cyrillic "р", can look identical, the mismatch is easy to miss. The literal equality check ep == ер evaluates to false.

This is the homoglyph problem: characters that look alike across different alphabets while carrying distinct Unicode code points. In a paper posted on November 10, 2026 (arXiv:2611.13609), researchers Mannon Ochilov, Oybek Narzullayev, and Bahodir Zaripov from Tashkent University of Information Technologies and Tashkent State University of Economics tackle this exact defect.

Their investigation focuses on a messy, sensitive operational setting: engineering-geological and ICT infrastructure records in Uzbekistan. By combining a byte-level ByT5 neural architecture, an empirical noise generator calibrated on observed error frequencies, and a strict edit-distance decoding bound, the authors report a 36.2% relative reduction in character error rate on a 5,204-line-pair real-document benchmark. They achieved this entirely on local hardware, with no document data sent to external cloud APIs.

scanned engineering technical report

The Bi-Alphabetic Trap: Why Mixed Scripts Break Exact Match Search

To understand why this problem is so pervasive, one has to look at the script transition described in the paper. Uzbek documentation uses both Cyrillic and Latin, and that transition remains incomplete.

Official and technical documents mix scripts on the same page and sometimes inside individual sentences. The paper's examples include tokens such as "PoE", the host name "LMS.TUIT.UZ", and the technical code "КМК 2.01.03-19". Correcting these documents requires preserving legitimate alphabet choices while repairing accidental ones.

When an OCR engine encounters mixed lines, visually ambiguous letters can be assigned to the wrong alphabet. Page-level script assumptions are not enough to resolve every case. In the authors' measurements, the density of homoglyph errors on mixed-script pages was close to five times higher than on single-script pages.

To ground their research in real scans rather than synthetic assumptions alone, the researchers assembled a Gold evaluation set. After discarding 849 line pairs during a manual review of an initial 6,053 pairs, they retained 5,204 pairs. Within this Gold set, they manually classified 359 distinct homoglyph error events.

The resulting breakdown revealed that homoglyph errors do not follow a uniform pattern:

  • Single substitutions (51.3%, 184 events): A lone character gets swapped for its visual twin in the other alphabet.
  • Cluster substitutions (18.4%, 66 events): Adjacent characters flip together across an alphabet boundary.
  • Multi-position substitutions (21.4%, 77 events): Several positions inside the same token contain substitutions.
  • Whole-word polarisation (8.9%, 32 events): An entire word migrates to the other alphabet.

This final category, whole-word polarisation, was an unexpected discovery for the authors. The token "PoE", for example, appeared in fully Latin, fully Cyrillic ("РоЕ"), and mixed forms. Independent character substitutions do not explicitly model this whole-token pattern: they can create partially switched tokens instead. The authors therefore added a separate mechanism for generating whole-word alphabet changes.

The distinction matters. Training a corrector to expect isolated substitutions alone does not reproduce the full structure of the errors observed in these scans.

Inside the Security Perimeter: Sensitive Reports on a Single GPU

For this project, confidentiality ruled out sending document fragments to commercial cloud APIs. It also prevented publication of the real-document evaluation set.

The underlying documents are restricted engineering-geological reports and ICT records containing site coordinates, contract numbers, and personal data. Three practical constraints governed the project:

  1. Zero document data egress: Sending text fragments to hosted commercial APIs was prohibited. The paper cites training-data recovery and hosted-service attack surfaces among the reasons for this restriction.
  2. Unpublished Gold benchmark: The 5,204-line-pair Gold evaluation set cannot be released. The paper instead points to aggregate statistics and an open noise generator, and cites a repository containing the empirical confusion matrix and evaluation scripts.
  3. A single local workstation: The entire pipeline had to run inside the organization's perimeter, with the neural component fitting on one GPU.

The team carried out training on a workstation equipped with an NVIDIA RTX 5090 GPU with 32 GB of GDDR7 memory. Using BF16 mixed precision, the model consumed approximately 26.4 GB of GPU memory. The paper reports 16 epochs, an early-stopping configuration with patience of three epochs, and 12 hours of wall-clock training time without gradient accumulation.

The authors place particular weight on correction safety because no external auditor re-checks the output. Removing existing OCR errors is only part of the job: a corrector can also damage text that was already right. The researchers therefore tracked newly introduced character errors alongside overall error reduction.

That distinction turns a familiar accuracy problem into a more demanding operational question: how much can the system repair without introducing too many fresh mistakes?

Why Dictionaries, Unicode Rules, and a Local LLM Fell Short

The paper discusses limitations of dictionary-based correction and Unicode security rules, and evaluates a rule-based corrector and a local LLM against ByT5. These are related comparisons, but they are not a comprehensive test of every correction paradigm.

Dictionary-based spell-checking: Traditional post-OCR correction often gathers candidates from a lexicon using edit distance, then ranks them with statistical models. The authors argue that homoglyph substitutions can escape this approach because a script error need not be treated as an out-of-vocabulary word. In their evaluation, the rule-based baseline restored only 7.2% of the annotated homoglyph events.

Standard Unicode security rules: The paper discusses UTS #39 and UTR #36 in connection with confusable characters and mixed-script risk signals. In Uzbek documents, however, using both alphabets can be legitimate. A mixed-script signal alone cannot determine whether a particular alphabet choice is an OCR mistake. The study does not report a separate benchmark of these Unicode standards as correction systems.

A locally deployed Large Language Model: The authors evaluated Qwen2.5-7B from a local checkpoint. They report that technical strings such as "КМК 2.01.03-19" and "LMS.TUIT.UZ" were vulnerable to inappropriate rewriting.

The paper connects this problem to two broader difficulties: sub-word segmentation can change sharply under character corruption, and technical identifiers offer little linguistic redundancy from which to reconstruct the intended text. A plausible-looking rewrite is not necessarily a faithful correction.

On the 5,204-line-pair Gold set, Qwen2.5-7B restored 52.4% of the annotated homoglyph events but introduced 1,132 new character errors. Its overall error reduction was just 7.6%.

The paper also reports an early result of CER 0.1219 and ERP −111%, describing a general-news-trained initial model that corrupted already-correct words. Its discussion is ambiguous about the model behind that early result, so it should not be attributed specifically to the evaluated Qwen2.5-7B baseline. The clear finding is that domain mismatch and over-correction were serious problems in the preliminary work.

The Architecture: Why ByT5 Works at Byte Level

To avoid dependence on sub-word segmentation, the authors selected Google's ByT5 architecture, using the google/byt5-small checkpoint.

Unlike models built around sub-word vocabularies, ByT5 operates directly on raw UTF-8 byte sequences. In UTF-8, a Cyrillic lowercase "е" is represented by two bytes (0xD0 0xB5), whereas a Latin lowercase "e" is represented by a single byte (0x65).

Because ByT5 reads and writes bytes, a homoglyph swap can be represented directly as a change in the byte sequence. An unexpected Cyrillic character in a Latin token does not require the model to find a matching sub-word vocabulary entry.

This removes one source of fragility. It does not make the model immune to incorrect corrections: the study's ByT5 variant without domain adaptation still introduced 286 new errors. Representation, training data, and output constraints all matter.

The team trained ByT5 using AdamW with weight decay 0.01, a learning rate of 3 × 10⁻⁴, linear scheduling, and 5% warm-up. The reported batch size was 64, with a sequence length of 256 bytes. Decoding used beam search with a beam width of four.

The authors considered mT5, mBART-50, and CANINE but did not include them in the comparison experiments. The results therefore support this particular ByT5 pipeline, rather than establishing superiority over those architectures.

Empirical Noise: Teaching the Model How OCR Actually Fails

A neural sequence-to-sequence corrector depends on the examples it learns from. The authors cleaned a raw corpus of 487,205 lines down to 422,815 operational lines, then derived 2,283,198 synthetic training pairs, 63,420 validation pairs, and 63,426 synthetic test pairs. They describe this as roughly five noisy variants per source line.

A central experiment tested how the training-noise distribution affected the result:

Training Noise Distribution         Synthetic Test ERP      Gold Set ERP
------------------------------------------------------------------------
Random visual noise                     -75.1%                 -7.1%
Homoglyph-oriented noise                +24.0%                +15.1%
Empirical matrix + domain adaptation      n/a                 +36.2%

For the first two configurations, the authors report keeping the architecture, corpus, and hyperparameters unchanged while replacing the noise distribution. Random visual noise degraded performance on both evaluations. Homoglyph-oriented noise produced positive error reduction on both.

That is a strong result within this experiment: the noise used to teach correction materially changed whether correction helped. It does not establish that random noise is harmful in every OCR task.

For the empirical generator, the authors used the proportions of the 359 classified Gold events as sampling probabilities. They drew homoglyph candidates from Unicode confusables tables, reweighted them according to observed frequencies, and calibrated the substitution rate to the error density measured on the scans.

To address whole-word polarisation, they introduced a token-level probability $q$. With probability $q$, the generator maps the token to the opposite alphabet; otherwise, it applies character-level substitutions governed by probability $p$. This explicitly represents both isolated changes and whole-token migrations.

The final configuration also changed the training data to a 60% report / 40% news mixture and added conservative decoding. Its +36.2% ERP therefore cannot be credited to the empirical matrix alone. The paper omits synthetic-test metrics for this configuration because the rebuilt training data made the original synthetic test unsuitable for a comparable measurement.

printed infrastructure blueprints and binder

The Levenshtein Circuit Breaker: Conservative Decoding in Practice

Even with byte-level processing and realistic noise, a neural model can over-correct unfamiliar technical strings.

The authors agreed on two acceptance criteria with the document owner at the beginning of the study:

  • Criterion M1: The system must achieve an Error Reduction Percentage of at least +15% on the Gold set.
  • Criterion M2: The system must introduce no more than 100 new character errors across the entire 5,204-line-pair Gold set.

To limit over-correction, they introduced a filter based on Levenshtein distance: the minimum number of single-character insertions, deletions, and substitutions needed to transform one string into another.

After the model produces a candidate correction $\hat{y}$ for a raw input line $\tilde{x}$, the system calculates the edit distance $d(\tilde{x}, \hat{y})$. If the distance exceeds a fixed threshold $\tau$, it rejects the model output and preserves the original OCR line:

$$y_{\text{final}} = \begin{cases} \hat{y}, & \text{if } d(\tilde{x}, \hat{y}) \le \tau \ \tilde{x}, & \text{otherwise} \end{cases}$$

The researchers selected $\tau = 3$ characters on the validation set. This permits candidates within three character edits of the input while rejecting more extensive changes. The bound is measured in characters, even though ByT5 itself operates on bytes.

The paper's examples show "КМК 2.01.03-19" and "LMS.TUIT.UZ" preserved unchanged, with the authors attributing that preservation to the distance filter blocking proposed rewrites.

The circuit-breaker analogy has a limit, however. A wrong change of one, two, or three characters can still pass. The rule constrains the extent of an accepted correction; it cannot guarantee that the correction is right or that a dataset-wide new-error ceiling will always be met. Meeting M2 was an observed result on this Gold set.

What the Numbers Show: Benchmarking the 5,204-Line Gold Set

The final evaluation placed all compared systems on the same 5,204-line-pair Gold set. Performance was tracked using Character Error Rate (CER, substitutions plus deletions plus insertions divided by the number of reference characters) and Error Reduction Percentage (ERP, the relative decrease in CER from raw OCR).

System                        CER       ERP      Homoglyphs Restored   New Errors
---------------------------------------------------------------------------------
Raw OCR (Tesseract 5.3)      0.0578      --               0%                0
Rule-based baseline          0.0575    +0.5%            7.2%               38
LLM (Qwen2.5-7B, local)      0.0534    +7.6%           52.4%            1,132
ByT5 (no domain adaptation)  0.0491   +15.1%           69.8%              286
ByT5 (proposed final)        0.0369   +36.2%           91.3%               84

The proposed system was the only configuration to satisfy both acceptance criteria simultaneously:

  • It reduced CER from 0.0578 to 0.0369, delivering ERP of +36.2%, above the M1 target of +15%.
  • It introduced 84 new character errors across all 5,204 line pairs, below the M2 ceiling of 100.
  • It restored 91.3% of the 359 annotated homoglyph events.

The ByT5 variant without domain adaptation also cleared M1 at +15.1%, but failed M2 with 286 new errors. The rule-based system stayed under the new-error ceiling but achieved little net error reduction.

Compared with Qwen2.5-7B, the proposed system achieved approximately 4.8 times the net error reduction and introduced approximately 13.5 times fewer new errors. These comparisons describe the evaluated configurations on this dataset.

The rule-based system also exposed a striking synthetic-to-real gap: it restored 99.3% of homoglyphs on the synthetic test but only 7.2% on genuine scans. Its ERP dropped from +20.1% to +0.5%. That result illustrates why a strong score under one synthetic noise distribution need not predict performance on real documents.

The authors estimated sampling uncertainty using 1,000 paired bootstrap resamples. The reported 95% confidence interval for ERP was 34.8%–37.6%, above the 15% project threshold. The paired CER-difference interval also excluded zero. These intervals describe variability within the available Gold set; they do not establish performance on other collections.

Condition            Lines (N)    Raw CER    Model CER      ERP
----------------------------------------------------------------
Cyrillic, clean        1,008      0.0608      0.0403      +33.7%
Cyrillic, noisy        1,000      0.0569      0.0365      +35.9%
Latin, clean           1,216      0.0610      0.0438      +28.2%
Latin, noisy           1,199      0.0550      0.0374      +32.0%
Mixed, clean             394      0.0572      0.0311      +45.6%
Mixed, noisy             387      0.0348      0.0206      +40.8%

The breakdown supports the authors' expectation that the largest gains would occur where homoglyph confusion was dense. Error reduction ranged from +28.2% to +35.9% on single-script pages, reaching +45.6% on clean mixed pages and +40.8% on noisy mixed pages.

The mixed-noisy group had the lowest raw CER, at 0.0348, despite high homoglyph density. These measures count different things: CER includes all character errors, while homoglyph density isolates alphabet confusion. The authors explain that mixed pages came mostly from modern, digitally prepared reports scanned at high quality, with relatively few image-related errors.

Why it matters for document engineering and OCR pipelines

This paper offers five practical lessons for designing document-processing pipelines, with the strongest evidence applying to the collection studied:

  1. Model observed failure patterns. Random visual noise harmed performance in the controlled comparison, while homoglyph-oriented noise helped. Classifying real errors gave the authors a basis for representing single substitutions, clusters, multi-position errors, and whole-word polarisation. The result makes a concrete case for checking whether synthetic training noise resembles the errors a corrector will encounter.
  2. Consider byte-level representations for character repair. ByT5 processes UTF-8 directly, avoiding dependence on sub-word segmentation for corrupted tokens. The evaluated pipeline performed well, but byte-level processing alone did not prevent over-correction, and the study did not benchmark all alternative architectures.
  3. Bound proposed corrections with distance checks. The three-character Levenshtein limit rejected extensive rewrites and contributed to the final system's conservative behavior. It is a useful constraint, not an infallible safeguard: short incorrect edits remain possible, and longer legitimate repairs may be rejected.
  4. Treat newly introduced errors as an acceptance metric. Net error reduction can conceal damage to previously correct text. The explicit ceiling of 100 new errors distinguished the final configuration from Qwen2.5-7B and the ByT5 variant without domain adaptation, both of which reduced CER while introducing too many errors for this project's requirements.
  5. Local training can be practical for a bounded correction task. The authors report training in 12 hours on one RTX 5090 workstation, with no document data egress. This demonstrates feasibility under their hardware and workload constraints. It does not establish inference throughput, total operating cost, or a general guarantee of confidentiality.

Boundaries and Open Questions

The study has clear operational boundaries, along with an evaluation-design ambiguity that matters when interpreting the results:

  • Domain-specific noise calibration: The matrix was derived from engineering-geological and ICT reports from one organization. Transfer to administrative, legal, or literary texts requires separate validation; whether the matrix needs recalibration would have to be tested.
  • Confounded ablation factors: The progression from +15.1% to +36.2% ERP combined the empirical matrix, domain-adapted training data with a 60% report / 40% news ratio, and conservative decoding. The authors propose a 2 × 2 ablation over noise type and domain adaptation. That would address those two factors; isolating decoding's contribution would require controlling or separately varying it.
  • Gold-set involvement in development: The paper describes the Gold set as reserved for final measurement and unused for training or hyperparameter selection. Yet it also derives the generator's sampling weights from that set's 359 annotated events and reports Gold evaluation every second epoch. These details leave the claimed separation between development and final evaluation unclear.
  • Small sample slices: Some groups, including the mixed-noisy cohort of 387 line pairs, are relatively small. The authors caution against placing too much weight on their exact performance ordering.
  • Closed evaluation data: Confidentiality prevents release of the Gold set. The cited noise generator, confusion matrix, and evaluation scripts support partial reproducibility, but independent teams cannot directly audit the unreleased scans and reference pairs.

Despite these limitations, the paper offers a pragmatic example of targeted post-OCR correction. On this collection, byte-level modeling, empirically informed noise, domain adaptation, and conservative decoding together reduced character error rate by over a third while introducing 84 new character errors. The next test is whether that balance holds on independently evaluated document streams, with the contribution of each component more clearly separated.