coptic-ocr / scripts /textnorm.py
codetomato's picture
Coptic OCR: segmenter, recognizers (E17s1, E10a), char LM, inference code
e9a85fb verified
Raw History Blame Contribute Delete
459 Bytes
"""One text normalization used everywhere (ground truth, synthetic text, predictions).
Every model is scored after the same normalization, so changing this file
changes the benchmark: bump BENCHMARK_VERSION in eval.py if you edit it.
"""
import re
import unicodedata
_WS = re.compile(r"\s+")
def normalize(s: str) -> str:
s = unicodedata.normalize("NFC", s)
s = s.replace(" ", " ").replace("\t", " ")
s = _WS.sub(" ", s).strip()
return s