Datasets:
Tasks:
Automatic Speech Recognition
Modalities:
Text
Formats:
json
Languages:
Kamba (Kenya)
Size:
< 1K
License:
File size: 2,182 Bytes
6a25a9d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | """
normalize.py — Kamba text normalization for KambaBench-ASR.
Versioned deliberately: bump __version__ and log the change in NORMALIZATION_CHANGELOG
whenever behavior changes, so a benchmark result is always reproducible against a specific
normalization version rather than silently drifting.
STATUS (v0.1): only safe, language-agnostic normalization is implemented — NFKC, code-switch /
disfluency tag stripping, punctuation stripping, whitespace collapse, lowercasing. No
Kamba-specific orthographic collapsing (e.g. documenting and merging accepted spelling variants)
has been added yet. Per the benchmark's orthography principle, that layer will only be added
after examining real transcripts from the candidate corpora and consulting native Kamba
speakers — see docs/ORTHOGRAPHY.md.
"""
import re
import unicodedata
__version__ = "0.1"
NORMALIZATION_CHANGELOG = {
"0.1": (
"Initial version. NFKC normalization; strip [cs]/[cs:en]/[cs:sw]-style code-switch "
"markers while keeping the inner words; strip [pause]/[sigh]/[laugh]/[breath]/[noise]/"
"[silence]-style disfluency tags; strip standard punctuation; collapse whitespace; "
"lowercase. No Kamba-specific orthographic rules yet."
),
}
_CS = re.compile(r"\[cs(?::(?:en|sw))?\]")
_DISFLUENCY = re.compile(r"\[(?:pause|sigh|laugh|breath|noise|silence)\]")
# TODO(orthography, v0.2+): confirm with native speakers whether Kamba orthography has any
# character that punctuation-stripping should NOT touch (some other Kenyan languages' writing
# systems use the apostrophe or hyphen to represent a real sound, not punctuation). Until
# confirmed, standard punctuation below is stripped uniformly. This does not affect the ĩ/ũ
# diacritics used in Kamba orthography — NFKC does not strip them, and they are not in this set.
_PUNCT = re.compile(r"[.,;?!\"/\\]")
_WS = re.compile(r"\s+")
def normalize(s: str) -> str:
"""Apply KambaBench-ASR normalization v{__version__} to a transcript string."""
s = unicodedata.normalize("NFKC", s)
s = _CS.sub(" ", s)
s = _DISFLUENCY.sub(" ", s)
s = _PUNCT.sub(" ", s)
return _WS.sub(" ", s).strip().lower()
|